paste image without background PIL - python

I am trying to paste many small grayscale images into a bigger one. All images are jpegs. The small images had been previously rotated, so they have black background. What I wanted to do is to paste them without a background color, in other words, I need the background color to be transparent.
Thank you for your suggestions,

to my knowledge, jpg does not support transparency, you probably want your output to be a png, and you will need to set the alpha channel to be nothing
http://www.talkgraphics.com/showthread.php?22385-How-do-I-make-jpeg-image-background-transparent

Related

tv-like noise b/w background removal from .jpg image

I'd like to remove this sort of tv-like noise from a .jpg image in order to get a .png image with transparent background.
This is because I'll later need to overlay this picture over another one.
I've tried 1,
2,3, but all of them probably work only on black backgrounds.
I'm coding with Python and I thought OpenCV would help.
Do you have any idea? Thanks! :)
Given that the noise is nearly exclusively black and white (i.e. desaturated) whereas the fish is colour, I would convert to HSV colourspace and look to the Saturation channel for providing separation - the middle one in the row below:

Python OpenCV - Crop image to area with gray background

It is quite hard to explain what I want in the title. I'll show what I need with an example or input/output. I have an image called 'image.jpg' that'll be an image with random strokes of different shades of black and dark-blackish gray on a white background and on one area it'll be a light grey background
I want to use python's opencv and maybe PIL if it's useful and crop the image so I'll only see the gray area. So after whatever code I'll do it'll look like this image here
That's it, appreciate all help here. I don't seem to know where to start here so I can't include whatever code I tried.

How can I increase the width of the black lines on an image with opencv?

I have an image of a map with black borders, and I would like to make them thicker with opencv on python. To be honest, I am quite new to image processing and really don't know how this task can be accomplished. I already opened the image with just one color channel, since it is black and white, but I really have no idea as of what to do next to be able to accomplish what I need.
Here is the image that I am talking about:
map
Thanks in advance

set_alpha() not working when using a png image as game over surface

When the game is over, I want to put an image above it. But I don't want it to override the game over surface, so I hope I can set the transparency of the png image after i load and convert_alpha(). But it isn't working after I use set_alpha(0).
What I can think of the problem are:
my png image doesn't have alpha channel, so I checked it in my photoshop. It is rgb, not rgba, so how can I add alpha channel for it which means convert rgb to rgba.
(Note: I can change the transparency of the image in photoshop and use it in my pygame, it works but i wanna i can change the degree of transparency in my program anytime, not just have to use photoshop)
my pygame methods using wrong
png image:
The result I want is here:
(please ignore the Chinese, they are just another two images)):
Code is:
img_bg = pygame.image.load('./ui/background.png').convert_alpha()
img_bg.set_alpha(0)
screen.blit(img_bg, (0, 0))
set_alpha doesn't work with surfaces that use per pixel alpha, so use the convert method instead of convert_alpha. I changed the value to 70, since 0 would make the image fully transparent.
img_bg = pygame.image.load('./ui/background.png').convert()
img_bg.set_alpha(70)

Produce a composed image with different sized layers with transparency

I'm very new to Python and am exploring it's use to allow users to build custom images. The idea is that the client would select a few options and the image would be created on the server then downloaded (or used for other things on the server side).
The image is composed of many images, most of which are small icon type of images that are irregular shapes and have transparency. All layers are .png files.
I've tried using Pillow but it seems the image needs to be the same size as the overall image to properly use the transparency of the top layers.
Here's what I've tried so far:
from PIL import Image
background = Image.open("Background.png")
foreground = Image.open("Trim.png")
fire = Image.open("Type_Fire_Large.png")
background = Image.alpha_composite(background, foreground)
background.paste(fire, (150, 150))
background.show()
The image looks like this:
Background.png is the shaded "noise" and Trim.png is the grey diagonal lines. The best part: Trim.png has the center transparent and is able to show Background.png in the middle. But it's also the same size as the image.
The problem is Fire; notice how theres that black border (and odd fuchsia dot). The documentation states that the overlay image needs to be the same size. But it seems like a common scenario where someone would want to place a smaller icon with transparency on top of another image and compose them into one image.
I'm not attached to any particular library, I'm wide open to ideas and alternatives. The only thing I'm trying to do is keep it simple, so creating an entire game engine or the like to produce an image would probably be too much.
To just paste one png on top of another, respecting transparency, try
background.paste(fire, (x,y), fire.convert("RGBA"))
First I'd say Johannes Holmberg already answered your main concern: The missing transparency.
But I can hopefully explain what it's about with that odd fuchsia dot:
A transparent color image is usually stored as RGBA (RGB for Red, Green, Blue and A for Alpha). Here Alpha defines the transparency, from no transparency to full transparency.
Overlaying the images the correct way we see the GIMP Logo but the color stripe is almost invisible - because it's (almost) transparent.
But - as every pixel could be possibly visible - every pixel does still have a color. Even those pixels with 100% transparency. Thus, if we do not take Alpha into consideration we see each pixel color without transparency. This way we might have disturbing colors that are usually not disturbing at all - as long as they are fully transparent.

Categories

Resources