Add denoiser mean possibility

This commit is contained in:
Benjamin Loison 2024-04-23 04:39:28 +02:00
parent a15b356e16
commit be9d4f8f4b
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -16,13 +16,15 @@ imagesFolderPathFileName = imagesFolderPath.replace('/', '_')
# - `wavelet`
# - `bilateral`
# - `tv_chambolle`
denoiser = 'bilateral'
# - `mean`
denoiser = 'mean'
raiseNotFlatFields = False
# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color`.
colors = Color
denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
if denoiser != 'mean':
denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
imagesFileNames = os.listdir(imagesFolderPath + ('/png' if raiseNotFlatFields else ''))
@ -114,6 +116,8 @@ def treatImage(imageFileName, computeExtremes = False, color = None):
imageDenoisedNpArray = denoise(imageNpArray, sigma_color=0.05, sigma_spatial=15)
case 'tv_chambolle':
imageDenoisedNpArray = denoise(imageNpArray, weight=0.2)
case 'mean':
imageDenoisedNpArray = imageNpArray - means[color]
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
if mean is None:
mean = imageNoiseNpArray
@ -131,6 +135,21 @@ for imageFileName in tqdm(imagesFileNames, 'Computing extremes of images'):
print(f'{minColor=}')
print(f'{maxColor=}')
if denoiser == 'mean':
means = {}
for color in Color:
colorMean = None
numberOfImagesInColorMean = 0
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} images'):
#print(imageFileName)
imageNpArray = getImageNpArray(imageFileName, False, color)
if colorMean is None:
colorMean = imageNpArray
else:
colorMean = ((colorMean * numberOfImagesInColorMean) + imageNpArray) / (numberOfImagesInColorMean + 1)
numberOfImagesInColorMean += 1
means[color] = colorMean
for color in colors:
mean = None
numberOfImagesInMean = 0