#59: Should make split_and_compare_prnus_of_subgroups.py compatible with RAW images
This commit is contained in:
@@ -2,6 +2,9 @@ from enum import Enum, auto
|
||||
import skimage.restoration
|
||||
import numpy as np
|
||||
import rawpy
|
||||
from tqdm import tqdm
|
||||
from PIL import Image
|
||||
from skimage import img_as_float
|
||||
|
||||
class Color(Enum):
|
||||
RED = auto()
|
||||
@@ -70,7 +73,7 @@ def getRawColorChannel(raw, color):
|
||||
return imageNpArray
|
||||
|
||||
def isARawImage(imageFilePath):
|
||||
return any([imageFileName.lower().endswith(f'.{rawImageFileExtension}') for rawImageFileExtension in RAW_IMAGE_FILE_EXTENSIONS])
|
||||
return any([imageFilePath.lower().endswith(f'.{rawImageFileExtension}') for rawImageFileExtension in RAW_IMAGE_FILE_EXTENSIONS])
|
||||
|
||||
def getColorChannel(imageFilePath, color):
|
||||
if isARawImage(imageFilePath):
|
||||
@@ -82,4 +85,38 @@ def getColorChannel(imageFilePath, color):
|
||||
return imageNpArray
|
||||
|
||||
def escapeFilePath(filePath):
|
||||
return filePath.replace('/', '_')
|
||||
return filePath.replace('/', '_')
|
||||
|
||||
|
||||
def getNewIndex(index, offset):
|
||||
newIndex = (index - offset) * 2 + offset
|
||||
return newIndex
|
||||
|
||||
def silentTqdm(data, desc = None):
|
||||
return data
|
||||
|
||||
def mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages, progress = False):
|
||||
tqdmVersion = tqdm if progress else silentTqdm
|
||||
for color in tqdmVersion(Color, 'Color'):
|
||||
colorImage = singleColorChannelImages[color]
|
||||
if color == list(Color)[0]:
|
||||
width, height = colorImage.shape
|
||||
multipleColorsImage = np.empty([dimension * 2 for dimension in colorImage.shape], dtype = np.float64)
|
||||
for y in tqdmVersion(range(height), 'Height'):
|
||||
for x in range(width):
|
||||
pixel = colorImage[x, y]
|
||||
'''
|
||||
Assume Bayer Filter:
|
||||
RG
|
||||
GB
|
||||
'''
|
||||
offsetX, offsetY = {
|
||||
Color.RED: (0, 0),
|
||||
Color.GREEN_RIGHT: (1, 0),
|
||||
Color.GREEN_BOTTOM: (0, 1),
|
||||
Color.BLUE: (1, 1),
|
||||
}[color]
|
||||
newX, newY = [getNewIndex(index, offset) for index, offset in [(x, offsetX), (y, offsetY)]]
|
||||
|
||||
multipleColorsImage[newX, newY] = pixel
|
||||
return multipleColorsImage
|
||||
Reference in New Issue
Block a user