mask = impro.resize_like(mask, img) x, y, size, area = impro.boundingSquare(mask, 1.5) if area > 100: if Bounding: img = impro.resize( img[y - size:y + size, x - size:x + size], OUT_SIZE) mask = impro.resize( mask[y - size:y + size, x - size:x + size], OUT_SIZE) img_mosaic = mosaic.addmosaic_random(img, mask) if HD: cv2.imwrite( os.path.join(train_A_path, '%05d' % cnt + '.jpg'), img_mosaic) cv2.imwrite( os.path.join(train_B_path, '%05d' % cnt + '.jpg'), img) else: merge_img = impro.makedataset(img_mosaic, img) cv2.imwrite( os.path.join(train_path, '%05d' % cnt + '.jpg'), merge_img) if MASK: cv2.imwrite(os.path.join(mask_path, '%05d' % cnt + '.png'), mask) print("Processing:", img_name, " ", "Remain:", len(img_names) * FOLD_NUM - cnt) except Exception as e: print(img_name, e) cnt += 1
img = np.array(img) img = img[...,::-1] if BOUNDING: mosaic_area = 0 while mosaic_area < 16384: mask = Image.open(os.path.join(ir_mask_path,random.choices(mask_names)[0])) mask = transform_mask(mask) mask = np.array(mask) mosaic_area = impro.mask_area(mask) mosaic_img = mosaic.addmosaic_random(img, mask,'bounding') BOUNDING_flag = '_bound' else: mask = Image.open(os.path.join(ir_mask_path,random.choices(mask_names)[0])) mask = transform_mask(mask) mask = np.array(mask) mosaic_img = mosaic.addmosaic_random(img, mask) BOUNDING_flag = '' if HD:#[128:384,128:384,:] --->256 cv2.imwrite(os.path.join(train_A_path,'%05d' % i+BOUNDING_flag+'.jpg'), mosaic_img) cv2.imwrite(os.path.join(train_B_path,'%05d' % i+BOUNDING_flag+'.jpg'), img) else: merge_img = impro.makedataset(mosaic_img, img) cv2.imwrite(os.path.join(train_path,'%05d' % i+BOUNDING_flag+'.jpg'), merge_img) if MASK: cv2.imwrite(os.path.join(mask_path,'%05d' % i+BOUNDING_flag+'.png'), mask) print("Processing:",img_name," ","Remain:",len(img_names)-i) except Exception as e: print(img_name,e)