Simplify and clean split_and_compare_prnus_of_subgroups.py

This commit is contained in:
Benjamin Loison 2024-04-27 16:06:47 +02:00
parent ee7353cfde
commit e9dc28dc2a
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -5,6 +5,7 @@ from tqdm import tqdm
from utils import denoise
from skimage import img_as_float
import sys
import os
sys.path.insert(0, '../../algorithms/distance/')
@ -12,19 +13,18 @@ from rms_diff import rmsDiffNumpy
NUMBER_OF_SUBGROUPS = 1
DENOISER = 'wavelet'
IMAGES_FOLDER = 'flat-field/TIF'
imagesFileNames = os.listdir(IMAGES_FOLDER)
numberOfImagesPerSubgroup = len(imagesFileNames) // NUMBER_OF_SUBGROUPS
# 1
numberOfImagesThresholds = range(numberOfImagesPerSubgroup, numberOfImagesPerSubgroup + 1)
# Assume random image order to not introduce a bias.
subgroupsPrnuEstimatesNpArray = []
for subgroupIndex in range(NUMBER_OF_SUBGROUPS):
for subgroupIndex in tqdm(range(NUMBER_OF_SUBGROUPS), 'Subgroup'):
imagesPrnuEstimateNpArray = []
for imageFileName in tqdm(imagesFileNames[numberOfImagesPerSubgroup * subgroupIndex : numberOfImagesPerSubgroup * (subgroupIndex + 1)]):
subgroupImagesFileNames = imagesFileNames[numberOfImagesPerSubgroup * subgroupIndex : numberOfImagesPerSubgroup * (subgroupIndex + 1)]
for imageFileName in tqdm(subgroupImagesFileNames, f'Image of subgroup {subgroupIndex}'):
imagePath = f'{IMAGES_FOLDER}/{imageFileName}'
imagePil = Image.open(imagePath)
imageNpArray = img_as_float(np.array(imagePil))
@ -39,7 +39,7 @@ for subgroupIndex in range(NUMBER_OF_SUBGROUPS):
subgroupsPrnuEstimatesNpArray += [subgroupPrnuEstimateNpArray]
rmss = []
for numberOfImagesIndex, numberOfImages in enumerate(numberOfImagesThresholds):
for numberOfImagesIndex in range(len(numberOfImagesThresholds)):
rms = rmsDiffNumpy(subgroupsPrnuEstimatesNpArray[0][numberOfImagesIndex], subgroupsPrnuEstimatesNpArray[1][numberOfImagesIndex])
rmss += [rms]