Apply Context-Adaptive Interpolator
This commit is contained in:
parent
9a3cfd7ba1
commit
dfe2540c02
@ -7,4 +7,7 @@ def randomGaussianImage(scale, size):
|
||||
|
||||
def showImageWithMatplotlib(npArray):
|
||||
plt.imshow(npArray)
|
||||
plt.show()
|
||||
plt.show()
|
||||
|
||||
def toPilImage(npArray):
|
||||
return Image.fromarray(npArray)
|
@ -15,7 +15,7 @@ from context_adaptive_interpolator import contextAdaptiveInterpolator
|
||||
|
||||
sys.path.insert(0, '../../algorithms/image_utils/')
|
||||
|
||||
from image_utils import showImageWithMatplotlib, randomGaussianImage
|
||||
from image_utils import showImageWithMatplotlib, randomGaussianImage, toPilImage
|
||||
from tqdm import tqdm
|
||||
|
||||
IMAGE_SIZE = 64
|
||||
@ -37,9 +37,6 @@ imagesWithPrnu = [[imageWithoutPrnu + prnus[phoneIndex] for imageWithoutPrnu in
|
||||
|
||||
allImages = np.max([np.max(imagesWithoutPrnu) + np.max(prnus) + np.max(imagesWithPrnu)])
|
||||
|
||||
def toPilImage(npArray):
|
||||
return Image.fromarray(npArray)
|
||||
|
||||
def showImageWithPil(npArray):
|
||||
npArray -= npArray.min()
|
||||
npArray = (npArray / npArray.max()) * 255
|
||||
|
@ -7,12 +7,16 @@ import sys
|
||||
|
||||
sys.path.insert(0, '../../algorithms/image_utils/')
|
||||
|
||||
from image_utils import showImageWithMatplotlib, randomGaussianImage
|
||||
from image_utils import showImageWithMatplotlib, randomGaussianImage, toPilImage
|
||||
|
||||
sys.path.insert(0, '../../algorithms/context_adaptive_interpolator/')
|
||||
|
||||
from context_adaptive_interpolator import contextAdaptiveInterpolator
|
||||
|
||||
datasetPath = 'no_noise_images'
|
||||
# Note that contrarily to `datasets/fake/`, here we do not have images being Gaussian with `scale` `1` but actual images with pixel values between 0 and 255.
|
||||
# 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.1
|
||||
PRNU_FACTOR = 0.15
|
||||
IMAGE_SIZE_SHAPE = (469, 704)
|
||||
|
||||
np.random.seed(0)
|
||||
@ -21,11 +25,22 @@ np.random.seed(0)
|
||||
prnuPil = Image.open('prnu.png').convert('F')
|
||||
prnuNpArray = np.array(prnuPil) * PRNU_FACTOR
|
||||
|
||||
def isIn256Range(x):
|
||||
return 0 <= x and x <= 255
|
||||
|
||||
for imageName in os.listdir(datasetPath):
|
||||
if imageName.endswith('.png'):
|
||||
imagePath = f'{datasetPath}/{imageName}'
|
||||
imagePil = Image.open(imagePath).convert('F')
|
||||
imageNpArray = np.array(imagePil)
|
||||
#showImageWithMatplotlib(imageNpArray)
|
||||
showImageWithMatplotlib(imageNpArray + prnuNpArray)
|
||||
break
|
||||
imageWithoutPrnuPil = Image.open(imagePath).convert('F')
|
||||
imageWithoutPrnuNpArray = np.array(imageWithoutPrnuPil)
|
||||
#showImageWithMatplotlib(imageWithoutPrnuNpArray)
|
||||
imageWithPrnuNpArray = imageWithoutPrnuNpArray + prnuNpArray
|
||||
showImageWithMatplotlib(imageWithPrnuNpArray)
|
||||
break
|
||||
assert all([isIn256Range(extreme) for extreme in [imageWithPrnuNpArray.max(), imageWithPrnuNpArray.min()]]), 'Adding the PRNU resulted in out of 256 bounds image'
|
||||
imageWithPrnuPil = toPilImage(imageWithPrnuNpArray)
|
||||
imageWithPrnuCaiPil = contextAdaptiveInterpolator(imageWithPrnuPil.load(), imageWithPrnuPil)
|
||||
imageWithPrnuCaiNpArray = np.array(imageWithPrnuCaiPil)
|
||||
showImageWithMatplotlib(imageWithPrnuCaiNpArray)
|
||||
break
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user