#63: WIP
This commit is contained in:
parent
319ca8fb60
commit
b6425b426e
@ -25,32 +25,30 @@ imagesCamerasFileNames = {camera: os.listdir(imageCameraFolder) for camera, imag
|
||||
random.seed(0)
|
||||
# To not have a bias (chronological for instance) when split to make training and testing sets.
|
||||
for camera in IMAGES_CAMERAS_FOLDER:
|
||||
#print(imagesCamerasFileNames[camera][:3])
|
||||
random.shuffle(imagesCamerasFileNames[camera])
|
||||
#print(imagesCamerasFileNames[camera][:3])
|
||||
#exit(1)
|
||||
|
||||
minimumNumberOfImagesCameras = 10#min([len(imagesCamerasFileNames[camera]) for camera in IMAGES_CAMERAS_FOLDER])
|
||||
#print(minimumNumberOfImagesCameras)
|
||||
#exit(1)
|
||||
for camera in IMAGES_CAMERAS_FOLDER:
|
||||
IMAGES_CAMERAS_FOLDER[camera] = IMAGES_CAMERAS_FOLDER[camera][:minimumNumberOfImagesCameras]
|
||||
|
||||
numberOfCameras = len(IMAGES_CAMERAS_FOLDER)
|
||||
camerasIterativeMean = [iterativeMean() for _ in range(numberOfCameras)]
|
||||
camerasIterativeMean = {camera: iterativeMean() for camera in IMAGES_CAMERAS_FOLDER}
|
||||
|
||||
minColor = None
|
||||
maxColor = None
|
||||
|
||||
accuracy = []
|
||||
numberOfTrainingImages = int(minimumNumberOfImagesCameras * TRAINING_PORTION)
|
||||
numberOfTestingImages = minimumNumberOfImagesCameras - int(minimumNumberOfImagesCameras * TRAINING_PORTION)
|
||||
cameraTestingImagesNoise = {}#{camera: [] for camera in IMAGES_CAMERAS_FOLDER}
|
||||
|
||||
returnSingleColorChannelImage = lambda singleColorChannelImage, _minColor, _maxColor: singleColorChannelImage
|
||||
|
||||
for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else []) + [False], 'Compute extremes'):
|
||||
rescaleIfNeeded = returnSingleColorChannelImage if computeExtremes else rescaleRawImageForDenoiser
|
||||
for cameraImageIndex in tqdm(range(minimumNumberOfImagesCameras * TRAINING_PORTION), 'Camera image index'):
|
||||
for cameraIndex, camera in enumerate(tqdm(IMAGES_CAMERAS_FOLDER, 'Camera')):
|
||||
imageFileName = imagesCamerasFileNames[camera][cameraImageIndex]
|
||||
for cameraTrainingImageIndex in tqdm(range(minimumNumberOfImagesCameras if computeExtremes else numberOfTrainingImages), 'Camera training image index'):
|
||||
for camera in tqdm(IMAGES_CAMERAS_FOLDER, 'Camera'):
|
||||
imageFileName = imagesCamerasFileNames[camera][cameraTrainingImageIndex]
|
||||
imageFilePath = f'{IMAGES_CAMERAS_FOLDER[camera]}/{imageFileName}'
|
||||
singleColorChannelImages = {color: rescaleIfNeeded(getColorChannel(imageFilePath, color), minColor, maxColor) for color in Color}
|
||||
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
|
||||
@ -63,16 +61,33 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
|
||||
multipleColorsDenoisedImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelDenoisedImages)
|
||||
|
||||
imagePrnuEstimateNpArray = multipleColorsImage - multipleColorsDenoisedImage
|
||||
cameraIterativeMean = subgroupsIterativeMean[cameraIndex]
|
||||
cameraIterativeMean = camerasIterativeMean[camera]
|
||||
cameraIterativeMean.add(imagePrnuEstimateNpArray)
|
||||
if cameraIndex == numberOfCameras - 1:
|
||||
rms = rmsDiffNumpy(subgroupIterativeMean.mean, subgroupsIterativeMean[1 - cameraIndex].mean)
|
||||
rmss += [rms]
|
||||
for cameraTestingImageIndex in tqdm(range(numberOfTrainingImages), 'Camera testing image index'):
|
||||
singleColorChannelImages = {color: rescaleIfNeeded(getColorChannel(imageFilePath, color), minColor, maxColor) for color in Color}
|
||||
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
|
||||
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) for color in Color}
|
||||
multipleColorsDenoisedImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelDenoisedImages)
|
||||
rms = rmsDiffNumpy(subgroupIterativeMean.mean, subgroupsIterativeMean[1 - cameraIndex].mean)
|
||||
accuracy += [rms]
|
||||
if computeExtremes:
|
||||
print(f'{minColor=} {maxColor=}')
|
||||
print('Extracting noise of testing images')
|
||||
for camera in tqdm(IMAGES_CAMERAS_FOLDER, 'Camera'):
|
||||
for cameraTestingImageIndex in tqdm(range(numberOfTestingImages), 'Camera testing image index'):
|
||||
imageFilePath =
|
||||
singleColorChannelImages = {color: rescaleIfNeeded(getColorChannel(imageFilePath, color), minColor, maxColor) for color in Color}
|
||||
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
|
||||
singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) for color in Color}
|
||||
multipleColorsDenoisedImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelDenoisedImages)
|
||||
imagePrnuEstimateNpArray = multipleColorsImage - multipleColorsDenoisedImage
|
||||
cameraTestingImagesNoise[camera] = cameraTestingImagesNoise.get(camera, []) + [multipleColorsDenoisedImage]
|
||||
|
||||
|
||||
|
||||
for camera in range(IMAGES_CAMERAS_FOLDER):
|
||||
plt.imsave(f'{setting}_estimated_prnu_subgroup_{escapeFilePath(camera)}.png', (subgroupsIterativeMean[cameraIndex].mean))
|
||||
plt.imsave(f'{setting}_estimated_prnu_subgroup_{escapeFilePath(camera)}.png', (camerasIterativeMean[camera].mean))
|
||||
|
||||
plt.title(f'Accuracy of camera source attribution thanks to a given number of images to estimate PRNUs with {DENOISER} denoiser')
|
||||
plt.xlabel('Number of images to estimate PRNU')
|
||||
|
Loading…
x
Reference in New Issue
Block a user