Add an use toPilImage

This commit is contained in:
Benjamin Loison 2024-03-22 11:39:51 +01:00
parent 674025fa62
commit c287d5f0ef
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -1,5 +1,6 @@
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
import sys
sys.path.insert(0, '../../algorithms/distance/')
@ -9,16 +10,20 @@ from rmsdiff import rmsdiff
IMAGE_SIZE = 64
def randomImage(scale):
# Is `np.clip` necessary?
return np.round(np.random.normal(loc = 0, scale = scale, size = (IMAGE_SIZE, IMAGE_SIZE)))
# Is `np.clip` necessary? See `toPilImage`.
return np.random.normal(loc = 0, scale = scale, size = (IMAGE_SIZE, IMAGE_SIZE))
prnu = randomImage(scale = 1)
plt.imshow(prnu)
plt.show()
images = [randomImage(scale = 10) + prnu for _ in range(10)]
def toPilImage(npArray):
nonNegativeArray = npArray - np.min(npArray)
nonNegativeArray = np.round(255 * nonNegativeArray / np.max(nonNegativeArray))
return Image.fromarray(np.uint8(nonNegativeArray))
toPilImage(prnu).show()
for image in images:
print(rmsdiff(image, prnu))
print(rmsdiff(contextAdaptiveInterpolator(image), prnu))