Clean datasets/raise/extract_noise.py

This commit is contained in:
Benjamin Loison 2024-04-15 16:16:29 +02:00
parent a09f2ba1c0
commit bddfa4c8d5
No known key found for this signature in database

View File

@ -6,6 +6,7 @@ import numpy as np
from PIL import Image
import os
from tqdm import tqdm
import csv
imagesFolderPath = 'raise_nef_png'
denoiser = 'wavelet'
@ -16,35 +17,19 @@ denoise = getattr(skimage.restoration, f'denoise_{denoiser}')
mean = None
numberOfImagesInMean = 0
import csv
import magic
import re
deviceFiles = {}
resolutionFiles = {}
files = {}
resolutionFiles = {}
with open('RAISE_all.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in tqdm(list(reader)):
file = row['File'] + '.png'
device = row['Device']
resolution = row['Image Size']
deviceFiles[file] = device
#resolutionFiles[file] = resolution
image = Image.open(f'{imagesFolderPath}/{file}')
#t = magic.from_file(f'{imagesFolderPath}/{file}.png')
resolution = image.size
resolutionFiles[file] = resolution#re.search('(\d+) x (\d+)', t).groups()
#print(device, resolution)
#files[f'{file}.png'] = row
imagesFileNames = os.listdir(imagesFolderPath)
#print(len(imagesFileNames))
# imageFileName.replace('.png', '')
imagesFileNames = [imageFileName for imageFileName in imagesFileNames if deviceFiles[imageFileName] == 'Nikon D7000' and resolutionFiles[imageFileName] == (4946, 3278)]
#print(len(imagesFileNames))
requiresRaiseFiltering = False
if requiresRaiseFiltering:
files = {}
with open('RAISE_all.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in tqdm(list(reader), 'CSV parsing'):
file = row['File'] + '.png'
files[file] = row
imagesFileNames = [imageFileName for imageFileName in tqdm(imagesFileNames, 'Filtering images') if files[imageFileName]['Device'] == 'Nikon D7000' and Image.open(f'{imagesFolderPath}/{imageFileName}').size == (4946, 3278)]
def treatImage(imageFileName):
global mean, numberOfImagesInMean
@ -60,7 +45,7 @@ def treatImage(imageFileName):
mean = ((mean * numberOfImagesInMean) + imageNoiseNpArray) / (numberOfImagesInMean + 1)
numberOfImagesInMean += 1
for imageFileName in tqdm(imagesFileNames):
for imageFileName in tqdm(imagesFileNames, 'Denoising images'):
treatImage(imageFileName)
with open(npArrayFilePath, 'wb') as f: