Compare commits
No commits in common. "ce644501012444a4624c2d87958ba85d15e238c5" and "f85e63b6e00373d5239c4d405b796e5780b3b3b9" have entirely different histories.
ce64450101
...
f85e63b6e0
@ -24,7 +24,7 @@ PREDICT_ONLY_ON_WHOLE_TRAINING_SET = False
|
||||
|
||||
setting = ','.join([escapeFilePath(imageCameraFolder) for imageCameraFolder in IMAGES_CAMERAS_FOLDER]) + f'_{DENOISER}'
|
||||
|
||||
imagesCamerasFileNames = {camera: [imageCameraFile for imageCameraFile in os.listdir(imageCameraFolder) if imageCameraFile.endswith('.NEF') or imageCameraFile.endswith('.ARW')] for camera, imageCameraFolder in IMAGES_CAMERAS_FOLDER.items()}
|
||||
imagesCamerasFileNames = {camera: os.listdir(imageCameraFolder) for camera, imageCameraFolder in IMAGES_CAMERAS_FOLDER.items()}
|
||||
# Fix randomness for reproducibility.
|
||||
random.seed(0)
|
||||
# Randomize order to not have a bias (chronological for instance) when split to make training and testing sets.
|
||||
@ -104,20 +104,15 @@ from utils import silentTqdm
|
||||
returnSingleColorChannelImage = lambda singleColorChannelImage, _minColor, _maxColor: singleColorChannelImage
|
||||
|
||||
# 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).
|
||||
print('Load training images to memory')
|
||||
rescaleIfNeeded = rescaleRawImageForDenoiser
|
||||
cameraTrainingImages = {}
|
||||
for cameraTrainingImageIndex in tqdm(range(numberOfTrainingImages), 'Load to memory camera training image'):
|
||||
for cameraIndex, camera in enumerate(IMAGES_CAMERAS_FOLDER):
|
||||
for cameraTrainingImageIndex in tqdm(range(numberOfTrainingImages), 'Camera training image index'):
|
||||
for cameraIndex, camera in enumerate(tqdm(IMAGES_CAMERAS_FOLDER, 'Camera')):
|
||||
singleColorChannelImages = getSingleColorChannelImages(camera, cameraTrainingImageIndex)
|
||||
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
|
||||
cameraTrainingImages[camera] = cameraTrainingImages.get(camera, []) + [multipleColorsImage]
|
||||
|
||||
singleColorChannelTestingImages = {camera: [] for camera in IMAGES_CAMERAS_FOLDER}
|
||||
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]
|
||||
print('Training images loaded to memory')
|
||||
|
||||
# 2 loops:
|
||||
# - the first one is about computing `{min,max}Color`
|
||||
@ -133,7 +128,7 @@ 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 = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
|
||||
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
|
||||
|
||||
imagePrnuEstimateNpArray = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
|
||||
@ -176,7 +171,7 @@ 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 = getSingleColorChannelImages(camera, numberOfTrainingImages + cameraTestingImageIndex)
|
||||
multipleColorsImage = getMultipleColorsImage(singleColorChannelImages)
|
||||
cameraTestingImageNoise = getImagePrnuEstimateNpArray(singleColorChannelImages, multipleColorsImage, camera)
|
||||
|
||||
|
@ -8,7 +8,6 @@ from skimage import img_as_float
|
||||
from datetime import datetime
|
||||
import builtins as __builtin__
|
||||
from scipy.ndimage import gaussian_filter
|
||||
import os
|
||||
|
||||
class Color(Enum):
|
||||
RED = auto()
|
||||
@ -90,12 +89,8 @@ def isARawImage(imageFilePath):
|
||||
|
||||
def getColorChannel(imageFilePath, color):
|
||||
if isARawImage(imageFilePath):
|
||||
numpyFilePath = f'{imageFilePath}.{color}.npy'
|
||||
if os.path.isfile(numpyFilePath):
|
||||
imageNpArray = np.load(numpyFilePath)
|
||||
else:
|
||||
with rawpy.imread(imageFilePath) as raw:
|
||||
imageNpArray = getRawColorChannel(raw, color)
|
||||
with rawpy.imread(imageFilePath) as raw:
|
||||
imageNpArray = getRawColorChannel(raw, color)
|
||||
else:
|
||||
imagePil = Image.open(imageFilePath)
|
||||
imageNpArray = img_as_float(np.array(imagePil))
|
||||
@ -150,7 +145,7 @@ def getColorMeans(imagesFileNames, colors, singleColorChannelCropResolution = No
|
||||
colorMeans = {}
|
||||
for color in colors:
|
||||
colorIterativeMean = iterativeMean()
|
||||
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {str(color).replace("_", " ")} colored images'):
|
||||
for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color.replace("_", " ")} colored images'):
|
||||
imageNpArray = getImageNpArray(imageFileName, False, color, Denoiser.MEAN)
|
||||
if singleColorChannelCropResolution is not None:
|
||||
imageNpArray = getImageCrop(imageNpArray, singleColorChannelCropResolution)
|
||||
|
Loading…
Reference in New Issue
Block a user