I have 3 images of the same size, I read each one using matplotlib.image.imread which returns a 3D numpy array.
(Height, Width, ChannelsNumber) # ChannelsNumber = 3 for RGB
Now, i want to merge the 3 images into a 4D numpy array like this :
(Height, Width, ChannelsNumber, NumberOfImages)
Meaning, the 3rd dimension array at position (X,Y) will no longer contain RGB values for pixel (X,Y) but will contain 3 arrays one for each channel (), where each array will contain 3 R, G, r B values (for 3 images)
- array at position
X,Y,0will contain all RED values for images1,2,3at pixelX,Y - array at position
X,Y,1will contain all GREEN values for images 1,2,3 at pixelX,Y - array at position
X,Y,2will contain all BLUE values for images 1,2,3 at pixelX,Y
For example :
(10,15,0) will be an array containing all the RED values for all the images for Pixel (10,15)
Here's what i have tried :
import numpy as np
import os
import matplotlib.image as mpimg
img1 = mpimg.imread('./image1.jpg')
img2 = mpimg.imread('./image2.jpg')
img3 = mpimg.imread('./image3.jpg')
x = np.dstack((img1, img2, img3))
this returns a 3D array, where the 3rd dimension is an array that contains the RGB values of the images in this format:
[R-img1, B-img1, G-img1, R-img2, B-img2, G-img2, R-img3, B-img3, G-img3]
where what i want is :
[
[R-img1, R-img2, R-img3,],
[R-img1, B-img2, -img3,],
[B-img1, B-img2, B-img3,]
]
Thank you !
img1 = stacked_imgs[...,0]