Compare commits

..

No commits in common. "5ea0a862c0c5c7dd31c38920bed7260e3a0dcab0" and "b50f013234298d5e3274729a9769b8d45d0b5f1f" have entirely different histories.

3 changed files with 14 additions and 21 deletions

View File

@ -6,12 +6,13 @@ from PIL import Image
import os
from tqdm import tqdm
import csv
from utils import Color, denoise, iterativeMean, isARawImage, escapeFilePath, getColorChannel
import rawpy
from utils import Color, denoise, iterativeMean, isARawImage
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
imagesFolderPath = 'rafael/arw'
imagesFolderPathFileName = escapeFilePath(imagesFolderPath)
imagesFolderPathFileName = imagesFolderPath.replace('/', '_')
# Among:
# `denoise` possible denoisers and `mean`.
denoiser = 'mean'
@ -56,7 +57,12 @@ def getImageNpArray(imageFileName, computeExtremes, color):
imageFilePath = f'{imagesFolderPath}/nef/{imageFileName}'
else:
imageFilePath = f'{imagesFolderPath}/{imageFileName}'
imageNpArray = getColorChannel(imageFilePath)
if imageFileName.endswith('.NEF') or imageFileName.endswith('.ARW'):
with rawpy.imread(imageFilePath) as raw:
imageNpArray = getRawColorChannel(raw)
else:
imagePil = Image.open(imageFilePath)
imageNpArray = img_as_float(np.array(imagePil))
if computeExtremes:
colorRawImageVisibleMin = imageNpArray.min()

View File

@ -4,7 +4,7 @@ from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color
from utils import denoise, iterativeMean
from skimage import img_as_float
import sys
import os
@ -18,7 +18,7 @@ NUMBER_OF_SUBGROUPS = 2
DENOISER = 'wavelet'
IMAGES_FOLDER = 'flat-field/TIF'
setting = escapeFilePath(IMAGES_FOLDER) + f'_{DENOISER}'
setting = IMAGES_FOLDER.replace('/', '_') + f'_{DENOISER}'
imagesFileNames = os.listdir(IMAGES_FOLDER)
# To not have a bias (chronological for instance) when split to make subgroups.
@ -33,8 +33,8 @@ for subgroupImageIndex in tqdm(range(numberOfImagesPerSubgroup), 'Subgroup image
imageIndex = (subgroupIndex * NUMBER_OF_SUBGROUPS) + subgroupImageIndex
imageFileName = imagesFileNames[imageIndex]
imageFilePath = f'{IMAGES_FOLDER}/{imageFileName}'
imageNpArray = getColorChannel(imageFilePath, Color.GREEN_RIGHT)
imagePil = Image.open(imageFilePath)
imageNpArray = img_as_float(np.array(imagePil))
imagePrnuEstimateNpArray = imageNpArray - denoise(imageNpArray, DENOISER)
subgroupIterativeMean = subgroupsIterativeMean[subgroupIndex]
subgroupIterativeMean.add(imagePrnuEstimateNpArray)

View File

@ -1,7 +1,6 @@
from enum import Enum, auto
import skimage.restoration
import numpy as np
import rawpy
class Color(Enum):
RED = auto()
@ -70,16 +69,4 @@ def getRawColorChannel(raw, color):
return imageNpArray
def isARawImage(imageFilePath):
return any([imageFileName.lower().endswith(f'.{rawImageFileExtension}') for rawImageFileExtension in RAW_IMAGE_FILE_EXTENSIONS])
def getColorChannel(imageFilePath, color):
if isARawImage(imageFilePath):
with rawpy.imread(imageFilePath) as raw:
imageNpArray = getRawColorChannel(raw, color)
else:
imagePil = Image.open(imageFilePath)
imageNpArray = img_as_float(np.array(imagePil))
return imageNpArray
def escapeFilePath(filePath):
return filePath.replace('/', '_')
return any([imageFileName.lower().endswith(f'.{rawImageFileExtension}') for rawImageFileExtension in RAW_IMAGE_FILE_EXTENSIONS])