Move denoise
from extract_noise.py
to utils.py
See next commit leveraging it in `split_and_compare_prnus_of_subgroups.py`
This commit is contained in:
parent
6a93b04686
commit
9d2903af60
@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import skimage.restoration
|
||||
from skimage import img_as_float
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
@ -8,26 +7,20 @@ import os
|
||||
from tqdm import tqdm
|
||||
import csv
|
||||
import rawpy
|
||||
from utils import Color
|
||||
from utils import Color, denoise
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.ndimage import gaussian_filter
|
||||
|
||||
imagesFolderPath = 'rafael/arw'
|
||||
imagesFolderPathFileName = imagesFolderPath.replace('/', '_')
|
||||
# Among:
|
||||
# - `wavelet`
|
||||
# - `bilateral`
|
||||
# - `tv_chambolle`
|
||||
# - `mean`
|
||||
# `denoise` possible denoisers and `mean`.
|
||||
denoiser = 'mean'
|
||||
|
||||
raiseNotFlatFields = False
|
||||
# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color` or `[None]` for not raw images.
|
||||
colors = [None]
|
||||
|
||||
if denoiser != 'mean':
|
||||
denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
|
||||
|
||||
imagesFileNames = os.listdir(imagesFolderPath + ('/png' if raiseNotFlatFields else ''))
|
||||
|
||||
if raiseNotFlatFields:
|
||||
@ -113,15 +106,10 @@ def treatImage(imageFileName, computeExtremes = False, color = None):
|
||||
imageNpArray = getImageNpArray(imageFileName, computeExtremes, color)
|
||||
if imageNpArray is None:
|
||||
return
|
||||
match denoiser:
|
||||
case 'wavelet':
|
||||
imageDenoisedNpArray = denoise(imageNpArray, rescale_sigma=True)
|
||||
case 'bilateral':
|
||||
imageDenoisedNpArray = denoise(imageNpArray, sigma_color=0.05, sigma_spatial=15)
|
||||
case 'tv_chambolle':
|
||||
imageDenoisedNpArray = denoise(imageNpArray, weight=0.2)
|
||||
case 'mean':
|
||||
imageDenoisedNpArray = means[color]
|
||||
if denoiser != 'mean':
|
||||
imageDenoisedNpArray = denoise(imageNpArray, denoiser)
|
||||
else:
|
||||
imageDenoisedNpArray = means[color]
|
||||
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
|
||||
if mean is None:
|
||||
mean = imageNoiseNpArray
|
||||
|
@ -1,4 +1,5 @@
|
||||
from enum import Enum, auto
|
||||
import skimage.restoration
|
||||
|
||||
class Color(Enum):
|
||||
RED = auto()
|
||||
@ -8,3 +9,19 @@ class Color(Enum):
|
||||
|
||||
def __str__(self):
|
||||
return self.name.lower()
|
||||
|
||||
# Among:
|
||||
# - `wavelet`
|
||||
# - `bilateral`
|
||||
# - `tv_chambolle`
|
||||
def denoise(imageNpArray, denoiserName):
|
||||
skImageRestorationDenoise = getattr(skimage.restoration, f'denoise_{denoiserName}')
|
||||
|
||||
match denoiserName:
|
||||
case 'wavelet':
|
||||
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, rescale_sigma=True)
|
||||
case 'bilateral':
|
||||
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, sigma_color=0.05, sigma_spatial=15)
|
||||
case 'tv_chambolle':
|
||||
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, weight=0.2)
|
||||
return imageDenoisedNpArray
|
Loading…
Reference in New Issue
Block a user