Add RESOLUTION support for Denoiser.MEAN in extract_noise.py

This commit is contained in:
Benjamin Loison 2024-05-15 19:20:19 +02:00
parent ec4657eda8
commit 7ed6ff5adb
No known key found for this signature in database

View File

@ -54,9 +54,14 @@ def getImageFilePath(imageFileName):
# `color` is the actual color to estimate PRNU with.
def treatImage(imageFileName, computeExtremes = False, color = None):
global estimatedPrnuIterativeMean
global estimatedPrnuIterativeMean, minColor, maxColor
imageFilePath = getImageFilePath(imageFileName)
imageNpArray = getImageNpArray(imageFilePath, computeExtremes, color, DENOISER)
imageNpArray, minColor, maxColor = getImageNpArray(imageFilePath, computeExtremes, color, DENOISER, minColor, maxColor)
# What about `{min,max}Color`?
if RESOLUTION is not None:
imageNpArrayHeight, imageNpArrayWidth = imageNpArray.shape
padHeight, padWidth = [(imageNpArrayDimension - RESOLUTION[0]) // 2 for dimensionIndex, imageNpArrayDimension in enumerate([imageNpArrayHeight, imageNpArrayWidth])]
imageNpArray = imageNpArray[padHeight:-padHeight, padWidth:-padWidth]
if imageNpArray is None:
return
if DENOISER != Denoiser.MEAN:
@ -72,13 +77,15 @@ if (minColor is None or maxColor is None) and DENOISER != Denoiser.MEAN:
for color in COLORS:
treatImage(imageFileName, computeExtremes = True, color = color)
# To skip this step next time.
# To skip this step next time
# Maybe thanks to `rawpy.RawPy` fields, possibly stating device maximal value, can avoid doing so to some extent.
print(f'{minColor=}')
print(f'{maxColor=}')
if DENOISER == Denoiser.MEAN:
colorMeans = getColorMeans(imagesFileNames, COLORS)
print(imagesFileNames)
imagesFilePaths = list(map(getImageFilePath, imagesFileNames))
colorMeans = getColorMeans(imagesFilePaths, COLORS, RESOLUTION)
for color in Color:
colorMeans[color] = colorMeans[color]
fileName = f'mean_{imagesFolderPathFileName}_{color}'