Split images in 4x4 to increase PRNU estimation accuracy

This commit is contained in:
Benjamin Loison 2024-03-29 01:21:26 +01:00
parent 9b57d3441c
commit f297060f42
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -19,14 +19,14 @@ from skimage.restoration import denoise_tv_chambolle
datasetPath = 'no_noise_images'
# Note that contrarily to `datasets/fake/`, here we do not have images being Gaussian with `scale` `1` but actual images with pixel values between 0 and 255.
# In addition to the range difference, note that the distribution in the first set of images was a Gaussian and here is very different and specific.
PRNU_FACTOR = 0.1
PRNU_FACTOR = 0.01
IMAGE_SIZE_SHAPE = (469, 704)
np.random.seed(0)
#prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE)
prnuPil = Image.open('prnu.png').convert('F')
prnusNpArray = [np.array(prnuPil) * PRNU_FACTOR for PRNU_FACTOR in PRNU_FACTORS]
prnuPil = Image.open('prnu_4x4.png').convert('F')
prnuNpArray = np.array(prnuPil) * PRNU_FACTOR
def isIn256Range(x):
return 0 <= x and x <= 255
@ -39,14 +39,19 @@ for imageName in os.listdir(datasetPath):
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
imageWithPrnuNpArray = imageWithoutPrnuNpArray + prnuNpArray
#assert all([isIn256Range(extreme) for extreme in [imageWithPrnuNpArray.max(), imageWithPrnuNpArray.min()]]), 'Adding the PRNU resulted in out of 256 bounds image'
imageWithPrnuPil = toPilImage(imageWithPrnuNpArray)
#imagePrnuEstimatePil = contextAdaptiveInterpolator(imageWithPrnuPil.load(), imageWithPrnuPil)
#imagePrnuEstimateNpArray = np.array(imagePrnuEstimatePil)
imagePrnuEstimateNpArray = imageWithPrnuNpArray - denoise_tv_chambolle(imageWithPrnuNpArray, weight=0.2, channel_axis=-1)
m = imageWithoutPrnuNpArray.shape[0] // 4
n = imageWithoutPrnuNpArray.shape[1] // 4
imagesPrnuEstimateNpArray += [imagePrnuEstimateNpArray]
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:
imageWithPrnuNpArray = imageWithoutPrnuNpArrayTile + prnuNpArray
#assert all([isIn256Range(extreme) for extreme in [imageWithPrnuNpArray.max(), imageWithPrnuNpArray.min()]]), 'Adding the PRNU resulted in out of 256 bounds image'
imageWithPrnuPil = toPilImage(imageWithPrnuNpArray)
#imagePrnuEstimatePil = contextAdaptiveInterpolator(imageWithPrnuPil.load(), imageWithPrnuPil)
#imagePrnuEstimateNpArray = np.array(imagePrnuEstimatePil)
imagePrnuEstimateNpArray = imageWithPrnuNpArray - denoise_tv_chambolle(imageWithPrnuNpArray, weight=0.2, channel_axis=-1)
imagesPrnuEstimateNpArray += [imagePrnuEstimateNpArray]
showImageWithMatplotlib(np.array(imagesPrnuEstimateNpArray).mean(axis = 0))