Combine 3 separate numpy arrays to an RGB image in Python

I don't really understand your question but here is an example of something similar I've done recently that seems like it might help:

# r, g, and b are 512x512 float arrays with values >= 0 and < 1.
from PIL import Image
import numpy as np
rgbArray = np.zeros((512,512,3), 'uint8')
rgbArray[..., 0] = r*256
rgbArray[..., 1] = g*256
rgbArray[..., 2] = b*256
img = Image.fromarray(rgbArray)
img.save('myimg.jpeg')

I hope that helps


rgb = np.dstack((r,g,b))  # stacks 3 h x w arrays -> h x w x 3

This code doesnt create 3d array if you pass 3 channels. 2 channels remain.


rgb = np.dstack((r,g,b))  # stacks 3 h x w arrays -> h x w x 3

To also convert floats 0 .. 1 to uint8 s,

rgb_uint8 = (np.dstack((r,g,b)) * 255.999) .astype(np.uint8)  # right, Janna, not 256