From faed1e33e85facc5e0a60f11bb2ede941578f87a Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Wed, 3 Apr 2024 18:20:08 +0200 Subject: [PATCH] #33: Add `datasets/raise/extract_noise.py` --- datasets/raise/extract_noise.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 datasets/raise/extract_noise.py diff --git a/datasets/raise/extract_noise.py b/datasets/raise/extract_noise.py new file mode 100755 index 0000000..5bb0610 --- /dev/null +++ b/datasets/raise/extract_noise.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 + +from skimage.restoration import denoise_tv_chambolle +from skimage import img_as_float +import numpy as np +from PIL import Image +import os +from tqdm import tqdm +import gzip + +imagesFolderPath = 'tif' +npArrayFolderPath = 'np' + +for imageFileName in tqdm(os.listdir(imagesFolderPath)): + npArrayFilePath = f'{npArrayFolderPath}/{imageFileName}.npy.gz' + if os.path.isfile(npArrayFilePath): + continue + imageFilePath = f'{imagesFolderPath}/{imageFileName}' + imagePil = Image.open(imageFilePath) + imageNpArray = img_as_float(np.array(imagePil)) + imageNoiseNpArray = imageNpArray - denoise_tv_chambolle(imageNpArray, weight=0.2, channel_axis=-1) + with gzip.open(npArrayFilePath, 'wb') as f: + np.save(f, imageNoiseNpArray)