Make extract_noise.py easier to configure by providing denoiser

This commit is contained in:
Benjamin Loison 2024-04-08 04:52:29 +02:00
parent 38d29e3c8f
commit bc06612501
No known key found for this signature in database

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
from skimage.restoration import denoise_tv_chambolle
import skimage.restoration
from skimage import img_as_float
import numpy as np
from PIL import Image
@ -8,7 +8,10 @@ import os
from tqdm import tqdm
imagesFolderPath = 'flat-field'
npArrayFilePath = 'mean.npy'
denoiser = 'wavelet'
npArrayFilePath = f'mean_{imagesFolderPath}_{denoiser}.npy'
denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
mean = None
numberOfImagesInMean = 0
@ -20,7 +23,8 @@ def treatImage(imageFileName):
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
imagePil = Image.open(imageFilePath)
imageNpArray = img_as_float(np.array(imagePil))
imageDenoisedNpArray = denoise_tv_chambolle(imageNpArray, weight=0.2, channel_axis=-1)
# As the arguments differ from a denoiser to the other should use a match instead.
imageDenoisedNpArray = denoise(imageNpArray, channel_axis=-1, convert2ycbcr=True, rescale_sigma=True)
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
if mean is None:
mean = imageNoiseNpArray