#62: Optimize significantly mergeSingleColorChannelImagesAccordingToBayerFilter
				
					
				
			This commit is contained in:
		@@ -96,29 +96,17 @@ 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
 | 
			
		||||
    colorImage = singleColorChannelImages[list(Color)[0]]
 | 
			
		||||
    multipleColorsImage = np.empty([dimension * 2 for dimension in colorImage.shape], dtype = np.float64)
 | 
			
		||||
    '''
 | 
			
		||||
    Assume Bayer Filter:
 | 
			
		||||
    RG
 | 
			
		||||
    GB
 | 
			
		||||
    '''
 | 
			
		||||
    multipleColorsImage[::2,::2] = singleColorChannelImages[Color.RED]
 | 
			
		||||
    multipleColorsImage[1::2,::2] = singleColorChannelImages[Color.GREEN_RIGHT]
 | 
			
		||||
    multipleColorsImage[::2,1::2] = singleColorChannelImages[Color.GREEN_BOTTOM]
 | 
			
		||||
    multipleColorsImage[1::2,1::2] = singleColorChannelImages[Color.BLUE]
 | 
			
		||||
    return multipleColorsImage
 | 
			
		||||
 | 
			
		||||
def saveNpArray(fileName, npArray):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user