Compare commits

...

2 Commits

Author SHA1 Message Date
Benjamin Loison
514413e1dd
Add and use getColorMeans 2024-05-03 02:21:01 +02:00
Benjamin Loison
01d18a4943
Rename means to colorMeans
To be clearer for future `attribute_source_camera.py` usage.
2024-05-03 02:13:53 +02:00
2 changed files with 18 additions and 12 deletions

View File

@ -4,9 +4,8 @@ import numpy as np
import os
from tqdm import tqdm
import csv
from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel, saveNpArray, rescaleRawImageForDenoiser, updateExtremes
from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel, saveNpArray, rescaleRawImageForDenoiser, updateExtremes, getColorMeans
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
imagesFolderPath = 'rafael/arw'
imagesFolderPathFileName = escapeFilePath(imagesFolderPath)
@ -75,7 +74,7 @@ def treatImage(imageFileName, computeExtremes = False, color = None):
if denoiser != 'mean':
imageDenoisedNpArray = denoise(imageNpArray, denoiser)
else:
imageDenoisedNpArray = means[color]
imageDenoisedNpArray = colorMeans[color]
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
estimatedPrnuIterativeMean.add(imageNoiseNpArray)
@ -91,17 +90,12 @@ if (minColor is None or maxColor is None) and denoiser != 'mean':
print(f'{maxColor=}')
if denoiser == 'mean':
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
colorMeans = getColorMeans(imagesFileNames, colors)
for color in Color:
colorMeans[color] = colorMeans[color]
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, colorIterativeMean.mean)
saveNpArray(fileName, colorMeans[color])
for color in colors:
estimatedPrnuIterativeMean = iterativeMean()

View File

@ -7,6 +7,7 @@ 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()
@ -130,3 +131,14 @@ 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