Not correct generalized SPLIT_N_X_N due to imageWithoutPrnuNpArrayTile

This commit is contained in:
2024-03-29 13:11:24 +01:00
parent 96bbd50a3b
commit 2d96bdc225
2 changed files with 11 additions and 7 deletions

View File

@@ -25,7 +25,7 @@ datasetPath = 'no_noise_images'
# 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
NOISE_FACTOR = 0.1
SPLIT_N_X_N = 1
SPLIT_N_X_N = 4
IMAGE_SIZE_SHAPE = [dimension // SPLIT_N_X_N for dimension in (704, 469)]
@@ -33,7 +33,6 @@ np.random.seed(0)
#prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE)
prnuNpArray = getPrnuShownAsSuch(IMAGE_SIZE_SHAPE) * PRNU_FACTOR
showImageWithMatplotlib(prnuNpArray)
def isIn256Range(x):
return 0 <= x and x <= 255
@@ -46,11 +45,14 @@ for imageName in os.listdir(datasetPath):
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
m = imageWithoutPrnuNpArray.shape[0] // SPLIT_N_X_N
n = imageWithoutPrnuNpArray.shape[1] // SPLIT_N_X_N
m = IMAGE_SIZE_SHAPE[1]
n = IMAGE_SIZE_SHAPE[0]
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:
#print(imageWithoutPrnuNpArrayTile.shape, tuple(IMAGE_SIZE_SHAPE[::-1]))
#if imageWithoutPrnuNpArrayTile.shape != tuple(IMAGE_SIZE_SHAPE[::-1]):
# continue
imageNoise = randomGaussianImage(scale = 255 * NOISE_FACTOR, size = imageWithoutPrnuNpArrayTile.shape)
imageWithPrnuNpArray = imageWithoutPrnuNpArrayTile + prnuNpArray + imageNoise
#assert all([isIn256Range(extreme) for extreme in [imageWithPrnuNpArray.max(), imageWithPrnuNpArray.min()]]), 'Adding the PRNU resulted in out of 256 bounds image'