Add and use rmsDiffNumpy

This commit is contained in:
Benjamin Loison 2024-03-25 20:14:33 +01:00
parent 7c7cbad0ef
commit 2baf9c3000
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,7 @@ from PIL import ImageChops
import math
import operator
import functools
import numpy as np
def rmsDiffPil(im1, im2):
"Calculate the root-mean-square difference between two images"
@ -13,3 +14,5 @@ def rmsDiffPil(im1, im2):
map(lambda h, i: h*(i**2), h, range(256))
) / (float(im1.size[0]) * im1.size[1]))
def rmsDiffNumpy(image0, image1):
return np.sqrt(np.mean(np.square(image0 - image1)))

View File

@ -5,7 +5,7 @@ import sys
sys.path.insert(0, '../../algorithms/distance/')
from rms_diff import rmsDiffPil
from rms_diff import rmsDiffPil, rmsDiffNumpy
sys.path.insert(0, '../../algorithms/context_adaptive_interpolator/')
@ -56,14 +56,15 @@ axs[1].imshow(imagesWithPrnu[0][0])
imagesWithPrnuPil = [[toPilImage(imageWithPrnu) for imageWithPrnu in imagesWithPrnu[phoneIndex]] for phoneIndex in range(NUMBER_OF_PHONES)]
#showImageWithMatplotlib(imagesWithPrnu[0][0])
axs[2].set_title(f'First image with PRNU (RMS with image without PRNU: {rmsDiffPil(toPilImage(imagesWithPrnu[0][0]), toPilImage(imagesWithoutPrnu[0][0]))})')
axs[2].set_title(f'First image with PRNU\nRMS with image without PRNU: {round(rmsDiffNumpy(imagesWithPrnu[0][0], imagesWithoutPrnu[0][0]), 4)}')
axs[2].imshow(imagesWithPrnu[0][0])
imagesWithPrnuPil0Mean = np.array(imagesWithPrnuPil[0]).mean(axis = 0)
#showImageWithMatplotlib(imagesWithPrnuPil0Mean)
axs[3].set_title('Mean of images with PRNU')
axs[3].set_title(f'Mean of images with PRNU\ni.e. estimated PRNU\nRMS with actual PRNU: {round(rmsDiffNumpy(imagesWithPrnuPil0Mean, prnus[0]), 4)}')
axs[3].imshow(imagesWithPrnuPil0Mean)
plt.tight_layout()
plt.show()
##