def fade_scores(): i = 0 for filename in os.listdir(with_coloration_path): # print("Filename: ", filename) # print("Inside first for loop") i += 1 im_path = with_coloration_path + filename inp_img = cv2.imread(im_path) fade_inp_img = compute_fade(inp_img) predicted_path = get_path(inp_img, 117) # threshold=117 ws['A{}'.format(i + 1)] = filename ws['B{}'.format(i + 1)] = fade_inp_img dehazenet_image = cv2.imread( dehazenet_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(filename[:-4])) fade_dehazenet = compute_fade(dehazenet_image) ws['C{}'.format(i + 1)] = fade_dehazenet if predicted_path == 1: enhanced_img = apply_CLAHE(adaptive_enhance(inp_img)) ws['D{}'.format(i + 1)] = compute_fade(enhanced_img) else: ws['D{}'.format(i + 1)] = fade_dehazenet # Comparison with raw input image scores # In FADE, lesser score is better if ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "No" else: ws['E{}'.format(i + 1)] = "Equal" # Comparison with DehazeNet scores if ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "No" else: ws['F{}'.format(i + 1)] = "Equal" # ws['D{}'.format(i + 1)] = niqe(dehaze_image(inp_img, im_path)) # ws['C{}'.format(i + 1)] = ws['D{}'.format(i + 1)].value print("FADE computed for: ", filename) for filename in os.listdir(without_coloration_path): # print("Filename: ", filename) # print("Inside first for loop") i += 1 im_path = without_coloration_path + filename inp_img = cv2.imread(im_path) fade_inp_img = compute_fade(inp_img) predicted_path = get_path(inp_img, 117) # threshold=117 ws['A{}'.format(i + 1)] = filename ws['B{}'.format(i + 1)] = fade_inp_img dehazenet_image = cv2.imread( dehazenet_without_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(filename[:-4])) fade_dehazenet = compute_fade(dehazenet_image) ws['C{}'.format(i + 1)] = fade_dehazenet if predicted_path == 1: enhanced_img = apply_CLAHE(adaptive_enhance(inp_img)) ws['D{}'.format(i + 1)] = compute_fade(enhanced_img) else: ws['D{}'.format(i + 1)] = fade_dehazenet # Comparison with raw input image scores if ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "No" else: ws['E{}'.format(i + 1)] = "Equal" # Comparison with DehazeNet scores if ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "No" else: ws['F{}'.format(i + 1)] = "Equal" # op_img = dehaze_image(inp_img, im_path) # niqe_score = niqe(op_img) # ws['D{}'.format(i + 1)] = niqe_score # ws['C{}'.format(i + 1)] = ws['D{}'.format(i + 1)].value print("FADE computed for: ", filename) wb.save(excel_path) print("Script complete and excel saved!")
def ssim_scores(): i = 0 for filename in os.listdir(with_coloration_path): i += 1 gt_name = filename[:filename.find( '_')] + '.png' # till the first occurence of underscore # print(gt_name) # print(gt_path + gt_name) gt_img = cv2.imread(gt_path + gt_name) im_path = with_coloration_path + filename inp_img = cv2.imread(im_path) predicted_path = get_path(inp_img, 117) # threshold=117 ws['A{}'.format(i + 1)] = filename ws['B{}'.format(i + 1)] = structural_similarity(gt_img, inp_img, multichannel=True) dehazenet_image = cv2.imread( dehazenet_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(filename[:-4])) ssim_dehaze = structural_similarity(gt_img, dehazenet_image, multichannel=True) ws['C{}'.format(i + 1)] = ssim_dehaze if predicted_path == 1: ws['D{}'.format(i + 1)] = structural_similarity( gt_img, apply_CLAHE(adaptive_enhance(inp_img)), multichannel=True) else: ws['D{}'.format(i + 1)] = ssim_dehaze # Comparison with raw input image scores if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "No" else: ws['E{}'.format(i + 1)] = "Equal" # Comparison with DehazeNet scores if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "No" else: ws['F{}'.format(i + 1)] = "Equal" print("SSIM computed for: ", filename) for filename in os.listdir(without_coloration_path): i += 1 gt_name = filename[:filename.find( '_')] + '.png' # till the first occurence of underscore gt_img = cv2.imread(gt_path + gt_name) im_path = without_coloration_path + filename inp_img = cv2.imread(im_path) predicted_path = get_path(inp_img, 117) # threshold=117 ws['A{}'.format(i + 1)] = filename ws['B{}'.format(i + 1)] = structural_similarity(gt_img, inp_img, multichannel=True) dehazenet_image = cv2.imread( dehazenet_without_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(filename[:-4])) ssim_dehaze = structural_similarity(gt_img, dehazenet_image, multichannel=True) ws['C{}'.format(i + 1)] = ssim_dehaze if predicted_path == 1: ws['D{}'.format(i + 1)] = structural_similarity( gt_img, apply_CLAHE(adaptive_enhance(inp_img)), multichannel=True) else: ws['D{}'.format(i + 1)] = ssim_dehaze # Comparison with raw input image scores if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value: ws['E{}'.format(i + 1)] = "No" else: ws['E{}'.format(i + 1)] = "Equal" # Comparison with DehazeNet scores if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "Yes" elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value: ws['F{}'.format(i + 1)] = "No" else: ws['F{}'.format(i + 1)] = "Equal" print("SSIM computed for: ", filename) wb.save(excel_path) print("Script complete and excel saved!")
I = src / 255.0 dark = DarkChannel(I, 15) A = AtmLight(I, dark) te = TransmissionEstimate(im_path, height, width) t = TransmissionRefine(src, te) J = Recover(I, t, A, 0.1) dehazed_image = J * 255 return dehazed_image if __name__ == '__main__': if not len(sys.argv) == 2: print('Usage: python DeHazeNet.py haze_img_path') exit() else: im_path = sys.argv[1] src = cv2.imread(im_path) path = get_path(src, threshold=137) if path == 1: dehazed_image = apply_CLAHE(src) else: dehazed_image = dehaze_image(src, im_path) # cv2.imshow('TransmissionEstimate', te) # cv2.imshow('TransmissionRefine', t) # cv2.imshow('Origin', src) # cv2.imshow('Dehaze', J) # cv2.waitKey(0) save_path = im_path[:-4] + '_Dehaze' + im_path[-4:len(im_path)] cv2.imwrite(save_path, dehazed_image) print("Dehazed image saved!")