Compare commits

..

No commits in common. "f4d8c028b22d8fba941a15edd24229fb7812db74" and "a6ef3977dd364f6dbde12f491aa81a6b4f5be305" have entirely different histories.

View File

@ -14,16 +14,15 @@ 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 ''))
imagesFileNames = os.listdir(imagesFolderPath + '/png')
if raiseNotFlatFields:
requiresRaiseFiltering = True
if requiresRaiseFiltering:
files = {}
with open('RAISE_all.csv') as csvfile:
@ -33,47 +32,31 @@ if raiseNotFlatFields:
files[file] = row
imagesFileNames = [imageFileName for imageFileName in tqdm(imagesFileNames, 'Filtering images') if files[imageFileName]['Device'] == 'Nikon D7000' and Image.open(f'{imagesFolderPath}/png/{imageFileName}').size == (4946, 3278)]
SKY = range(2_699, 2_807)
WALL = range(2_807, 2_912)
#imagesFileNames = [f'DSC0{imageIndex}.ARW' for imageIndex in SKY]
#imagesFileNames = [f'DSC0{imageIndex}.ARW' for imageIndex in range(2807, 2911)]
minColor = None
maxColor = None
def treatImage(imageFileName, computeExtremes = False):
global mean, numberOfImagesInMean, minColor, maxColor
if raiseNotFlatFields:
imageFileName = imageFileName.replace('.png', '.NEF')
imageFilePath = f'{imagesFolderPath}/nef/{imageFileName}'
else:
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
imageFileName = imageFileName.replace('.png', '.NEF')
imageFilePath = f'{imagesFolderPath}/nef/{imageFileName}'
if imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW'):
with rawpy.imread(imageFilePath) as raw:
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))
# RG
# GB
rawImageVisible = raw.raw_image_visible.copy()
redRawImageVisible = rawImageVisible[::2, ::2]
greenRightRawImageVisible = rawImageVisible[::2, 1::2]
greenBottomRawImageVisible = rawImageVisible[1::2, ::2]
blueRawImageVisible = rawImageVisible[1::2, 1::2]
# Actual color to estimate the PRNU with.
colorRawImageVisible = greenBottomRawImageVisible
greenRawImageVisible = rawImageVisible[1::2, ::2]
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
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 = (colorRawImageVisible - minColor) / (maxColor - minColor)
imageNpArray = (greenRawImageVisible - 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.
else: