I exported a png image to a python numpy array.
import numpy
import Image
import matplotlib.pyplot as plt
Im=Image.opne('file.png')
arr=numpy.array(Im).reshape(Im.size[1],Im.size[0],4)
plt.imshow(arr)
plt.show()
Now, in books I found reshape of png using 3 channels, which does not work for me. I had to use 4.
>>> Im.shape
(401, 601, 4)
I can visualize the Red channel :
ImR=Im[:,:,0]
Similar for Green and Blue. The last one give me a white screen.
I managed to remove it:
Im4=Im[:,:,:-1]
and now:
>>> Im4.shape
(401, 601, 3)
I can visualize the image as before removing this 4th column
My question is: what is this 4th column for in PNG?
If the PNG had an alpha channel, the fourth column would be alpha. Since visualizing that channel gave you all-white, all of the alphas are maxval (255 if your samples are 8-bit) which means all pixels are opaque.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With