Restore other than raw images support

This commit is contained in:
Benjamin Loison 2024-04-25 18:12:36 +02:00
parent f88b6ec1a9
commit 719bb487dd
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 24 additions and 20 deletions

View File

@ -21,8 +21,8 @@ imagesFolderPathFileName = imagesFolderPath.replace('/', '_')
denoiser = 'mean'
raiseNotFlatFields = False
# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color`.
colors = Color
# `[Color.RED, Color.GREEN_RIGHT, ...]` or `Color` or `[None]` for not raw images.
colors = [None]
if denoiser != 'mean':
denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
@ -80,28 +80,30 @@ def getImageNpArray(imageFileName, computeExtremes, color):
match color:
case Color.RED:
colorRawImageVisible = redRawImageVisible
imageNpArray = redRawImageVisible
case Color.GREEN_RIGHT:
colorRawImageVisible = greenRightRawImageVisible
imageNpArray = greenRightRawImageVisible
case Color.GREEN_BOTTOM:
colorRawImageVisible = greenBottomRawImageVisible
imageNpArray = greenBottomRawImageVisible
case Color.BLUE:
colorRawImageVisible = blueRawImageVisible
if computeExtremes:
colorRawImageVisibleMin = colorRawImageVisible.min()
colorRawImageVisibleMax = colorRawImageVisible.max()
if minColor is None or colorRawImageVisibleMin < minColor:
minColor = colorRawImageVisibleMin
if maxColor is None or colorRawImageVisibleMax > maxColor:
maxColor = colorRawImageVisibleMax
return
imageNpArray = (colorRawImageVisible - minColor) / (maxColor - minColor)
# 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.
imageNpArray = blueRawImageVisible
else:
imagePil = Image.open(imageFilePath)
imageNpArray = img_as_float(np.array(imagePil))
if computeExtremes:
colorRawImageVisibleMin = imageNpArray.min()
colorRawImageVisibleMax = imageNpArray.max()
if minColor is None or colorRawImageVisibleMin < minColor:
minColor = colorRawImageVisibleMin
if maxColor is None or colorRawImageVisibleMax > maxColor:
maxColor = colorRawImageVisibleMax
return
if imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW'):
imageNpArray = (imageNpArray - minColor) / (maxColor - minColor)
# 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
# `color` is the actual color to estimate PRNU with.
@ -143,10 +145,10 @@ def saveNpArray(fileName, npArray):
if denoiser == 'mean':
means = {}
for color in Color:
for color in colors:
colorMean = None
numberOfImagesInColorMean = 0
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color} images'):
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color colored images'):
imageNpArray = getImageNpArray(imageFileName, False, color)
if colorMean is None:
colorMean = imageNpArray

View File

@ -3,6 +3,8 @@ import matplotlib.pyplot as plt
fileName = 'mean_flat-field_nef_wavelet_blue'
npArray = np.load(f'{fileName}.npy')
# For other than raw images:
#npArray = (npArray - npArray.min()) / (npArray.max() - npArray.min())
plt.imsave(f'{fileName}.png', npArray)
#plt.imshow(npArray)
#plt.show()