Compare commits

...

3 Commits

Author SHA1 Message Date
Benjamin Loison
60a9dfe89c
Update forgotten to commit scripts 2024-05-15 20:00:44 +02:00
Benjamin Loison
6e7e06b85c
Clean attribute_source_camera.py 2024-05-15 19:57:56 +02:00
Benjamin Loison
e3e3d44ca9
#62: Comment loading images to memory in favor of cropping 2024-05-15 19:57:04 +02:00
2 changed files with 8 additions and 4 deletions

View File

@ -111,6 +111,7 @@ returnSingleColorChannelImage = lambda singleColorChannelImage, _minColor, _maxC
# Assume to have `{min,max}Color` hardcoded.
# Can just load to memory `getSingleColorChannelImages`, see [Robust_image_source_identification_on_modern_smartphones/issues/62#issuecomment-1861](https://gitea.lemnoslife.com/Benjamin_Loison/Robust_image_source_identification_on_modern_smartphones/issues/62#issuecomment-1861).
'''
rescaleIfNeeded = rescaleRawImageForDenoiser
cameraTrainingImages = {}
for cameraTrainingImageIndex in tqdm(range(numberOfTrainingImages), 'Load to memory camera training image'):
@ -124,6 +125,7 @@ for camera in IMAGES_CAMERAS_FOLDER:
for cameraTestingImageIndex in tqdm(range(numberOfTestingImages), 'Load to memory camera testing image'):
singleColorChannelImages = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
singleColorChannelTestingImages[camera] += [singleColorChannelImages]
'''
# 2 loops:
# - the first one is about computing `{min,max}Color`
@ -139,7 +141,8 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
for cameraTestingImageIndex in tqdm(range(numberOfTestingImages), 'Camera testing image index'):
print(f'{camera=} {numberOfTrainingImages + cameraTestingImageIndex=}')
singleColorChannelImages = singleColorChannelTestingImages[camera][cameraTestingImageIndex]#getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
#singleColorChannelImages = singleColorChannelTestingImages[camera][cameraTestingImageIndex]
singleColorChannelImages = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
@ -156,7 +159,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
minColor, maxColor = updateExtremes(multipleColorsImage, minColor, maxColor)
continue
if DENOISER == Denoiser.MEAN:
if DENOISER == Denoiser.MEAN and not PREDICT_ONLY_ON_WHOLE_TRAINING_SET:
for color in Color:
cameraColorMeans[camera][color].add(singleColorChannelImages[color])
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
@ -182,7 +185,8 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
if DENOISER != Denoiser.MEAN:
cameraTestingImageNoise = cameraTestingImagesNoise[actualCamera][cameraTestingImageIndex]
else:
singleColorChannelImages = singleColorChannelTestingImages[camera][cameraTestingImageIndex]#getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
#singleColorChannelImages = singleColorChannelTestingImages[camera][cameraTestingImageIndex]
singleColorChannelImages = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
cameraTestingImageNoise = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)

View File

@ -205,7 +205,7 @@ def getColorMeans(imagesFileNames, colors, singleColorChannelCropResolution = No
for color in colors:
colorIterativeMean = iterativeMean()
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {str(color).replace("_", " ")} colored images'):
imageNpArray = getImageNpArray(imageFileName, False, color, Denoiser.MEAN)
imageNpArray, minColor_, maxColor_ = getImageNpArray(imageFileName, False, color, Denoiser.MEAN, None, None)
if singleColorChannelCropResolution is not None:
imageNpArray = getImageCrop(imageNpArray, singleColorChannelCropResolution)
imageNpArray = gaussian_filter(imageNpArray, sigma = 5)