Add Denoiser Enum

This commit is contained in:
Benjamin Loison
2024-05-03 03:49:15 +02:00
parent 9fd44debf5
commit d7f7728211
4 changed files with 27 additions and 20 deletions

View File

@@ -18,19 +18,28 @@ class Color(Enum):
def __str__(self):
return self.name.lower()
class Denoiser(Enum):
WAVELET = auto()
BILATERAL = auto()
TV_CHAMBOLLE = auto()
MEAN = auto()
def __str__(self):
return self.name.lower()
# Among:
# - `wavelet`
# - `bilateral`
# - `tv_chambolle`
def denoise(imageNpArray, denoiserName):
skImageRestorationDenoise = getattr(skimage.restoration, f'denoise_{denoiserName}')
def denoise(imageNpArray, denoiser):
skImageRestorationDenoise = getattr(skimage.restoration, f'denoise_{denoiser}')
match denoiserName:
case 'wavelet':
match denoiser:
case Denoiser.WAVELET:
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, rescale_sigma=True)
case 'bilateral':
case Denoiser.BILATERAL:
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, sigma_color=0.05, sigma_spatial=15)
case 'tv_chambolle':
case Denoiser.TV_CHAMBOLLE:
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, weight=0.2)
return imageDenoisedNpArray
@@ -137,7 +146,7 @@ def getColorMeans(imagesFileNames, colors, singleColorChannelCropResolution = No
for color in colors:
colorIterativeMean = iterativeMean()
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} colored images'):
imageNpArray = getImageNpArray(imageFileName, False, color, 'mean')
imageNpArray = getImageNpArray(imageFileName, False, color, Denoiser.MEAN)
if singleColorChannelCropResolution is not None:
imageNpArray = getImageCrop(imageNpArray, singleColorChannelCropResolution)
imageNpArray = gaussian_filter(imageNpArray, sigma = 5)
@@ -153,7 +162,7 @@ def getImageNpArray(imageFilePath, computeExtremes, color, denoiser):
minColor, maxColor = updateExtremes(imageNpArray, minColor, maxColor)
return
if isARawImage(imageFilePath) and denoiser != 'mean':
if isARawImage(imageFilePath) and denoiser != 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.