From 7ed6ff5adbeef960f72122b86046d4e76fe988a4 Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Wed, 15 May 2024 19:20:19 +0200 Subject: [PATCH] Add `RESOLUTION` support for `Denoiser.MEAN` in `extract_noise.py` --- datasets/raise/extract_noise.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py index 548f08e..4941004 100755 --- a/datasets/raise/extract_noise.py +++ b/datasets/raise/extract_noise.py @@ -54,9 +54,14 @@ def getImageFilePath(imageFileName): # `color` is the actual color to estimate PRNU with. def treatImage(imageFileName, computeExtremes = False, color = None): - global estimatedPrnuIterativeMean + global estimatedPrnuIterativeMean, minColor, maxColor imageFilePath = getImageFilePath(imageFileName) - imageNpArray = getImageNpArray(imageFilePath, computeExtremes, color, DENOISER) + imageNpArray, minColor, maxColor = getImageNpArray(imageFilePath, computeExtremes, color, DENOISER, minColor, maxColor) + # What about `{min,max}Color`? + if RESOLUTION is not None: + imageNpArrayHeight, imageNpArrayWidth = imageNpArray.shape + padHeight, padWidth = [(imageNpArrayDimension - RESOLUTION[0]) // 2 for dimensionIndex, imageNpArrayDimension in enumerate([imageNpArrayHeight, imageNpArrayWidth])] + imageNpArray = imageNpArray[padHeight:-padHeight, padWidth:-padWidth] if imageNpArray is None: return if DENOISER != Denoiser.MEAN: @@ -72,13 +77,15 @@ if (minColor is None or maxColor is None) and DENOISER != Denoiser.MEAN: for color in COLORS: treatImage(imageFileName, computeExtremes = True, color = color) - # To skip this step next time. + # To skip this step next time # Maybe thanks to `rawpy.RawPy` fields, possibly stating device maximal value, can avoid doing so to some extent. print(f'{minColor=}') print(f'{maxColor=}') if DENOISER == Denoiser.MEAN: - colorMeans = getColorMeans(imagesFileNames, COLORS) + print(imagesFileNames) + imagesFilePaths = list(map(getImageFilePath, imagesFileNames)) + colorMeans = getColorMeans(imagesFilePaths, COLORS, RESOLUTION) for color in Color: colorMeans[color] = colorMeans[color] fileName = f'mean_{imagesFolderPathFileName}_{color}'