Add RMS computation

This commit is contained in:
Benjamin Loison 2024-03-29 01:35:48 +01:00
parent f297060f42
commit 3ccec5bbd0
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 13 additions and 5 deletions

View File

@ -5,7 +5,9 @@ from matplotlib import pyplot as plt
def randomGaussianImage(scale, size):
return np.random.normal(loc = 0, scale = scale, size = size)
def showImageWithMatplotlib(npArray):
def showImageWithMatplotlib(npArray, title = None):
if title is not None:
plt.title(title)
plt.imshow(npArray)
plt.show()

View File

@ -14,6 +14,10 @@ sys.path.insert(0, '../../algorithms/context_adaptive_interpolator/')
from context_adaptive_interpolator import contextAdaptiveInterpolator
sys.path.insert(0, '../../algorithms/distance/')
from rms_diff import rmsDiffNumpy
from skimage.restoration import denoise_tv_chambolle
datasetPath = 'no_noise_images'
@ -25,7 +29,7 @@ IMAGE_SIZE_SHAPE = (469, 704)
np.random.seed(0)
#prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE)
prnuPil = Image.open('prnu_4x4.png').convert('F')
prnuPil = Image.open('prnu.png').convert('F')
prnuNpArray = np.array(prnuPil) * PRNU_FACTOR
def isIn256Range(x):
@ -39,8 +43,8 @@ for imageName in os.listdir(datasetPath):
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
m = imageWithoutPrnuNpArray.shape[0] // 4
n = imageWithoutPrnuNpArray.shape[1] // 4
m = imageWithoutPrnuNpArray.shape[0] // 1
n = imageWithoutPrnuNpArray.shape[1] // 1
imageWithoutPrnuNpArrayTiles = [imageWithoutPrnuNpArray[x : x + m, y : y + n] for x in range(0, imageWithoutPrnuNpArray.shape[0], m) for y in range(0, imageWithoutPrnuNpArray.shape[1], n)]
for imageWithoutPrnuNpArrayTile in imageWithoutPrnuNpArrayTiles:
@ -53,5 +57,7 @@ for imageName in os.listdir(datasetPath):
imagesPrnuEstimateNpArray += [imagePrnuEstimateNpArray]
showImageWithMatplotlib(np.array(imagesPrnuEstimateNpArray).mean(axis = 0))
cameraPrnuEstimateNpArray = np.array(imagesPrnuEstimateNpArray).mean(axis = 0)
rms = rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray)
showImageWithMatplotlib(cameraPrnuEstimateNpArray, f'Camera PRNU estimate\nRMS with actual one: {rms:.4f}')