0
votes

The problem is to combine three RGB pictures to make an original picture. I need to take as an input three filtered pictures in RGB of the same picture. One red, one green, and one blue. I've tried to take every pixel in the image and add it to a tuple, which stores values of it.

from Cimpl import *

red_image = load_image("red_image.jpg")
blue_image = load_image("blue_image.jpg")
green_image = load_image("green_image.jpg")

new_image = copy(red_image)

for pixel in new_image:

    x, y, (r, g, b) = pixel

for bluePixel in blue_image:
    xBlue, yBlue, (rBlue, gBlue, bBlue) = bluePixel
    new_colour = create_color(r+rBlue,g+gBlue,b+bBlue)
    set_color (new_image, x, y, new_colour)


for greenPixel in green_image:
    xGreen, yGreen, (rGreen, gGreen, bGreen) = greenPixel
    new_colour = create_color(r+rGreen,g+gGreen,b+bGreen)
    set_color (new_image, x, y, new_colour)    

show(red_image)
show(new_image)

I seem to get the same picture back again and not the "combined image" of red, blue and green filters( red_image.jpg because I use that as "new_image")

1

1 Answers

0
votes

Let's make things clear, you have 3 images, each of them has 1 channel and you want to combine them into 1 3 channels image? If I'm right then try this.

import cv2
import numpy as np

red = cv2.imread('red.jpg')
green = cv2.imread('green.jpg')
blue = cv2.imread('blue.jpg')

image = np.dstack((blue, green, red)) # combine them, I'm not sure should I use red or blue first here though

cv2.imwrite('image.jpg')  # save it

cv2.imshow('img', image)  # show it
cv2.waitKey()

Note that opencv use BGR instead of RGB.

If you don't have cv2 and numpy yet.

pip install numpy
pip install opencv-python