From a8fa053687b09e0bf06aae0a331215711cb8c0b0 Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Tue, 16 Apr 2024 03:02:58 +0200 Subject: [PATCH] #49: Get PRNU by using RAW images --- datasets/raise/extract_noise.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py index 5e00882..72a80e0 100755 --- a/datasets/raise/extract_noise.py +++ b/datasets/raise/extract_noise.py @@ -33,10 +33,10 @@ if requiresRaiseFiltering: imagesFileNames = [imageFileName for imageFileName in tqdm(imagesFileNames, 'Filtering images') if files[imageFileName]['Device'] == 'Nikon D7000' and Image.open(f'{imagesFolderPath}/{imageFileName}').size == (4946, 3278)] -maxGreen = None +minGreen = 308#None def treatImage(imageFileName): - global mean, numberOfImagesInMean, maxGreen + global mean, numberOfImagesInMean, minGreen imageFilePath = f'{imagesFolderPath}/{imageFileName}' if imageFileName.endswith('.NEF'): with rawpy.imread(imageFilePath) as raw: @@ -45,18 +45,22 @@ def treatImage(imageFileName): assert np.array_equal(raw.raw_pattern, np.array([[0, 1], [3, 2]], dtype = np.uint8)) rawImageVisible = raw.raw_image_visible.copy() greenRawImageVisible = rawImageVisible[1::2, ::2] - greenRawImageVisibleMax = greenRawImageVisible.max() - if maxGreen is None or greenRawImageVisibleMax > maxGreen: - maxGreen = greenRawImageVisibleMax - print(f'{maxGreen=}') - imageNpArray = greenRawImageVisible + ''' + greenRawImageVisibleMin = greenRawImageVisible.min() + if minGreen is None or greenRawImageVisibleMin < minGreen: + minGreen = greenRawImageVisibleMin + print(minGreen) + ''' + imageNpArray = (greenRawImageVisible - minGreen) / (4908 - minGreen) # Pay attention to range of values expected by the denoiser. + # Indeed if provide the thousands valued raw image, then the denoiser only returns values between 0 and 1 and making the difference between both look pointless. #exit(1) else: imagePil = Image.open(imageFilePath) imageNpArray = img_as_float(np.array(imagePil)) # As the arguments differ from a denoiser to the other should use a match instead. imageDenoisedNpArray = denoise(imageNpArray, rescale_sigma=True) + #print(imageNpArray, imageDenoisedNpArray) imageNoiseNpArray = imageNpArray - imageDenoisedNpArray if mean is None: mean = imageNoiseNpArray