Compare commits

..

No commits in common. "514413e1ddcec728a03cc2da2306ecf1294f3a80" and "d8c7b8b0efed023790a4d360573a4db3dea64a56" have entirely different histories.

2 changed files with 12 additions and 18 deletions

View File

@ -4,8 +4,9 @@ import numpy as np
import os
from tqdm import tqdm
import csv
from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel, saveNpArray, rescaleRawImageForDenoiser, updateExtremes, getColorMeans
from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel, saveNpArray, rescaleRawImageForDenoiser, updateExtremes
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
imagesFolderPath = 'rafael/arw'
imagesFolderPathFileName = escapeFilePath(imagesFolderPath)
@ -74,7 +75,7 @@ def treatImage(imageFileName, computeExtremes = False, color = None):
if denoiser != 'mean':
imageDenoisedNpArray = denoise(imageNpArray, denoiser)
else:
imageDenoisedNpArray = colorMeans[color]
imageDenoisedNpArray = means[color]
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
estimatedPrnuIterativeMean.add(imageNoiseNpArray)
@ -90,12 +91,17 @@ if (minColor is None or maxColor is None) and denoiser != 'mean':
print(f'{maxColor=}')
if denoiser == 'mean':
colorMeans = getColorMeans(imagesFileNames, colors)
for color in Color:
colorMeans[color] = colorMeans[color]
means = {}
for color in colors:
colorIterativeMean = iterativeMean()
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} colored images'):
imageNpArray = getImageNpArray(imageFileName, False, color)
imageNpArray = gaussian_filter(imageNpArray, sigma = 5)
colorIterativeMean.add(imageNpArray)
means[color] = colorIterativeMean.mean
fileName = f'mean_{imagesFolderPathFileName}_{color}'
# Then use `merge_single_color_channel_images_according_to_bayer_filter.py` to consider all color channels, instead of saving this single color channel as an image.
saveNpArray(fileName, colorMeans[color])
saveNpArray(fileName, colorIterativeMean.mean)
for color in colors:
estimatedPrnuIterativeMean = iterativeMean()

View File

@ -7,7 +7,6 @@ from PIL import Image
from skimage import img_as_float
from datetime import datetime
import builtins as __builtin__
from scipy.ndimage import gaussian_filter
class Color(Enum):
RED = auto()
@ -131,14 +130,3 @@ def updateExtremes(imageNpArray, minColor, maxColor):
def print(*toPrint):
__builtin__.print(datetime.now(), *toPrint)
def getColorMeans(imagesFileNames, colors = Color):
colorMeans = {}
for color in colors:
colorIterativeMean = iterativeMean()
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} colored images'):
imageNpArray = getImageNpArray(imageFileName, False, color)
imageNpArray = gaussian_filter(imageNpArray, sigma = 5)
colorIterativeMean.add(imageNpArray)
colorMeans[color] = colorIterativeMean.mean
return colorMeans