├── README.md └── calculate_psnr_ssim.py /README.md: -------------------------------------------------------------------------------- 1 | ### Restoring Vision in Rain-by-snow Weather with Simple Attention-based Sampling Cross-hierarchy Transformer 2 | 3 | | Dataset | Download Link | 4 | | ------------ | ------------------------------------------------------------ | 5 | | RSCityscapes | [[Google Drive](https://drive.google.com/file/d/1OnpsBl7-6hH6AjZPcKvuBj4qC7KvgkIy/view?usp=sharing)] [[Baidu Cloud](https://pan.baidu.com/s/13M9B7Kuvo0y2u7Dyr5iMnw) code: w1r9] | 6 | | RS100K | [[Baidu Cloud](https://pan.baidu.com/s/13gMLeWO-sppG_qzG38waHw) code: dwkx] | 7 | | RS300 | [[Google Drive](https://drive.google.com/file/d/12hMgdTLPRCc6X_GETtTQP0rnqM5Y9Tn8/view?usp=sharing)] [[Baidu Cloud](https://pan.baidu.com/s/1gglY0fGtn0heN27J6LTUyA) code: 5erf] | 8 | -------------------------------------------------------------------------------- /calculate_psnr_ssim.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import cv2 4 | import argparse 5 | from skimage.metrics import peak_signal_noise_ratio, structural_similarity 6 | 7 | 8 | def calculate_psnr_ssim(args): 9 | 10 | path_result = args.result_dir 11 | path_target = args.target_dir 12 | image_list = os.listdir(path_target) 13 | L = len(image_list) 14 | total_psnr, total_ssim = 0, 0 15 | 16 | for i in range(L): 17 | image_input = cv2.imread(os.path.join(path_result, str(image_list[i])), 1) 18 | image_target = cv2.imread(os.path.join(path_target, str(image_list[i])), 1) 19 | 20 | psnr = peak_signal_noise_ratio(image_input, image_target) 21 | ssim = structural_similarity(image_input / 255., image_target / 255., channel_axis=-1) 22 | # for different skimage version 23 | # ssin = structural_similarity(image_in/255., image_tar/255., multichannel=True) 24 | 25 | total_psnr += psnr 26 | total_ssim += ssim 27 | 28 | sys.stdout.write(f'\r{(i+1)} / {L}, PSNR: {psnr}, SSIM: {ssim}\t') 29 | sys.stdout.flush() 30 | 31 | print(f'\nPSNR: {total_psnr / L}, SSIM: {total_ssim / L}') 32 | 33 | 34 | if __name__ == '__main__': 35 | 36 | parser = argparse.ArgumentParser() 37 | parser.add_argument('--result_dir', type=str, default='./RainCityscapes/test/result') 38 | parser.add_argument('--target_dir', type=str, default='./RainCityscapes/test/target') 39 | args = parser.parse_args() 40 | 41 | calculate_psnr_ssim(args) 42 | 43 | 44 | --------------------------------------------------------------------------------