From 10f8766793b4248f4af6b3acc8fb9966dcfa7f4d Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Mon, 13 May 2024 19:50:54 +0200 Subject: [PATCH] First try lazy load --- datasets/raise/utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/datasets/raise/utils.py b/datasets/raise/utils.py index c5043c6..d38fdea 100644 --- a/datasets/raise/utils.py +++ b/datasets/raise/utils.py @@ -8,6 +8,7 @@ from skimage import img_as_float from datetime import datetime import builtins as __builtin__ from scipy.ndimage import gaussian_filter +import os class Color(Enum): RED = auto() @@ -89,8 +90,14 @@ def isARawImage(imageFilePath): def getColorChannel(imageFilePath, color): if isARawImage(imageFilePath): - with rawpy.imread(imageFilePath) as raw: - imageNpArray = getRawColorChannel(raw, color) + numpyFilePath = f'{imageFilePath}.npy' + if os.path.isfile(numpyFilePath): + imageNpArray = np.load(numpyFilePath, allow_pickle = True).item()#[color] + print(imageNpArray) + #exit(1) + else: + with rawpy.imread(imageFilePath) as raw: + imageNpArray = getRawColorChannel(raw, color) else: imagePil = Image.open(imageFilePath) imageNpArray = img_as_float(np.array(imagePil)) @@ -145,7 +152,7 @@ def getColorMeans(imagesFileNames, colors, singleColorChannelCropResolution = No colorMeans = {} for color in colors: colorIterativeMean = iterativeMean() - for imageFileName in tqdm(imagesFileNames, f'Computing mean of {color.replace("_", " ")} colored images'): + for imageFileName in tqdm(imagesFileNames, f'Computing mean of {str(color).replace("_", " ")} colored images'): imageNpArray = getImageNpArray(imageFileName, False, color, Denoiser.MEAN) if singleColorChannelCropResolution is not None: imageNpArray = getImageCrop(imageNpArray, singleColorChannelCropResolution)