from patchPaint import paint import cv2 from PIL import Image import numpy as np from lucidDream import dreamData Iorg=cv2.imread('img.jpg') Morg=Image.open('gt.png') palette=Morg.getpalette() bg=paint(Iorg,np.array(Morg),False) cv2.imwrite('bg.jpg',bg) #bg=cv2.imread('bg.jpg') im_1,gt_1,bb_1,im_2,gt_2,bb_2,fb,ff=dreamData(Iorg,np.array(Morg),bg,True) # Image 1 in this pair. cv2.imwrite('gen1.jpg',im_1) # Mask for image 1. gtim1=Image.fromarray(gt_1,'P') gtim1.putpalette(palette) gtim1.save('gen1.png') # Deformed previous mask for image 1. bbim1=Image.fromarray(bb_1,'P') bbim1.putpalette(palette) bbim1.save('gen1bb.png') # Image 2 in this pair. cv2.imwrite('gen2.jpg',im_2)
# mask = Image.fromarray(mask, 'P') # mask.save(os.path.join(path_to_jj, 'mask.png')) # # mask = Image.open(os.path.join(path_to_jj, 'mask.png')) # # print np.array(mask)[300:500,300:500] # bb # if not os.path.exists(path_to_jj): # os.mkdir(path_to_jj) generate_num = 200 Iorg = cv2.imread(img_path) mask = Image.open(label_path) palette = mask.getpalette() mask = np.array(mask) print(mask.max()) bg = paint(Iorg, mask, False) for kk in range(generate_num): path_rgb1_save = os.path.join(path_to_jj, str(kk).zfill(5) + '_rgb1.jpg') path_rgb2_save = os.path.join(path_to_jj, str(kk).zfill(5) + '_rgb2.jpg') path_mask1_save = os.path.join(path_to_jj, str(kk).zfill(5) + '_gt1.png') path_mask2_save = os.path.join(path_to_jj, str(kk).zfill(5) + '_gt2.png') path_flow_save = os.path.join(path_to_jj, str(kk).zfill(5) + '_flow.png') im_1, gt_1, bb_1, im_2, gt_2, bb_2, fb, ff = dreamData( Iorg, mask, bg, True)