From 81852d5dc67c26c2165802fdcb6dc0ded72fa249 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Fri, 29 Mar 2024 13:22:36 +0100 Subject: [PATCH] Make Gaussian noise in `getPrnuShownAsSuch` only on text --- algorithms/image_utils/image_utils.py | 9 ++++++++- datasets/noise_free_test_images/estimate_prnu.py | 7 ++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/algorithms/image_utils/image_utils.py b/algorithms/image_utils/image_utils.py index 16afe67..a152207 100644 --- a/algorithms/image_utils/image_utils.py +++ b/algorithms/image_utils/image_utils.py @@ -31,4 +31,11 @@ def getPrnuShownAsSuch(size, gaussianNoise = 0): # Center vertically, especially in the case `HEIGHT` > `WIDTH`. draw.text((0, HEIGHT // 2 - fontSize // 2), TEXT, 255, font = font) imageNpArray = np.array(imagePil) - return imageNpArray + randomGaussianImage(gaussianNoise, size[::-1]) \ No newline at end of file + gaussianNoiseNpArray = randomGaussianImage(gaussianNoise, size[::-1]) + #prnuShownAsSuch = imageNpArray + gaussianNoiseNpArray + prnuShownAsSuch = imageNpArray + for y in range(HEIGHT): + for x in range(WIDTH): + if prnuShownAsSuch[y, x] != 0: + prnuShownAsSuch[y, x] += gaussianNoiseNpArray[y, x] + return prnuShownAsSuch \ No newline at end of file diff --git a/datasets/noise_free_test_images/estimate_prnu.py b/datasets/noise_free_test_images/estimate_prnu.py index 5603c63..91e492c 100644 --- a/datasets/noise_free_test_images/estimate_prnu.py +++ b/datasets/noise_free_test_images/estimate_prnu.py @@ -25,17 +25,14 @@ 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 = 4 +SPLIT_N_X_N = 1 IMAGE_SIZE_SHAPE = [dimension // SPLIT_N_X_N for dimension in (704, 469)] np.random.seed(0) #prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE) -prnuNpArray = getPrnuShownAsSuch(IMAGE_SIZE_SHAPE, 100) * PRNU_FACTOR -showImageWithMatplotlib(prnuNpArray) - -## +prnuNpArray = getPrnuShownAsSuch(IMAGE_SIZE_SHAPE, 255) * PRNU_FACTOR def isIn256Range(x): return 0 <= x and x <= 255