Compare RMS difference between average images and the average CAI images

#9 (comment)
This commit is contained in:
Benjamin Loison 2024-03-22 12:11:26 +01:00
parent 452dd755fc
commit a9adf2d53d
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -13,16 +13,17 @@ from context_adaptive_interpolator import contextAdaptiveInterpolator
IMAGE_SIZE = 64
# Is such `np.maximum` probabilistically correct with our theoretical method?
def randomImage(scale):
return np.maximum(np.random.normal(loc = 0, scale = scale, size = (IMAGE_SIZE, IMAGE_SIZE)), 0)
prnu = randomImage(scale = 1)
images = [randomImage(scale = 10) + prnu for _ in range(10)]
images = [randomImage(scale = 10) + prnu for _ in range(100)]
allImages = [prnu] + images
def toPilImage(npArray):
npArray = np.round(255 * npArray / np.max(allImages))
npArray = (255 * npArray / np.max(allImages)).round()
return Image.fromarray(np.uint8(npArray))
prnu = toPilImage(prnu)
@ -31,7 +32,13 @@ prnu = toPilImage(prnu)
images = [toPilImage(image) for image in images]
#images[0].show()
for image in images:
caiImages = [contextAdaptiveInterpolator(image.load(), image) for image in images]
for image, caiImage in zip(images, caiImages):
initialRmsDiff = rmsdiff(image, prnu)
caiRmsDiff = rmsdiff(contextAdaptiveInterpolator(image.load(), image), prnu)
print(f'{initialRmsDiff=} {caiRmsDiff=}')
caiRmsDiff = rmsdiff(caiImage, prnu)
#print(f'{initialRmsDiff=} {caiRmsDiff=}')
print('RMS diff with average image =', rmsdiff(toPilImage(np.array(images).mean(axis = 0)), prnu))
# Should be better than above one. Maybe not the case here as the images are Gaussian noise.
print('RMS diff with average CAI images =', rmsdiff(toPilImage(np.array(caiImages).mean(axis = 0)), prnu))