#59: Leverage iterativeMean to not suffer of RAM quantity issue

This commit is contained in:
Benjamin Loison 2024-04-27 16:49:06 +02:00
parent 6f6721da8d
commit c8fe71444f
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -2,7 +2,7 @@ from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from utils import denoise
from utils import denoise, iterativeMean
from skimage import img_as_float
import sys
import os
@ -12,7 +12,7 @@ sys.path.insert(0, '../../algorithms/distance/')
from rms_diff import rmsDiffNumpy
NUMBER_OF_SUBGROUPS = 1
NUMBER_OF_SUBGROUPS = 2
DENOISER = 'wavelet'
IMAGES_FOLDER = 'flat-field/TIF'
@ -24,7 +24,8 @@ numberOfImagesThresholds = range(numberOfImagesPerSubgroup, numberOfImagesPerSub
subgroupsPrnuEstimatesNpArray = []
for subgroupIndex in tqdm(range(NUMBER_OF_SUBGROUPS), 'Subgroup'):
imagesPrnuEstimateNpArray = []
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}'
@ -33,11 +34,10 @@ for subgroupIndex in tqdm(range(NUMBER_OF_SUBGROUPS), 'Subgroup'):
imagePrnuEstimateNpArray = imageNpArray - denoise(imageNpArray, DENOISER)
imagesPrnuEstimateNpArray += [imagePrnuEstimateNpArray]
subgroupPrnuEstimateNpArray = []
# Not efficient mean computation.
for numberOfImagesIndex, numberOfImages in enumerate(numberOfImagesThresholds):
subgroupPrnuEstimateNpArray += [np.array(imagesPrnuEstimateNpArray[:numberOfImages]).mean(axis = 0)]
plt.imsave('prnu.png', subgroupPrnuEstimateNpArray[-1])
subgroupIterativeMean.add(imagePrnuEstimateNpArray)
subgroupPrnuEstimateNpArray += [subgroupIterativeMean.mean]
plt.imsave(f'prnu_subgroup_{subgroupIndex}.png', subgroupPrnuEstimateNpArray[-1])
subgroupsPrnuEstimatesNpArray += [subgroupPrnuEstimateNpArray]
rmss = []