Compare commits

...

2 Commits

Author SHA1 Message Date
Benjamin Loison
a8fa053687
#49: Get PRNU by using RAW images 2024-04-16 03:02:58 +02:00
Benjamin Loison
6251c487e2
Add temporarily maxGreen computation
And got:

```
Denoising images:   0%|                                                                      | 0/100 [00:00<?, ?it/s]maxGreen=2275
Denoising images:   1%|▌                                                             | 1/100 [00:00<01:11,  1.38it/s]maxGreen=2377
Denoising images:   2%|█▏                                                            | 2/100 [00:01<01:18,  1.24it/s]maxGreen=3468
Denoising images:  19%|███████████▌                                                 | 19/100 [00:11<00:46,  1.75it/s]maxGreen=4908
Denoising images: 100%|████████████████████████████████████████████████████████████| 100/100 [00:57<00:00,  1.74it/s]
```
2024-04-16 02:51:27 +02:00

View File

@ -33,35 +33,34 @@ 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
def treatImage(imageFileName):
global mean, numberOfImagesInMean
global mean, numberOfImagesInMean, minGreen
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
if imageFileName.endswith('.NEF'):
imageFileName = 'ra2c888f8t.NEF'
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
print(imageFilePath)
with rawpy.imread(imageFilePath) as raw:
colorDesc = raw.color_desc.decode('ascii')
assert colorDesc == 'RGBG'
assert np.array_equal(raw.raw_pattern, np.array([[3, 2], [0, 1]], dtype = np.uint8))
assert np.array_equal(raw.raw_pattern, np.array([[0, 1], [3, 2]], dtype = np.uint8))
rawImageVisible = raw.raw_image_visible.copy()
centerY = 2263
centerX = 237
RANGE = 5
rawImageVisible = rawImageVisible.astype(np.float64)
rawImageVisibleShape = rawImageVisible.shape
for y in range(0, rawImageVisibleShape[0], 2):
for x in range(0, rawImageVisibleShape[1], 2):
rawImageVisible[y, x] *= -1
print(rawImageVisible[centerY - RANGE:centerY + RANGE, centerX - RANGE:centerX + RANGE])
#greenRawImageVisible = raw.rawImageVisible
greenRawImageVisible = rawImageVisible[1::2, ::2]
'''
greenRawImageVisibleMin = greenRawImageVisible.min()
if minGreen is None or greenRawImageVisibleMin < minGreen:
minGreen = greenRawImageVisibleMin
print(minGreen)
'''
imageNpArray = (greenRawImageVisible - minGreen) / (4908 - minGreen)
# Pay attention to range of values expected by the denoiser.
exit(1)
# 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, channel_axis=-1, convert2ycbcr=True, rescale_sigma=True)
imageDenoisedNpArray = denoise(imageNpArray, rescale_sigma=True)
#print(imageNpArray, imageDenoisedNpArray)
imageNoiseNpArray = imageNpArray - imageDenoisedNpArray
if mean is None:
mean = imageNoiseNpArray