how to merge the background of uint8 image? - python

I am trying to do lung extraction from CT images. I would like to remove the background and keep only the lungs (the yellow color background must change to blue-ish color and lungs must have unique color). How can I do that?

Related

creating a transparent overlay using OpenCV in python

So I have two images, one is a white image with a blurred spot and other is a image of a street(taken from KITTI dataset). I want to blend both the white image with blurred spot and street image such that the whiteness doesnt appear while blending.\
In the first image below, you can see a translucent gray spot. This I achieved by making a copy of the street image and then drawing a circle on it using cv2.circle function. This i blended it back with the original image and controlled the transparency of the circle.
In place of the circular spot, I want the blurred spot in the white image to appear with transparency. How can this be achieved?
When i do normal blending the white shade also appears. I tried converting into RGBA image and then blending but didnt work. Any idea how this could be achieved?

crop image into individual parts

I used semantic segmentation to color code the different elements in an image shown below.
In Python, I want to crop the original image into many small images based on the colors of the second image, so that the sofa becomes one cropped part, the lamp becomes one.etc. The overlap of the pillows on the sofa can be ignored. Say I have a 3D array of an image, I want to separate that array into the individual colored sections, and apply the coordinate of those elements in cropping the original image. How should I achieve this?
You can do it like this:
find the number of unique colours in the segmented image - see here
iterate over that list of colours making that colour white and everything else black, then findContours() to get the bounding box and save the contents of that bounding box as a PNG.

Convert output of template matching image into binary image using python

I have used cv2.matchTemplate() to identify target objects in an image. Now I want to convert below image into binary image(black and white) in such a way that detected target object(white frames) should be in white color and rest of the objects in image should be in black color.
This is how I want an output(Binary output illustrative). Wherever white frames (in input image) is there, image area should be white and rest are in black color.

Correct the color on an image

I have an image that was taken and had a bayer filter applied to it. I am trying to correct the color because depenging on what filter we apply (BG 2 RGB for example) it comes out with a tint, be it yellow, blue, green, pink etc... I am using the python image library to try and fix the image.
I have taken an image of the visible spectrum and can make it so that one or two colors are right by multiplying by the correct pixel weight but then the other colors go off. For example I can make white look great but then blue turns pink.
Is there any way besides modifying the bayer filter that I can process this image, hopefully in python with the PIL to fix this color imbalance.
Thanks!

Use a color to create an alpha channel for a PNG?

I have several images that claim to have a transparent background but are actually white. I'd like to use Python Image Library/PIL to set that white background color to actually be transparent.
Since PNG uses an alpha channel, I'd love to create the alpha channel by finding contiguous areas of white from the edges of the image (so I don't get "holes" of transparency when the image contains white data).
Any tips on how to create the alpha channel this way?
I'd guess you'd want to run across the image in a spiral from the outside, setting a pixel to transparent if it is white, and a pixel further towards the edge is also white transparent. Stop once you've done a whole circle without changing any pixels.
Shouldn't be too difficult to write such a loop.
Do some kind of flood fill, seeded from the white edge pixels.

Categories

Resources