#59: Should make split_and_compare_prnus_of_subgroups.py compatible with RAW images
				
					
				
			This commit is contained in:
		@@ -1,8 +1,6 @@
 | 
			
		||||
#!/usr/bin/env python
 | 
			
		||||
 | 
			
		||||
from skimage import img_as_float
 | 
			
		||||
import numpy as np
 | 
			
		||||
from PIL import Image
 | 
			
		||||
import os
 | 
			
		||||
from tqdm import tqdm
 | 
			
		||||
import csv
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
from PIL import Image
 | 
			
		||||
from utils import Color
 | 
			
		||||
from tqdm import tqdm
 | 
			
		||||
from utils import Color, mergeSingleColorChannelImagesAccordingToBayerFilter
 | 
			
		||||
import matplotlib.pyplot as plt
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
@@ -13,31 +12,7 @@ def getImageByColor(color):
 | 
			
		||||
    image = np.load(filePath)
 | 
			
		||||
    return image
 | 
			
		||||
 | 
			
		||||
def getNewIndex(index, offset):
 | 
			
		||||
    newIndex = (index - offset) * 2 + offset
 | 
			
		||||
    return newIndex
 | 
			
		||||
 | 
			
		||||
for color in tqdm(Color, 'Color'):
 | 
			
		||||
    colorImage = getImageByColor(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 tqdm(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
 | 
			
		||||
singleColorChannelImages = {color: getImageByColor(color) for color in Color}
 | 
			
		||||
multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages, progress = True)
 | 
			
		||||
 | 
			
		||||
plt.imsave(PREFIX + 'multiple_colors.png', multipleColorsImage)
 | 
			
		||||
@@ -1,11 +1,9 @@
 | 
			
		||||
#!/usr/bin/python3
 | 
			
		||||
#!/usr/bin/env python
 | 
			
		||||
 | 
			
		||||
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 skimage import img_as_float
 | 
			
		||||
from utils import denoise, iterativeMean, getColorChannel, escapeFilePath, Color, mergeSingleColorChannelImagesAccordingToBayerFilter
 | 
			
		||||
import sys
 | 
			
		||||
import os
 | 
			
		||||
from random import shuffle
 | 
			
		||||
@@ -16,7 +14,7 @@ from rms_diff import rmsDiffNumpy
 | 
			
		||||
 | 
			
		||||
NUMBER_OF_SUBGROUPS = 2
 | 
			
		||||
DENOISER = 'wavelet'
 | 
			
		||||
IMAGES_FOLDER = 'flat-field/TIF'
 | 
			
		||||
IMAGES_FOLDER = 'flat-field/NEF'
 | 
			
		||||
 | 
			
		||||
setting = escapeFilePath(IMAGES_FOLDER) + f'_{DENOISER}'
 | 
			
		||||
 | 
			
		||||
@@ -33,9 +31,13 @@ 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)
 | 
			
		||||
        singleColorChannelImages = {color: getColorChannel(imageFilePath, color) for color in Color}
 | 
			
		||||
        multipleColorsImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelImages)
 | 
			
		||||
 | 
			
		||||
        imagePrnuEstimateNpArray = imageNpArray - denoise(imageNpArray, DENOISER)
 | 
			
		||||
        singleColorChannelDenoisedImages = {color: denoise(singleColorChannelImages[color], DENOISER) for color in Color}
 | 
			
		||||
        multipleColorsDenoisedImage = mergeSingleColorChannelImagesAccordingToBayerFilter(singleColorChannelDenoisedImages)
 | 
			
		||||
 | 
			
		||||
        imagePrnuEstimateNpArray = multipleColorsImage - multipleColorsDenoisedImage
 | 
			
		||||
        subgroupIterativeMean = subgroupsIterativeMean[subgroupIndex]
 | 
			
		||||
        subgroupIterativeMean.add(imagePrnuEstimateNpArray)
 | 
			
		||||
        if subgroupIndex == NUMBER_OF_SUBGROUPS - 1:
 | 
			
		||||
 
 | 
			
		||||
@@ -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