Not correct generalized SPLIT_N_X_N
due to imageWithoutPrnuNpArrayTile
This commit is contained in:
parent
96bbd50a3b
commit
2d96bdc225
@ -23,9 +23,11 @@ def getPrnuShownAsSuch(size):
|
||||
|
||||
image = Image.new('L', size)
|
||||
draw = ImageDraw.Draw(image)
|
||||
# I guess that the maximal character height is higher than the maximal character width. Hence, the `TEXT` may not be spanned on the full width.
|
||||
fontSize = min(HEIGHT, WIDTH // len(TEXT))
|
||||
font = ImageFont.truetype(os.path.expanduser('~/.local/share/fonts/impact.ttf'), fontSize)
|
||||
fontPath = os.path.expanduser('~/.local/share/fonts/impact.ttf')
|
||||
for fontSize in range(1, HEIGHT + 1):
|
||||
font = ImageFont.truetype(fontPath, fontSize)
|
||||
if font.getlength(TEXT) > WIDTH:
|
||||
break
|
||||
# Center vertically, especially in the case `HEIGHT` > `WIDTH`.
|
||||
draw.text((0, HEIGHT // 2 - fontSize // 2), TEXT, 255, font = font)
|
||||
return np.array(image)
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user