Compare commits

...

2 Commits

Author SHA1 Message Date
Benjamin Loison
80a33428d6
Make split_and_compare_prnus_of_subgroups.py execution compatible with chaining shell commands
Otherwise it is stuck on `plt.show` until it is closed but we want to
chain with a notification command, so the notification is not
interesting in this case.
2024-04-27 19:36:45 +02:00
Benjamin Loison
9d8e5ddbec
Make split_and_compare_prnus_of_subgroups.py only use 2 images of RAM
quantity
2024-04-27 19:24:12 +02:00

View File

@ -18,41 +18,41 @@ NUMBER_OF_SUBGROUPS = 2
DENOISER = 'wavelet'
IMAGES_FOLDER = 'flat-field/TIF'
setting = IMAGES_FOLDER.replace('/', '_') + f'_{DENOISER}'
imagesFileNames = os.listdir(IMAGES_FOLDER)
# To not have a bias (chronological for instance) when split to make subgroups.
shuffle(imagesFileNames)
numberOfImagesPerSubgroup = len(imagesFileNames) // NUMBER_OF_SUBGROUPS
numberOfImagesThresholds = range(numberOfImagesPerSubgroup, numberOfImagesPerSubgroup + 1)
subgroupsPrnuEstimatesNpArray = []
for subgroupIndex in tqdm(range(NUMBER_OF_SUBGROUPS), 'Subgroup'):
subgroupPrnuEstimateNpArray = []
subgroupIterativeMean = iterativeMean()
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)
numberOfImagesPerSubgroup = len(imagesFileNames) // NUMBER_OF_SUBGROUPS
subgroupsIterativeMean = [iterativeMean() for _ in range(NUMBER_OF_SUBGROUPS)]
rmss = []
for subgroupImageIndex in tqdm(range(numberOfImagesPerSubgroup), 'Subgroup image index'):
for subgroupIndex in tqdm(range(NUMBER_OF_SUBGROUPS), 'Subgroup'):
imageIndex = (subgroupIndex * NUMBER_OF_SUBGROUPS) + subgroupImageIndex
imageFileName = imagesFileNames[imageIndex]
imageFilePath = f'{IMAGES_FOLDER}/{imageFileName}'
imagePil = Image.open(imageFilePath)
imageNpArray = img_as_float(np.array(imagePil))
imagePrnuEstimateNpArray = imageNpArray - denoise(imageNpArray, DENOISER)
subgroupIterativeMean = subgroupsIterativeMean[subgroupIndex]
subgroupIterativeMean.add(imagePrnuEstimateNpArray)
subgroupPrnuEstimateNpArray += [subgroupIterativeMean.mean]
if subgroupIndex == NUMBER_OF_SUBGROUPS - 1:
assert NUMBER_OF_SUBGROUPS == 2
rms = rmsDiffNumpy(subgroupIterativeMean.mean, subgroupsIterativeMean[1 - subgroupIndex].mean)
rmss += [rms]
subgroupsPrnuEstimatesNpArray += [subgroupPrnuEstimateNpArray]
mostImagesSubgroupPrnuEstimatesNpArray = [subgroupPrnuEstimatesNpArray[-1] for subgroupPrnuEstimatesNpArray in subgroupsPrnuEstimateNpArray]
mostImagesSubgroupPrnuEstimatesNpArray = [subgroupIterativeMean.mean for subgroupIterativeMean in subgroupsIterativeMean]
minimum = np.min(mostImagesSubgroupPrnuEstimatesNpArray)
maximum = np.max(mostImagesSubgroupPrnuEstimatesNpArray)
for subgroupIndex in range(NUMBER_OF_SUBGROUPS):
plt.imsave(f'prnu_subgroup_{subgroupIndex}.png', (subgroupsPrnuEstimateNpArray[subgroupIndex][-1] - minimum) / (maximum - minimum))
rmss = []
for numberOfImagesIndex in range(len(numberOfImagesThresholds)):
rms = rmsDiffNumpy(subgroupsPrnuEstimatesNpArray[0][numberOfImagesIndex], subgroupsPrnuEstimatesNpArray[1][numberOfImagesIndex])
rmss += [rms]
plt.imsave(f'{setting}_estimated_prnu_subgroup_{subgroupIndex}.png', (subgroupsIterativeMean[subgroupIndex].mean - minimum) / (maximum - minimum))
plt.title(f'RMS between both subgroups estimated PRNUs with {DENOISER} denoiser for a given number of images among them')
plt.xlabel('Number of images of each subgroup')
plt.ylabel('RMS between both subgroups estimated PRNUs')
plt.plot(rmss)
plt.show()
plt.savefig(f'{setting}_rms_between_estimated_prnu_of_2_subgroups.svg')
#plt.show()