Melanie Melanie - 2 months ago 18
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

numpy
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

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)) ) )
Comments