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:
Related
When I use this method with an 1 channel image, it's shown in grayscale. Is there a way to use other color maps (not grayscale) when showing an 1 channel image? If there is, it means grayscale is the default for imshow when working with an image with only 1 channel? Thanks in advance
As far as I know, you cannot apply a color map in Python/OpenCV cv2.imshow like you can with Mathplotlib pyplot. But you can create a color map and apply it to your grayscale image using cv2.LUT to change your grayscale image into a colored image that you can display with cv2.imshow.
Please see the documentation for cv2.imshow at https://docs.opencv.org/4.1.1/d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563
I am trying to crop only liver from this picture. I have tried everything but cannot find any useful information about it. I am using Python/Rstudio. Also after removing the unnecessary part, I am willing to get pixels/intensity of the new image. Any help would be appreciated. Please check one of the image This is somehow what I want to crop
UPDATE:
I am trying to crop the main image based on edges I got from the canny edge detector. Is there any way to crop the main image based on edges? Please check the images.
Liver Image
Canny Edge Detection
Well, if your images are static, same size, and taken from the same angle, then below simple script should suffice your needs:
import cv2
img = cv2.imread("cMyp9.png")
mask = np.where(img==255)
img2 = cv2.imread("your_next_image.png")
img2 [mask] = 255
now your img2 is a cropped version
How to use python to filter an image based on colour?
Given a coloured image. I would like to turn it into an image that is black everywhere except for pixels that have colour close to the RGB colour (170,120,75).
How can I go about doing this efficiently?
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.
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 :