-
Notifications
You must be signed in to change notification settings - Fork 5
/
metrics.py
33 lines (27 loc) · 1.24 KB
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
This module is for evaluation metrics calculation i.e., MSE, MAE, PSNR, SSIM.
Copyright (c) 2020-present, Abdullah Abuolaim
This source code is licensed under the license found in the LICENSE file in
the root directory of this source tree.
Note: this code is the implementation of the "Defocus Deblurring Using Dual-
Pixel Data" paper accepted to ECCV 2020. Link to GitHub repository:
https://github.com/Abdullah-Abuolaim/defocus-deblurring-dual-pixel
Email: [email protected]
"""
from config import *
def MAE(img1, img2):
mae_0=mean_absolute_error(img1[:,:,0], img2[:,:,0],
multioutput='uniform_average')
mae_1=mean_absolute_error(img1[:,:,1], img2[:,:,1],
multioutput='uniform_average')
mae_2=mean_absolute_error(img1[:,:,2], img2[:,:,2],
multioutput='uniform_average')
return np.mean([mae_0,mae_1,mae_2])
def MSE_PSNR_SSIM(img1, img2):
mse_ = np.mean( (img1 - img2) ** 2 )
if mse_ == 0:
return 100
PIXEL_MAX = 1
return mse_, 10 * math.log10(PIXEL_MAX / mse_), ssim(img1,
img2, data_range=PIXEL_MAX,
multichannel=True)