Alpha channel become red when imread - python

I have .png image like this
But when I want to read and show the image, the alpha channel area become fully red like this
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.

Related

Paste RBG image without its background onto another picture (PIL)

So I need to post an RGB picture (with transparent background) onto background image, but when I am trying to post it with image.paste() I get transparent background through which I don't see the background I want. What should I do?
Thanks!
Code (its just that):
skin = Image.open("./temp2.png")
skin = skin.resize((148, 355))
stats.paste(skin,(42,232))
stats.save("temp.png")
Images:
Image I want to paste
The background I want to paste it on
Wanted Result
Actual Result (gray is transparent)
You can use alpha composite in PIL to paste an image and keep the alpha channels for transparency.
stats = Image.open("stats.png")
skin = Image.open("skin.png")
skin = skin.resize((148, 355))
stats.alpha_composite(skin,(42,232))
stats.save("temp.png")
Resulting image:

How shall I crop images with 2 colour borders in Python?

My original image was this:enter image description here
After I rotate them, I got this:
enter image description here
Therefore, I am currently having both black and white borders. I only want the middle part of the image, how can I crop them with Python?
I am new here, appreciate if anyone can help! Thanks in advance.

Opencv: How to stitch four trapezoid images to make a square image?

I am currently trying very hard to figure out a way to make these four trapezoid images into one nice image. The final image should look something like this(used photoshop to make it):
That above image will be complied with four of these images:
The problem is that when I try to rotate and combine these images, the black surroundings come into the final image as well like this:
How am I supposed to rid of the blacked out area or make it transparent? I've tried using a mask but that only make the black area white instead. I have also tried using the alpha channel, but that didn't work(although maybe I was doing wrong). Any ideas on what I can do in OpenCV?
I did actually figure it out. I did it with these steps:
Create two SAME SIZED black backgrounds with numpy zeros
Put one image in each background where you want them(for me, it was left and top)
Then all you need to do is cv.add(first, second)
The reason it works is because black pixels are 0,0,0 so adding to a pixel that is, say, 25,62,34, the pixel doesn't change and thus rids of the black corner.

PIL Image.getcolors() cannot distinguish between black and transparent?

I'm trying to count the number of distinct colors in an image using img.getcolors(). However, this does not distinguish between transparent and black pixels - they both report as one pixel colored [0,0,0].
How can I distinguish between transparent and black pixels? Many of the images I need to process are largely black on a transparent background.
For test purposes, I'm using a PNG I created which is half transparent, half black. len(img.getcolors()) is 1.
Embarrassing answer:
I was using convert('RGB') before calling getcolors(). Without the conversion, a 4-value tuple comes back with an alpha channel.

Remove alpha compositing knowing the watermark (revert/compensate)

I have watermarked a bunch of images image with PIL (PILLOW in fact).
I have the original watermark and I know exactly how it has been resized and pasted on the image (0.75 opacity). The watermark is essentially black, white and red.
I want to restore images as close as possible as they were originally.
Is there any chance I could do that automatically?
What about quality? Is it worth it? Do you have examples of the result of such a process?
If so, how would I manage to do this?
Here is the code I used to watermark the image:
logo = Image.open(path)
red, green, blue, alpha = logo.split()
alpha = ImageEnhance.Brightness(alpha).enhance(0.75)
logo.putalpha(alpha)
img = Image.open('...')
img = Image.composite(logo, img, logo)
I've made a mask with of my logo and use GIMP's G'MIC plugin : http://blog.patdavid.net/2014/02/getting-around-in-gimp-gmic-inpainting.html
Here is as far as I can get, which is not really good enough:
This has been made with inpainting technic, but I am sure I could somehow exploit the fact that my watermark is somewhat transparent.
I've also tried to unblend the picture, given the watermark and watermarked pictures as input.
Unforunately, the watermarked picture being compressed in jpeg, I couldn't get any better than this :

Categories