Melanie Melanie - 1 year ago 301
Python Question

Adding alpha channel to RGB array using numpy

I have an image array in RGB space and want to add the alpha channel to be all zeros. Specifically, I have a

array with shape (205, 54, 3) and I want to change the shape to (205, 54, 4) with the additional spot in the third dimension being all 0.0's. Which numpy operation would achieve this?

Answer Source

You could use one of the stack functions (stack/hstack/vstack/dstack/concatenate) to join multiple arrays together.

numpy.dstack( ( your_input_array, numpy.zeros((25, 54)) ) )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download