From 4bea5e3a97023dde9a34de1f6bbface567cf14fe Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Fri, 3 May 2024 02:32:05 +0200 Subject: [PATCH] Move `getImageNpArray` to `utils.py` --- datasets/raise/extract_noise.py | 20 +++----------------- datasets/raise/utils.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py index 220540d..264d14a 100755 --- a/datasets/raise/extract_noise.py +++ b/datasets/raise/extract_noise.py @@ -4,7 +4,7 @@ import numpy as np import os from tqdm import tqdm import csv -from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel, saveNpArray, rescaleRawImageForDenoiser, updateExtremes, getColorMeans +from utils import Color, denoise, iterativeMean, escapeFilePath, saveNpArray, getColorMeans, getImageNpArray import matplotlib.pyplot as plt imagesFolderPath = 'rafael/arw' @@ -54,25 +54,11 @@ def getImageFilePath(imageFileName): imageFilePath = f'{imagesFolderPath}/{imageFileName}' return imageFilePath -def getImageNpArray(imageFileName, computeExtremes, color): - global minColor, maxColor - imageFilePath = getImageFilePath(imageFileName) - imageNpArray = getColorChannel(imageFilePath, color) - - if computeExtremes: - minColor, maxColor = updateExtremes(imageNpArray, minColor, maxColor) - return - - if isARawImage(imageFileName) and denoiser != 'mean': - imageNpArray = rescaleRawImageForDenoiser(imageNpArray, minColor, maxColor) - # 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. def treatImage(imageFileName, computeExtremes = False, color = None): global estimatedPrnuIterativeMean - imageNpArray = getImageNpArray(imageFileName, computeExtremes, color) + imageFilePath = getImageFilePath(imageFileName) + imageNpArray = getImageNpArray(imageFilePath, computeExtremes, color) if imageNpArray is None: return if denoiser != 'mean': diff --git a/datasets/raise/utils.py b/datasets/raise/utils.py index 7314baa..4b33340 100644 --- a/datasets/raise/utils.py +++ b/datasets/raise/utils.py @@ -142,3 +142,17 @@ def getColorMeans(imagesFileNames, colors = Color): colorIterativeMean.add(imageNpArray) colorMeans[color] = colorIterativeMean.mean return colorMeans + +def getImageNpArray(imageFilePath, computeExtremes, color): + global minColor, maxColor + imageNpArray = getColorChannel(imageFilePath, color) + + if computeExtremes: + minColor, maxColor = updateExtremes(imageNpArray, minColor, maxColor) + return + + if isARawImage(imageFilePath) and denoiser != 'mean': + imageNpArray = rescaleRawImageForDenoiser(imageNpArray, minColor, maxColor) + # 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