


import glob
from PIL import Image
import shutil
from random import shuffle
#Retriving all image names and it's path with .jpg extension from given directory path in imageNames list
imageNames = glob.glob(r"D:/škola/magister/2.rocnik/leto/diplomka/dataset/internet/Dataset c1/dataset_komplet_resized/CLOUDY/*.jpg")
#D:/škola/magister/2.rocnik/leto/diplomka/dataset/internet/Dataset c1/dataset_komplet/FOGGY/*.jpg
#Defining width and height of image

files = list(imageNames)
length = len(imageNames)

shuffle(files)
#Count variable to show the progress of image resized
count=0

#Creating for loop to take one image from imageNames list and resize
for i in imageNames:
	#opening image for editing
    
    img = Image.open(i)
    img = img.convert('RGB')
    img.thumbnail((224, 224))
    AAA = 'cloudy'
    
    if count <= (0.8*length):
        img.save(r"D:/škola/magister/2.rocnik/leto/diplomka/dataset/internet/Dataset c1/shuffled/train/CLOUDY//"+str(count)+".jpg")
        count+=1        
    #elif count > (0.6*length) and count <= (0.8*length):
    #    img.save(r"D:/škola/magister/2.rocnik/leto/diplomka/dataset/internet/Dataset c1/shuffled/test/SUNNY//"+str(count)+".jpg") 
    #    count+=1
    else: 
        img.save(r"D:/škola/magister/2.rocnik/leto/diplomka/dataset/internet/Dataset c1/shuffled/validate/CLOUDY//"+str(count)+".jpg")
        count+=1
    #using resize() to resize image
    
    #save() to save image at given path and count is the name of image eg. first image name will be 0.jpg
    #img.save(r"D:/škola/magister/2.rocnik/leto/diplomka/dataset/internet/Dataset c1/dataset_komplet_resized/FOGGY//"+str(count)+AAA+".jpg") 
    #incrementing count value
    #count+=1
    #showing image resize progress
    print("Images Resized " +str(count)+"/"+str(len(imageNames)),end='\r')
    
    