def merge_com_img(sensing_date,uid,img_type): import cv2 import numpy as np from PIL import Image n_file_name = sensing_date+uid+'M'+img_type+'.png' etci_file_name=sensing_date+uid+'_TCI.png' n_file = cv2.imread(n_file_name) etci = cv2.imread(etci_file_name) orig_h,orig_w,orig_rgb = etci.shape h,w = orig_h,orig_w print(h) print(w) n_file = cv2.resize(n_file,(w,h)) sw2 = cv2.imwrite(n_file_name,n_file) etci = cv2.resize(etci,(w,h)) new_img = np.zeros([h,w,3]) for py in range(0,h): for px in range(0,w): #print(n_array[py][px]) if (n_file[py][px][1] > 0) & (n_file[py][px][1]<240): #if (n_array[py][px] > 12) & (n_array[py][px]<80): new_img[py][px][0]=n_file[py][px][0] new_img[py][px][1]=n_file[py][px][1] new_img[py][px][2]=n_file[py][px][2] else: new_img[py][px][0]=etci[py][px][0] new_img[py][px][1]=etci[py][px][1] new_img[py][px][2]=etci[py][px][2] mn_file_name = n_file_name status = cv2.imwrite(mn_file_name,new_img) new_img = Image.open(mn_file_name) etci_orig = Image.open(etci_file_name) etci_orig = etci_orig.convert("RGBA") new_img = new_img.convert("RGBA") new_img = new_img.resize((orig_w,orig_h),Image.NEAREST) new_img = Image.blend(etci_orig,new_img,0.6) new_img.save(mn_file_name,"PNG")