frentzy

Imagini Modificate

Oct 24th, 2020
864
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PIL import Image, ImageOps
  2. import glob
  3. import numpy as np
  4. import cv2
  5. import os
  6. import errno
  7.  
  8. image_list = [] #aici retin pozele originale
  9. string_list = [] #aici retin numele pozelor
  10. micsorate_list = [] #aici retin pozele micsorate,pentru restul n-am mai facut list-uri
  11.  
  12. for filename in glob.glob('C:/Users/Frentzy/Pictures/*.jpg'):
  13.     im=Image.open(filename)
  14.     image_list.append(im)
  15.     string_list.append(filename)
  16.    
  17. #List imagini micsorate
  18. for image in image_list:
  19.     width,height = image.size
  20.     width = int(width/2)
  21.     height = int(height/2)
  22.     micsorate_list.append(image.resize((width, height), Image.ANTIALIAS))
  23.    
  24.  
  25. # BMP,Micsorate,Oglindite
  26. path1 = "C:/Users/Frentzy/Documents/PythonProjects/Proiect1/Micsorate/"
  27. path2 = "C:/Users/Frentzy/Documents/PythonProjects/Proiect1/BMP/"
  28. path3 = "C:/Users/Frentzy/Documents/PythonProjects/Proiect1/Oglindite/"
  29.  
  30. #Verificare de erori, in caz de exista deja directorul
  31. try:
  32.     os.makedirs(path1)
  33. except OSError as e:
  34.     if e.errno != errno.EEXIST:
  35.         raise
  36.        
  37. try:
  38.     os.makedirs(path2)
  39. except OSError as e:
  40.     if e.errno != errno.EEXIST:
  41.         raise
  42.  
  43. try:
  44.     os.makedirs(path3)
  45. except OSError as e:
  46.     if e.errno != errno.EEXIST:
  47.         raise
  48.  
  49. #retine numele originale ale pozelor
  50. name_list = []
  51. sub_list = ["C:/Users/Frentzy/Pictures\\"," "]
  52. for path in string_list:
  53.     string = path
  54.     for sub in sub_list:
  55.         string = string.replace(sub, ' ')
  56.     res = "".join(string.split())
  57.     name_list.append(res)
  58.    
  59. #Task 1
  60. i = 0
  61. for img in micsorate_list:
  62.     img.save(path1+name_list[i], "JPEG")
  63.     i += 1
  64.  
  65. #Task 2  
  66. i = 0
  67. for string in name_list:
  68.     name_list[i] = string.replace(".jpg"," ")
  69.     i+=1
  70. i = 0
  71. for img in image_list:
  72.     img.save(path2+name_list[i]+".bmp")
  73.     i+=1
  74.  
  75. #Task 3
  76. i = 0
  77. for img in image_list:
  78.     mirror_img = ImageOps.mirror(img)
  79.     mirror_img.save(path3+name_list[i]+".jpg", "JPEG")
  80.     i+=1
RAW Paste Data