from PIL import Image
import glob
import os
import pdb

if __name__ == "__main__":
    root_animal=os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/animal')
    root_building = os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/building')
    root_grass = os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/grass')
    root_mountain = os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/mountain')
    root_plant = os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/plant')
    root_sky = os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/sky')
    root_water = os.path.expanduser('/mnt/server5_hard1/seungjun/KAIR-master/trainsets/OutdoorSceneTrain_v2/water')

    root_X2='/mnt/server5_hard1/seungjun/KAIR-master/trainsets/trainL/X2/'
    root_X3 ='/mnt/server5_hard1/seungjun/KAIR-master/trainsets/trainL/X3/'
    root_X4 ='/mnt/server5_hard1/seungjun/KAIR-master/trainsets/trainL/X4/'


    datas_=[root_animal, root_building, root_grass, root_mountain, root_plant, root_sky, root_water]
    scaling_factor=[2,3,4]
    save_dirs=[root_X2, root_X3, root_X4]
    
    for root_data in datas_:
        for filename in glob.glob(root_data + '**/*.png'):  # assuming gif
            img_=Image.open(filename).convert('RGB')
            
            img_name=filename.split('/')
            img_name=img_name[-1]
            for idk,savek in zip(scaling_factor, save_dirs):
                img_down = img_.resize((img_.width//idk, img_.height//idk))
                img_up =img_down.resize((img_.width,img_.height),Image.BICUBIC)
                save_dir=savek+img_name
                save_dir=save_dir.split('.png')[0]
                save_dir=save_dir+'x'+str(idk)+'.png'
                print("saving {}".format(save_dir))
                img_up.save(save_dir)