Compare commits

..

No commits in common. "d7f7728211713ade6de632f3446a35f511d5b041" and "0c429aa4d6ff3552daea51d490623d4c142b20c1" have entirely different histories.

4 changed files with 23 additions and 30 deletions

View File

@ -3,7 +3,7 @@
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color, mergeSingleColorChannelImagesAccordingToBayerFilter, rescaleRawImageForDenoiser, updateExtremes, saveNpArray, getColorMeans, getImageCrop, Denoiser
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color, mergeSingleColorChannelImagesAccordingToBayerFilter, rescaleRawImageForDenoiser, updateExtremes, saveNpArray, getColorMeans, getImageCrop
import sys
import os
import random
@ -12,7 +12,7 @@ sys.path.insert(0, '../../algorithms/distance/')
from rms_diff import rmsDiffNumpy
DENOISER = Denoiser.MEAN
DENOISER = 'mean'
IMAGES_CAMERAS_FOLDER = {
'RAISE': 'flat-field/nef',
'Rafael 23/04/24': 'rafael/230424',
@ -68,13 +68,13 @@ def getMultipleColorsImage(singleColorChannelImages):
return multipleColorsImage
def getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera):
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) if DENOISER != Denoiser.MEAN else cameraColorMeans[camera][color] for color in Color}
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) if DENOISER != 'mean' else cameraColorMeans[camera][color] for color in Color}
multipleColorsDenoisedImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelDenoisedImages)
imagePrnuEstimateNpArray = multipleColorsImage - multipleColorsDenoisedImage
return imagePrnuEstimateNpArray
imagesCamerasFilePaths = {camera: [f'{IMAGES_CAMERAS_FOLDER[camera]}/{imagesCamerasFileName}' for imagesCamerasFileName in imagesCamerasFileNames[camera]] for camera in imagesCamerasFileNames}
cameraColorMeans = {camera: getColorMeans(imagesCamerasFilePaths[camera], Color, minimalColorChannelCameraResolution) for camera in imagesCamerasFilePaths}
cameraColorMeans = {camera: getColorMeans(imagesCamerasFilePaths[camera], Color, DENOISER, minimalColorChannelCameraResolution) for camera in imagesCamerasFilePaths}
from utils import silentTqdm
#tqdm = silentTqdm

View File

@ -4,12 +4,14 @@ import numpy as np
import os
from tqdm import tqdm
import csv
from utils import Color, denoise, iterativeMean, escapeFilePath, saveNpArray, getColorMeans, getImageNpArray, Denoiser
from utils import Color, denoise, iterativeMean, escapeFilePath, saveNpArray, getColorMeans, getImageNpArray
import matplotlib.pyplot as plt
IMAGES_FOLDER_PATH = 'rafael/230424'
imagesFolderPathFileName = escapeFilePath(IMAGES_FOLDER_PATH)
DENOISER = Denoiser.WAVELET
# Among:
# `denoise` possible denoisers and `mean`.
DENOISER = 'mean'
RAISE_NOT_FLAT_FIELDS = False
# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color` or `[None]` for not raw images.
@ -59,14 +61,14 @@ def treatImage(imageFileName, computeExtremes = False, color = None):
imageNpArray = getImageNpArray(imageFilePath, computeExtremes, color, DENOISER)
if imageNpArray is None:
return
if DENOISER != Denoiser.MEAN:
if DENOISER != 'mean':
imageDenoisedNpArray = denoise(imageNpArray, DENOISER)
else:
imageDenoisedNpArray = colorMeans[color]
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
estimatedPrnuIterativeMean.add(imageNoiseNpArray)
if (minColor is None or maxColor is None) and DENOISER != Denoiser.MEAN:
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:
@ -77,8 +79,8 @@ if (minColor is None or maxColor is None) and DENOISER != Denoiser.MEAN:
print(f'{minColor=}')
print(f'{maxColor=}')
if DENOISER == Denoiser.MEAN:
colorMeans = getColorMeans(imagesFileNames, COLORS)
if DENOISER == 'mean':
colorMeans = getColorMeans(imagesFileNames, COLORS, DENOISER)
for color in Color:
colorMeans[color] = colorMeans[color]
fileName = f'mean_{imagesFolderPathFileName}_{color}'

View File

@ -3,7 +3,7 @@
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color, mergeSingleColorChannelImagesAccordingToBayerFilter, rescaleRawImageForDenoiser, updateExtremes, saveNpArray, Denoiser
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color, mergeSingleColorChannelImagesAccordingToBayerFilter, rescaleRawImageForDenoiser, updateExtremes, saveNpArray
import sys
import os
import random
@ -13,7 +13,7 @@ sys.path.insert(0, '../../algorithms/distance/')
from rms_diff import rmsDiffNumpy
NUMBER_OF_SUBGROUPS = 2
DENOISER = Denoiser.WAVELET
DENOISER = 'wavelet'
IMAGES_FOLDER = 'flat-field/NEF'
setting = escapeFilePath(IMAGES_FOLDER) + f'_{DENOISER}'

View File

@ -18,28 +18,19 @@ 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, denoiser):
skImageRestorationDenoise = getattr(skimage.restoration, f'denoise_{denoiser}')
def denoise(imageNpArray, denoiserName):
skImageRestorationDenoise = getattr(skimage.restoration, f'denoise_{denoiserName}')
match denoiser:
case Denoiser.WAVELET:
match denoiserName:
case 'wavelet':
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, rescale_sigma=True)
case Denoiser.BILATERAL:
case 'bilateral':
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, sigma_color=0.05, sigma_spatial=15)
case Denoiser.TV_CHAMBOLLE:
case 'tv_chambolle':
imageDenoisedNpArray = skImageRestorationDenoise(imageNpArray, weight=0.2)
return imageDenoisedNpArray
@ -141,12 +132,12 @@ def updateExtremes(imageNpArray, minColor, maxColor):
def print(*toPrint):
__builtin__.print(datetime.now(), *toPrint)
def getColorMeans(imagesFileNames, colors, singleColorChannelCropResolution = None):
def getColorMeans(imagesFileNames, colors, denoiser, singleColorChannelCropResolution = None):
colorMeans = {}
for color in colors:
colorIterativeMean = iterativeMean()
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} colored images'):
imageNpArray = getImageNpArray(imageFileName, False, color, Denoiser.MEAN)
imageNpArray = getImageNpArray(imageFileName, False, color, denoiser)
if singleColorChannelCropResolution is not None:
imageNpArray = getImageCrop(imageNpArray, singleColorChannelCropResolution)
imageNpArray = gaussian_filter(imageNpArray, sigma = 5)
@ -162,7 +153,7 @@ def getImageNpArray(imageFilePath, computeExtremes, color, denoiser):
minColor, maxColor = updateExtremes(imageNpArray, minColor, maxColor)
return
if isARawImage(imageFilePath) and denoiser != Denoiser.MEAN:
if isARawImage(imageFilePath) and 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.