import cv2,os
import numpy as np
def mask(path):
img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
_,mask = cv2.threshold(img,80,255,cv2.THRESH_BINARY)
return mask
def repair(img,mask):
rep = cv2.resize(img,None,fx=0.6,fy=0.6,interpolation=cv2.INTER_CUBIC)
# print(type(mask))
mask = cv2.resize(mask(img_path),None,fx=0.6,fy=0.6,interpolation=cv2.INTER_CUBIC)
dst = cv2.illuminationChange(rep,mask)
return dst
if __name__ == '__main__':
# path = r'./1.jpg'
# path = r"D:\install\Meshroom-2020.1.1-win64\Meshroom-2020.1.1\data\input\04_04"
# mask = mask(path)
# img = cv2.imread(path)
# dst = repair(img,mask)
# cv2.imshow("a",dst)
# cv2.waitKey()
# # cv2.imwrite('1-1.jpg', dst)
# Try to batch in batches below
file_root = r'D:\install\Meshroom-2020.1.1-win64\Meshroom-2020.1.1\data\input\04_04' # All pictures under the current folder
file_list = os.listdir(file_root)
save_out = r"D:\install\Meshroom-2020.1.1-win64\Meshroom-2020.1.1\data\input\04_04\out" # Save the folder name of the picture
for img_name in file_list:
if img_name.endswith('.jpg'):
img_path = file_root + "\\"+ img_name
img = cv2.imread(img_path)
dst = repair(img, mask)
I = cv2.imread(img_path, -1)
# Image = SITK.Readimage (". DCM")# Read DCM
# inputimg = np.squeeze (SITK.GetarrayFromimage (Image))# Read DCM
# print(I.shape)
# M, N = I.shape
out_name = img_name.split('.')[0]
save_path = save_out + "\\" + out_name + '.jpg'
cv2.imwrite(save_path, dst)
print(img_name + "Save success")
Effect:
If you encounter SRC error:
1.OPENCV reduced version3.4around2. print(type(mask)),
3. def repair(img,mask):
rep = cv2.resize(img,None,fx=0.6,fy=0.6,interpolation=cv2.INTER_CUBIC)
# print(type(mask))
mask = cv2.resize(mask(img_path),None,fx=0.6,fy=0.6,interpolation=cv2.INTER_CUBIC)
dst = cv2.illuminationChange(rep,mask)
return dst