Make PRNU compatible with 4x4 split
This commit is contained in:
@@ -24,13 +24,14 @@ 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.
|
# 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.
|
# 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.01
|
PRNU_FACTOR = 0.01
|
||||||
NOISE_FACTOR = 0.25
|
NOISE_FACTOR = 0.1
|
||||||
IMAGE_SIZE_SHAPE = (469, 704)
|
IMAGE_SIZE_SHAPE = (469, 704)
|
||||||
|
IMAGE_SIZE_SHAPE_4x4 = [size // 4 for size in IMAGE_SIZE_SHAPE]
|
||||||
|
|
||||||
np.random.seed(0)
|
np.random.seed(0)
|
||||||
|
|
||||||
#prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE)
|
#prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE)
|
||||||
prnuPil = Image.open('prnu.png').convert('F')
|
prnuPil = Image.open('prnu_4x4_noise.png').convert('F')
|
||||||
prnuNpArray = np.array(prnuPil) * PRNU_FACTOR
|
prnuNpArray = np.array(prnuPil) * PRNU_FACTOR
|
||||||
|
|
||||||
def isIn256Range(x):
|
def isIn256Range(x):
|
||||||
@@ -44,25 +45,13 @@ for imageName in os.listdir(datasetPath):
|
|||||||
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
|
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
|
||||||
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
|
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
|
||||||
|
|
||||||
m = imageWithoutPrnuNpArray.shape[0] // 1
|
m = imageWithoutPrnuNpArray.shape[0] // 4
|
||||||
n = imageWithoutPrnuNpArray.shape[1] // 1
|
n = imageWithoutPrnuNpArray.shape[1] // 4
|
||||||
|
|
||||||
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)]
|
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:
|
for imageWithoutPrnuNpArrayTile in imageWithoutPrnuNpArrayTiles:
|
||||||
imageNoise = randomGaussianImage(scale = 255 * NOISE_FACTOR, size = imageWithoutPrnuNpArrayTile.shape)
|
imageNoise = randomGaussianImage(scale = 255 * NOISE_FACTOR, size = imageWithoutPrnuNpArrayTile.shape)
|
||||||
imageWithPrnuNpArray = imageWithoutPrnuNpArrayTile + prnuNpArray + imageNoise
|
imageWithPrnuNpArray = imageWithoutPrnuNpArrayTile + prnuNpArray + imageNoise
|
||||||
#showImageWithMatplotlib(imageWithPrnuNpArray)
|
|
||||||
fig, axes = plt.subplots(1, 2)
|
|
||||||
fig.suptitle('Comparison of an image without and with Gaussian noise and PRNU')
|
|
||||||
|
|
||||||
axes[0].set_title('Image without Gaussian noise and PRNU')
|
|
||||||
axes[0].imshow(imageWithoutPrnuNpArray)
|
|
||||||
|
|
||||||
axes[1].set_title('Image with Gaussian noise and PRNU')
|
|
||||||
axes[1].imshow(imageWithPrnuNpArray)
|
|
||||||
|
|
||||||
plt.show()
|
|
||||||
break
|
|
||||||
#assert all([isIn256Range(extreme) for extreme in [imageWithPrnuNpArray.max(), imageWithPrnuNpArray.min()]]), 'Adding the PRNU resulted in out of 256 bounds image'
|
#assert all([isIn256Range(extreme) for extreme in [imageWithPrnuNpArray.max(), imageWithPrnuNpArray.min()]]), 'Adding the PRNU resulted in out of 256 bounds image'
|
||||||
imageWithPrnuPil = toPilImage(imageWithPrnuNpArray)
|
imageWithPrnuPil = toPilImage(imageWithPrnuNpArray)
|
||||||
#imagePrnuEstimatePil = contextAdaptiveInterpolator(imageWithPrnuPil.load(), imageWithPrnuPil)
|
#imagePrnuEstimatePil = contextAdaptiveInterpolator(imageWithPrnuPil.load(), imageWithPrnuPil)
|
||||||
@@ -70,9 +59,8 @@ for imageName in os.listdir(datasetPath):
|
|||||||
imagePrnuEstimateNpArray = imageWithPrnuNpArray - denoise_tv_chambolle(imageWithPrnuNpArray, weight=0.2, channel_axis=-1)
|
imagePrnuEstimateNpArray = imageWithPrnuNpArray - denoise_tv_chambolle(imageWithPrnuNpArray, weight=0.2, channel_axis=-1)
|
||||||
|
|
||||||
imagesPrnuEstimateNpArray += [imagePrnuEstimateNpArray]
|
imagesPrnuEstimateNpArray += [imagePrnuEstimateNpArray]
|
||||||
break
|
|
||||||
|
|
||||||
cameraPrnuEstimateNpArray = np.array(imagesPrnuEstimateNpArray).mean(axis = 0)
|
cameraPrnuEstimateNpArray = np.array(imagesPrnuEstimateNpArray).mean(axis = 0)
|
||||||
#rms = rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray, True)
|
rms = rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray, True)
|
||||||
#showImageWithMatplotlib(cameraPrnuEstimateNpArray, f'Camera PRNU estimate\nRMS with actual one: {rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray):.4f} (normalized RMS: {rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray, True):.4f})')
|
showImageWithMatplotlib(cameraPrnuEstimateNpArray, f'Camera PRNU estimate\nRMS with actual one: {rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray):.4f} (normalized RMS: {rmsDiffNumpy(cameraPrnuEstimateNpArray, prnuNpArray, True):.4f})')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user