Add and use isARawImage

This commit is contained in:
Benjamin Loison 2024-04-27 21:46:40 +02:00
parent a0fc38d023
commit b50f013234
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 12 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import os
from tqdm import tqdm
import csv
import rawpy
from utils import Color, denoise, iterativeMean
from utils import Color, denoise, iterativeMean, isARawImage
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
@ -73,7 +73,7 @@ def getImageNpArray(imageFileName, computeExtremes, color):
maxColor = colorRawImageVisibleMax
return
if (imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW')) and denoiser != 'mean':
if isARawImage(imageFileName) and denoiser != 'mean':
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.

View File

@ -38,7 +38,12 @@ class iterativeMean:
self.mean = ((self.mean * self.numberOfElementsInMean) + element) / (self.numberOfElementsInMean + 1)
self.numberOfElementsInMean += 1
def getRawColorChannel(raw):
RAW_IMAGE_FILE_EXTENSIONS = [
'arw',
'nef',
]
def getRawColorChannel(raw, color):
colorDesc = raw.color_desc.decode('ascii')
assert colorDesc == 'RGBG'
assert np.array_equal(raw.raw_pattern, np.array([[0, 1], [3, 2]], dtype = np.uint8))
@ -61,4 +66,7 @@ def getRawColorChannel(raw):
imageNpArray = greenBottomRawImageVisible
case Color.BLUE:
imageNpArray = blueRawImageVisible
return imageNpArray
return imageNpArray
def isARawImage(imageFilePath):
return any([imageFileName.lower().endswith(f'.{rawImageFileExtension}') for rawImageFileExtension in RAW_IMAGE_FILE_EXTENSIONS])