First try lazy load

This commit is contained in:
Benjamin Loison 2024-05-13 19:50:54 +02:00
parent f85e63b6e0
commit 10f8766793
No known key found for this signature in database

View File

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