-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpsnr_ssim.py
29 lines (23 loc) · 1.04 KB
/
psnr_ssim.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
# 1. Import the necessary packages
from skimage.measure import compare_ssim
import argparse
import imutils
import cv2
# 2. Construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--first", required=True, help="Directory of the image that will be compared")
ap.add_argument("-s", "--second", required=True, help="Directory of the image that will be used to compare")
args = vars(ap.parse_args())
# 3. Load the two input images
imageA = cv2.imread(args["first"])
imageB = cv2.imread(args["second"])
# 4. Convert the images to grayscale
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)
# 5. Compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
PSNR = cv2.PSNR(imageA, imageB)
# 6. You can print only the score if you want
print("SSIM: {}".format(score), "PSNR: {}".format(PSNR))