Generalize with a partial image SPLIT_N_X_N
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
import os
|
||||
|
||||
def randomGaussianImage(scale, size):
|
||||
return np.random.normal(loc = 0, scale = scale, size = size)
|
||||
@@ -13,4 +14,18 @@ def showImageWithMatplotlib(npArray, title = None, cmap = 'viridis'):
|
||||
plt.show()
|
||||
|
||||
def toPilImage(npArray):
|
||||
return Image.fromarray(npArray)
|
||||
return Image.fromarray(npArray)
|
||||
|
||||
def getPrnuShownAsSuch(size):
|
||||
# Supports `WIDTH` > `HEIGHT` and conversely.
|
||||
WIDTH, HEIGHT = size
|
||||
TEXT = 'PRNU'
|
||||
|
||||
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)
|
||||
# Center vertically, especially in the case `HEIGHT` > `WIDTH`.
|
||||
draw.text((0, HEIGHT // 2 - fontSize // 2), TEXT, 255, font = font)
|
||||
return np.array(image)
|
Reference in New Issue
Block a user