Image shows differently between PIL Image and opencv imread()

Hi, guys,

I read a JPG image in Python with cv2.imread() and added an alpha channel with random values. I used cv2.imwrite() to store the modified image after that. However, I got a different display result when I use cv2.imread() and show() from PIL.Image library.
The code is shown below:

cv2.imwrite('D:/Hygon/python/block_comp/BlockCompression/test_rgba.png',img_origin)
cv2.imshow('Example - Show RGBA image in window',img_origin)
a=Image.open('D:/Hygon/python/block_comp/BlockCompression/test_rgba.png')
a.show()

The result is shown in the following diagram:

Could you help me figure out what’s happening and which one is the real image? Thanks a lot.

OS: Windows11
Python: 3.10.9 (anacoda)
OpenCV: 4.8.0

imshow() ignores the alpha channel.

it shows you what’s in the RGB channels, regardless of how transparent each pixel is supposed to be.

Thanks a lot. That makes sense.