0

I have .png image like this

lenna-eye

But when I want to read and show the image, the alpha channel area become fully red like this red

My python code for read and show are like this.

imageA = cv2.imread('img/lenna.png')
cv2.imshow("image A", imageA)

Why the transparent area become red when I want to just read and show it? Can I make it still transparent? Thank you.

evanhutomo
  • 627
  • 1
  • 11
  • 24
  • Check [this](https://stackoverflow.com/questions/1451021/alpha-channel-in-opencv) out. – I.Newton Feb 20 '18 at 05:13
  • https://stackoverflow.com/a/41896175/8580478 This gave me proper output – janu777 Feb 20 '18 at 05:22
  • opencv does not regard the alpha channel at all when rendering the image. In addition, innyour case, the way you use imread, it does not even create the alpha channel. – Micka Feb 20 '18 at 06:05
  • @Micka but that picture already has alpha channel, so I thought I didn't need to add it again. – evanhutomo Feb 20 '18 at 08:58
  • use the right flags in opencv's imread to read the alpha channel. Without the flag, openCV will create a 3 channel BGR image with 24 bit per pixel, no matter what the original image was. BUT: even if the image has a nice alpha channel, openCV's imshow won't render it correctly (it will just ignore the alpha channel because openCV's gui is just too simpel and just for testing). Use some better rendering library. BUT: if the image has an alpha channel and you save it as .png with cv2.imwrite, the alpha channel will be saved, so you can check it in GIMP etc. – Micka Feb 20 '18 at 09:28

0 Answers0