#33: Add datasets/raise/extract_noise.py

This commit is contained in:
Benjamin Loison 2024-04-03 18:20:08 +02:00
parent 4dd52aae90
commit faed1e33e8
No known key found for this signature in database

23
datasets/raise/extract_noise.py Executable file
View File

@ -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)