Output an estimated PRNU per color channel
This commit is contained in:
parent
f15af68bba
commit
8c9dfc2e41
@ -13,15 +13,11 @@ from enum import Enum, auto
|
||||
imagesFolderPath = '/mnt/HDD0/raise'
|
||||
imagesFolderPathFileName = imagesFolderPath.replace('/', '_')
|
||||
denoiser = 'wavelet'
|
||||
npArrayFilePath = f'mean_{imagesFolderPathFileName}_{denoiser}.npy'
|
||||
|
||||
raiseNotFlatFields = False
|
||||
|
||||
denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
|
||||
|
||||
mean = None
|
||||
numberOfImagesInMean = 0
|
||||
|
||||
imagesFileNames = os.listdir(imagesFolderPath + ('/png' if raiseNotFlatFields else ''))
|
||||
|
||||
if raiseNotFlatFields:
|
||||
@ -48,6 +44,9 @@ class Color(Enum):
|
||||
GREEN_BOTTOM = auto()
|
||||
BLUE = auto()
|
||||
|
||||
def __str__(self):
|
||||
return self.name.lower()
|
||||
|
||||
# `color` is the actual color to estimate PRNU with.
|
||||
def treatImage(imageFileName, computeExtremes = False, color = None):
|
||||
global mean, numberOfImagesInMean, minColor, maxColor
|
||||
@ -110,16 +109,23 @@ def treatImage(imageFileName, computeExtremes = False, color = None):
|
||||
mean = ((mean * numberOfImagesInMean) + imageNoiseNpArray) / (numberOfImagesInMean + 1)
|
||||
numberOfImagesInMean += 1
|
||||
|
||||
# Assuming same intensity scale across color channels.
|
||||
for imageFileName in tqdm(imagesFileNames, 'Computing extremes of images'):
|
||||
treatImage(imageFileName, computeExtremes = True, color = Color.GREEN)
|
||||
for color in Color:
|
||||
treatImage(imageFileName, computeExtremes = True, color = color)
|
||||
|
||||
# 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=}')
|
||||
|
||||
for imageFileName in tqdm(imagesFileNames, 'Denoising images'):
|
||||
treatImage(imageFileName)
|
||||
for color in Color:
|
||||
mean = None
|
||||
numberOfImagesInMean = 0
|
||||
|
||||
with open(npArrayFilePath, 'wb') as f:
|
||||
np.save(f, mean)
|
||||
for imageFileName in tqdm(imagesFileNames, 'Denoising images'):
|
||||
treatImage(imageFileName)
|
||||
|
||||
npArrayFilePath = f'mean_{imagesFolderPathFileName}_{denoiser}_{color}.npy'
|
||||
with open(npArrayFilePath, 'wb') as f:
|
||||
np.save(f, mean)
|
||||
|
Loading…
Reference in New Issue
Block a user