Compare commits

..

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

2 changed files with 9 additions and 18 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
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color, mergeSingleColorChannelImagesAccordingToBayerFilter, rescaleRawImageForDenoiser, updateExtremes, saveNpArray
import sys
import os
import random
@ -12,7 +12,7 @@ sys.path.insert(0, '../../algorithms/distance/')
from rms_diff import rmsDiffNumpy
DENOISER = 'mean'
DENOISER = 'wavelet'
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 = min([len(imagesCamerasFileNames[camera]) for camera in IMAGES_CAMERAS_FOLDER])
minimumNumberOfImagesCameras = 16#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,22 +60,19 @@ def getImageFilePath(camera, cameraImageIndex):
def getSingleColorChannelImages(camera, cameraImageIndex):
imageFilePath = getImageFilePath(camera, cameraImageIndex)
singleColorChannelImages = {color: rescaleIfNeeded(getImageCrop(getColorChannel(imageFilePath, color), minimalColorChannelCameraResolution), minColor, maxColor) for color in Color}
singleColorChannelImages = {color: rescaleIfNeeded(getColorChannel(imageFilePath, color)[:minimalColorChannelCameraResolution[0],:minimalColorChannelCameraResolution[1]], minColor, maxColor) for color in Color}
return singleColorChannelImages
def getMultipleColorsImage(singleColorChannelImages):
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
return multipleColorsImage
def getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera):
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) if DENOISER != 'mean' else cameraColorMeans[camera][color] for color in Color}
def getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage):
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) 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
@ -93,7 +90,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
singleColorChannelImages = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
imagePrnuEstimateNpArray = getImagePrnuEstimatedNpArray(singleColorChannelImages, multipleColorsImage)
cameraTestingImagesNoise[camera] = cameraTestingImagesNoise.get(camera, []) + [imagePrnuEstimateNpArray]
for cameraTrainingImageIndex in tqdm(range(minimumNumberOfImagesCameras if computeExtremes else numberOfTrainingImages), 'Camera training image index'):
@ -105,7 +102,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
minColor, maxColor = updateExtremes(multipleColorsImage, minColor, maxColor)
continue
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
imagePrnuEstimateNpArray = getImagePrnuEstimatedNpArray(singleColorChannelImages, multipleColorsImage)
cameraIterativeMean = camerasIterativeMean[camera]
cameraIterativeMean.add(imagePrnuEstimateNpArray)

View File

@ -132,14 +132,12 @@ def updateExtremes(imageNpArray, minColor, maxColor):
def print(*toPrint):
__builtin__.print(datetime.now(), *toPrint)
def getColorMeans(imagesFileNames, colors, denoiser, singleColorChannelCropResolution = None):
def getColorMeans(imagesFileNames, colors, denoiser):
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
@ -158,7 +156,3 @@ 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