diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py index 2b20582..26cec21 100755 --- a/datasets/raise/extract_noise.py +++ b/datasets/raise/extract_noise.py @@ -21,29 +21,29 @@ imagesFileNames = os.listdir(imagesFolderPath) pbar = tqdm(total = len(imagesFileNames)) def treatImage(imageFileName): - global mean, numberOfImagesInMean, pbar - imageFilePath = f'{imagesFolderPath}/{imageFileName}' - imagePil = Image.open(imageFilePath) - imageNpArray = img_as_float(np.array(imagePil)) - print('Before mean computation') - imageNoiseNpArray = imageNpArray - denoise_tv_chambolle(imageNpArray, weight=0.2, channel_axis=-1) - print('After mean computation') - with mutex: - print('Start mutex section') - if mean is None: - print('Inter A') - mean = imageNoiseNpArray - else: - print('Inter B') - mean = ((mean * numberOfImagesInMean) + imageNoiseNpArray) / (numberOfImagesInMean + 1) - print('Intermediary 0') - numberOfImagesInMean += 1 - print('Intermediary 1') - pbar.update(numberOfImagesInMean) - print('End mutex section') + global mean, numberOfImagesInMean, pbar + imageFilePath = f'{imagesFolderPath}/{imageFileName}' + imagePil = Image.open(imageFilePath) + imageNpArray = img_as_float(np.array(imagePil)) + print('Before mean computation') + imageNoiseNpArray = imageNpArray - denoise_tv_chambolle(imageNpArray, weight=0.2, channel_axis=-1) + print('After mean computation') + with mutex: + print('Start mutex section') + if mean is None: + print('Inter A') + mean = imageNoiseNpArray + else: + print('Inter B') + mean = ((mean * numberOfImagesInMean) + imageNoiseNpArray) / (numberOfImagesInMean + 1) + print('Intermediary 0') + numberOfImagesInMean += 1 + print('Intermediary 1') + pbar.update(numberOfImagesInMean) + print('End mutex section') with Pool(5) as p: - p.map(treatImage, imagesFileNames) + p.map(treatImage, imagesFileNames) with open(npArrayFilePath, 'wb') as f: - np.save(f, mean) + np.save(f, mean)