-
Notifications
You must be signed in to change notification settings - Fork 1
/
PNSR.py
28 lines (27 loc) · 964 Bytes
/
PNSR.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
import math
import numpy as np
import signal
import cv2
class Compare():
def correlation(self, img1, img2):
return signal.correlate2d (img1, img2)
def meanSquareError(self, img1, img2):
error = np.sum((img1.astype('float') - img2.astype('float')) ** 2)
error /= float(img1.shape[0] * img1.shape[1]);
return error
def psnr(self, img1, img2):
mse = self.meanSquareError(img1,img2)
if mse == 0:
return 100
PIXEL_MAX = 255.0
return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))
def addPadd(self,img,row,col):
img = cv2.resize(img,(col+(8-col%8),row+(8-row%8)))
return img
a = Compare()
img = cv2.imread('E:\JUET\Projects\StegMed\Test Images\RGB Images\PNG Images\Penguin1.png')
row, col = img.shape[:2]
img = a.addPadd(img,row,col)
simg = cv2.imread('E:\JUET\Projects\StegMed\Test Images\RGB Images\PNG Images\enc_Penguin1.png')
b = a.psnr(img,simg)
print(b)