Compute automatically extreme values
This commit is contained in:
parent
a8fa053687
commit
d4e13ed123
@ -33,10 +33,11 @@ if requiresRaiseFiltering:
|
||||
|
||||
imagesFileNames = [imageFileName for imageFileName in tqdm(imagesFileNames, 'Filtering images') if files[imageFileName]['Device'] == 'Nikon D7000' and Image.open(f'{imagesFolderPath}/{imageFileName}').size == (4946, 3278)]
|
||||
|
||||
minGreen = 308#None
|
||||
minColor = None
|
||||
maxColor = None
|
||||
|
||||
def treatImage(imageFileName):
|
||||
global mean, numberOfImagesInMean, minGreen
|
||||
def treatImage(imageFileName, computeExtremes = False):
|
||||
global mean, numberOfImagesInMean, minColor, maxColor
|
||||
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
|
||||
if imageFileName.endswith('.NEF'):
|
||||
with rawpy.imread(imageFilePath) as raw:
|
||||
@ -45,22 +46,22 @@ def treatImage(imageFileName):
|
||||
assert np.array_equal(raw.raw_pattern, np.array([[0, 1], [3, 2]], dtype = np.uint8))
|
||||
rawImageVisible = raw.raw_image_visible.copy()
|
||||
greenRawImageVisible = rawImageVisible[1::2, ::2]
|
||||
'''
|
||||
greenRawImageVisibleMin = greenRawImageVisible.min()
|
||||
if minGreen is None or greenRawImageVisibleMin < minGreen:
|
||||
minGreen = greenRawImageVisibleMin
|
||||
print(minGreen)
|
||||
'''
|
||||
imageNpArray = (greenRawImageVisible - minGreen) / (4908 - minGreen)
|
||||
if computeExtremes:
|
||||
greenRawImageVisibleMin = greenRawImageVisible.min()
|
||||
greenRawImageVisibleMax = greenRawImageVisible.max()
|
||||
if minColor is None or greenRawImageVisibleMin < minColor:
|
||||
minColor = greenRawImageVisibleMin
|
||||
if maxColor is None or greenRawImageVisibleMax > maxColor:
|
||||
maxColor = greenRawImageVisibleMax
|
||||
return
|
||||
imageNpArray = (greenRawImageVisible - minGreen) / (maxGreen - minGreen)
|
||||
# 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.
|
||||
#exit(1)
|
||||
else:
|
||||
imagePil = Image.open(imageFilePath)
|
||||
imageNpArray = img_as_float(np.array(imagePil))
|
||||
# As the arguments differ from a denoiser to the other should use a match instead.
|
||||
imageDenoisedNpArray = denoise(imageNpArray, rescale_sigma=True)
|
||||
#print(imageNpArray, imageDenoisedNpArray)
|
||||
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
|
||||
if mean is None:
|
||||
mean = imageNoiseNpArray
|
||||
@ -68,6 +69,9 @@ def treatImage(imageFileName):
|
||||
mean = ((mean * numberOfImagesInMean) + imageNoiseNpArray) / (numberOfImagesInMean + 1)
|
||||
numberOfImagesInMean += 1
|
||||
|
||||
for imageFileName in tqdm(imagesFileNames, 'Computing extremes of images'):
|
||||
treatImage(imageFileName, computeExtremes = True)
|
||||
|
||||
for imageFileName in tqdm(imagesFileNames, 'Denoising images'):
|
||||
treatImage(imageFileName)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user