Adding alpha channel to RGB array using numpy
<p>I have an image array in RGB space and want to add the alpha channel to be all zeros. Specifically, I have a <code>numpy</code> 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?</p>

<p>If you have your current image as rgb variable then just use:</p>

<pre><code>rgba = numpy.concatenate((rgb, numpy.zeros((205, 54, 1))), axis=2)
</code></pre>

<p>Concatenate function merge rgb and zeros array together. Zeros function creates array of zeros. We set axis to 2 what means we merge in the thirde dimensions. Note: axis are counted from 0.</p>

python numpy