From 719bb487ddb912ae386193009ef75a4e21b67702 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 25 Apr 2024 18:12:36 +0200 Subject: [PATCH] Restore other than raw images support --- datasets/raise/extract_noise.py | 42 ++++++++++++++++--------------- datasets/raise/show_mean_noise.py | 2 ++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py index 5f216a3..83c2f77 100755 --- a/datasets/raise/extract_noise.py +++ b/datasets/raise/extract_noise.py @@ -21,8 +21,8 @@ imagesFolderPathFileName = imagesFolderPath.replace('/', '_') denoiser = 'mean' raiseNotFlatFields = False -# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color`. -colors = Color +# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color` or `[None]` for not raw images. +colors = [None] if denoiser != 'mean': denoise = getattr(skimage.restoration, f'denoise_{denoiser}') @@ -80,28 +80,30 @@ def getImageNpArray(imageFileName, computeExtremes, color): match color: case Color.RED: - colorRawImageVisible = redRawImageVisible + imageNpArray = redRawImageVisible case Color.GREEN_RIGHT: - colorRawImageVisible = greenRightRawImageVisible + imageNpArray = greenRightRawImageVisible case Color.GREEN_BOTTOM: - colorRawImageVisible = greenBottomRawImageVisible + imageNpArray = greenBottomRawImageVisible case Color.BLUE: - colorRawImageVisible = blueRawImageVisible - - if computeExtremes: - colorRawImageVisibleMin = colorRawImageVisible.min() - colorRawImageVisibleMax = colorRawImageVisible.max() - if minColor is None or colorRawImageVisibleMin < minColor: - minColor = colorRawImageVisibleMin - if maxColor is None or colorRawImageVisibleMax > maxColor: - maxColor = colorRawImageVisibleMax - return - imageNpArray = (colorRawImageVisible - minColor) / (maxColor - minColor) - # 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. + imageNpArray = blueRawImageVisible else: imagePil = Image.open(imageFilePath) imageNpArray = img_as_float(np.array(imagePil)) + + if computeExtremes: + colorRawImageVisibleMin = imageNpArray.min() + colorRawImageVisibleMax = imageNpArray.max() + if minColor is None or colorRawImageVisibleMin < minColor: + minColor = colorRawImageVisibleMin + if maxColor is None or colorRawImageVisibleMax > maxColor: + maxColor = colorRawImageVisibleMax + return + + if imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW'): + imageNpArray = (imageNpArray - minColor) / (maxColor - minColor) + # 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. return imageNpArray # `color` is the actual color to estimate PRNU with. @@ -143,10 +145,10 @@ def saveNpArray(fileName, npArray): if denoiser == 'mean': means = {} - for color in Color: + for color in colors: colorMean = None numberOfImagesInColorMean = 0 - for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} images'): + for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color colored images'): imageNpArray = getImageNpArray(imageFileName, False, color) if colorMean is None: colorMean = imageNpArray diff --git a/datasets/raise/show_mean_noise.py b/datasets/raise/show_mean_noise.py index 0ddb0cd..f603dc5 100644 --- a/datasets/raise/show_mean_noise.py +++ b/datasets/raise/show_mean_noise.py @@ -3,6 +3,8 @@ import matplotlib.pyplot as plt fileName = 'mean_flat-field_nef_wavelet_blue' npArray = np.load(f'{fileName}.npy') +# For other than raw images: +#npArray = (npArray - npArray.min()) / (npArray.max() - npArray.min()) plt.imsave(f'{fileName}.png', npArray) #plt.imshow(npArray) #plt.show() \ No newline at end of file