Generalize with a partial image SPLIT_N_X_N

This commit is contained in:
2024-03-29 12:57:56 +01:00
parent 4bf9ef8206
commit 96bbd50a3b
2 changed files with 25 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ import sys
sys.path.insert(0, '../../algorithms/image_utils/')
from image_utils import showImageWithMatplotlib, randomGaussianImage, toPilImage
from image_utils import showImageWithMatplotlib, randomGaussianImage, toPilImage, getPrnuShownAsSuch
sys.path.insert(0, '../../algorithms/context_adaptive_interpolator/')
@@ -25,15 +25,15 @@ 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
IMAGE_SIZE_SHAPE = (469, 704)
IMAGE_SIZE_SHAPE_4x4 = [size // 4 for size in IMAGE_SIZE_SHAPE]
SPLIT_N_X_N = 1
IMAGE_SIZE_SHAPE = [dimension // SPLIT_N_X_N for dimension in (704, 469)]
np.random.seed(0)
splitNxN = 4
#prnuNpArray = 255 * randomGaussianImage(scale = PRNU_FACTOR, size = IMAGE_SIZE_SHAPE)
prnuPil = Image.open(f'prnu_{"4x4_" if splitNxN == 4 else ""}noise.png').convert('F')
prnuNpArray = np.array(prnuPil) * PRNU_FACTOR
prnuNpArray = getPrnuShownAsSuch(IMAGE_SIZE_SHAPE) * PRNU_FACTOR
showImageWithMatplotlib(prnuNpArray)
def isIn256Range(x):
return 0 <= x and x <= 255
@@ -46,8 +46,8 @@ for imageName in os.listdir(datasetPath):
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
m = imageWithoutPrnuNpArray.shape[0] // splitNxN
n = imageWithoutPrnuNpArray.shape[1] // splitNxN
m = imageWithoutPrnuNpArray.shape[0] // SPLIT_N_X_N
n = imageWithoutPrnuNpArray.shape[1] // SPLIT_N_X_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: