Compare commits
2 Commits
9d33abcea3
...
0c429aa4d6
Author | SHA1 | Date | |
---|---|---|---|
|
0c429aa4d6 | ||
|
fd6a9868fe |
@ -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
|
||||
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 = 'wavelet'
|
||||
DENOISER = 'mean'
|
||||
IMAGES_CAMERAS_FOLDER = {
|
||||
'RAISE': 'flat-field/nef',
|
||||
'Rafael 23/04/24': 'rafael/230424',
|
||||
@ -27,7 +27,7 @@ random.seed(0)
|
||||
for camera in IMAGES_CAMERAS_FOLDER:
|
||||
random.shuffle(imagesCamerasFileNames[camera])
|
||||
|
||||
minimumNumberOfImagesCameras = 16#min([len(imagesCamerasFileNames[camera]) for camera in IMAGES_CAMERAS_FOLDER])
|
||||
minimumNumberOfImagesCameras = min([len(imagesCamerasFileNames[camera]) for camera in IMAGES_CAMERAS_FOLDER])
|
||||
for camera in IMAGES_CAMERAS_FOLDER:
|
||||
imagesCamerasFileNames[camera] = imagesCamerasFileNames[camera][:minimumNumberOfImagesCameras]
|
||||
print(camera, imagesCamerasFileNames[camera])
|
||||
@ -60,19 +60,22 @@ def getImageFilePath(camera, cameraImageIndex):
|
||||
|
||||
def getSingleColorChannelImages(camera, cameraImageIndex):
|
||||
imageFilePath = getImageFilePath(camera, cameraImageIndex)
|
||||
singleColorChannelImages = {color: rescaleIfNeeded(getColorChannel(imageFilePath, color)[:minimalColorChannelCameraResolution[0],:minimalColorChannelCameraResolution[1]], minColor, maxColor) for color in Color}
|
||||
singleColorChannelImages = {color: rescaleIfNeeded(getImageCrop(getColorChannel(imageFilePath, color), minimalColorChannelCameraResolution), minColor, maxColor) for color in Color}
|
||||
return singleColorChannelImages
|
||||
|
||||
def getMultipleColorsImage(singleColorChannelImages):
|
||||
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
|
||||
return multipleColorsImage
|
||||
|
||||
def getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage):
|
||||
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) for color in Color}
|
||||
def getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera):
|
||||
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, DENOISER, minimalColorChannelCameraResolution) for camera in imagesCamerasFilePaths}
|
||||
|
||||
from utils import silentTqdm
|
||||
#tqdm = silentTqdm
|
||||
|
||||
@ -90,7 +93,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
|
||||
singleColorChannelImages = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
|
||||
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
|
||||
|
||||
imagePrnuEstimateNpArray = getImagePrnuEstimatedNpArray(singleColorChannelImages, multipleColorsImage)
|
||||
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
|
||||
|
||||
cameraTestingImagesNoise[camera] = cameraTestingImagesNoise.get(camera, []) + [imagePrnuEstimateNpArray]
|
||||
for cameraTrainingImageIndex in tqdm(range(minimumNumberOfImagesCameras if computeExtremes else numberOfTrainingImages), 'Camera training image index'):
|
||||
@ -102,7 +105,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
|
||||
minColor, maxColor = updateExtremes(multipleColorsImage, minColor, maxColor)
|
||||
continue
|
||||
|
||||
imagePrnuEstimateNpArray = getImagePrnuEstimatedNpArray(singleColorChannelImages, multipleColorsImage)
|
||||
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
|
||||
|
||||
cameraIterativeMean = camerasIterativeMean[camera]
|
||||
cameraIterativeMean.add(imagePrnuEstimateNpArray)
|
||||
|
@ -132,12 +132,14 @@ def updateExtremes(imageNpArray, minColor, maxColor):
|
||||
def print(*toPrint):
|
||||
__builtin__.print(datetime.now(), *toPrint)
|
||||
|
||||
def getColorMeans(imagesFileNames, colors, denoiser):
|
||||
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)
|
||||
if singleColorChannelCropResolution is not None:
|
||||
imageNpArray = getImageCrop(imageNpArray, singleColorChannelCropResolution)
|
||||
imageNpArray = gaussian_filter(imageNpArray, sigma = 5)
|
||||
colorIterativeMean.add(imageNpArray)
|
||||
colorMeans[color] = colorIterativeMean.mean
|
||||
@ -156,3 +158,7 @@ def getImageNpArray(imageFilePath, computeExtremes, color, denoiser):
|
||||
# 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.
|
||||
return imageNpArray
|
||||
|
||||
def getImageCrop(image, cropResolution):
|
||||
imageCrop = image[:cropResolution[0], :cropResolution[1]]
|
||||
return imageCrop
|
||||
|
Loading…
Reference in New Issue
Block a user