From 3ffcd33efe5cd947e5c65ffeecff1ac1d1e165d4 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Fri, 26 Apr 2024 04:39:06 +0200 Subject: [PATCH] Add Gaussian filter to blur images when using mean as denoiser See https://docs.scipy.org/doc/scipy-1.13.0/reference/generated/scipy.ndimage.gaussian_filter.html#ba1e4df0-d4be-47c2-81e5-059286837a2b. --- datasets/raise/extract_noise.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py index 83c2f77..895488d 100755 --- a/datasets/raise/extract_noise.py +++ b/datasets/raise/extract_noise.py @@ -10,6 +10,7 @@ import csv import rawpy from utils import Color import matplotlib.pyplot as plt +from scipy.ndimage import gaussian_filter imagesFolderPath = 'rafael/arw' imagesFolderPathFileName = imagesFolderPath.replace('/', '_') @@ -100,7 +101,7 @@ def getImageNpArray(imageFileName, computeExtremes, color): maxColor = colorRawImageVisibleMax return - if imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW'): + if (imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW')) and denoiser != 'mean': 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. @@ -128,7 +129,7 @@ def treatImage(imageFileName, computeExtremes = False, color = None): mean = ((mean * numberOfImagesInMean) + imageNoiseNpArray) / (numberOfImagesInMean + 1) numberOfImagesInMean += 1 -if minColor is None or maxColor is None: +if (minColor is None or maxColor is None) and denoiser != 'mean': # Assuming same intensity scale across color channels. for imageFileName in tqdm(imagesFileNames, 'Computing extremes of images'): for color in colors: @@ -148,8 +149,9 @@ if denoiser == 'mean': for color in colors: colorMean = None numberOfImagesInColorMean = 0 - for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color colored images'): + for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} colored images'): imageNpArray = getImageNpArray(imageFileName, False, color) + imageNpArray = gaussian_filter(imageNpArray, sigma = 5) if colorMean is None: colorMean = imageNpArray else: