Files
Robust_image_source_identif…/datasets/raise/merge_single_color_channel_images_according_to_bayer_filter.py
2024-04-27 16:20:02 +02:00

46 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python3
from PIL import Image
from utils import Color
from tqdm import tqdm
import matplotlib.pyplot as plt
import numpy as np
PREFIX = 'mean_rafael_arw_sky_mean_'
def getImageByColor(color):
filePath = PREFIX + f'{color}.npy'
image = np.load(filePath)
return image
color = Color.BLUE
image = getImageByColor(color)
width, height = image.shape
multipleColorsImage = np.empty([dimension * 2 for dimension in image.shape], dtype = np.float64)
def getNewIndex(index, offset):
newIndex = (index - offset) * 2 + offset
return newIndex
for color in tqdm(Color, 'Color'):
colorImage = getImageByColor(color)
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
plt.imsave(PREFIX + 'multiple_colors.png', multipleColorsImage)