Extract person from an image or make the background transparent - python

I want to extract the person in a image without any background.I want to do this for multiple images of the same kind.Please help me do so using python which can automate this process.
https://depositphotos.com/148319285/stock-video-man-run-on-green-screen.html
I,ve tried using canny edge detector could only find edges but couldnot crop it.Is there any alternative way to detect background and remove completely.

Background subtraction using opencv. Check the link for examples and details: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html

In case of such prepared images, you migth find useful simple thresholding: https://docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html in your case you would need to get grayscale image by extracting green channel from image. It would produce binary (black and white ONLY) image with white for background and black for object (or reverse depending on your choice).

Related

How to remove background from an image and set outline using python?

What I am going to do
Remove background from an image (removed area should be transparent)
Add a white outline to the image
I investigate ways to remove background from images and found several ways using opencv or other libraries like backgroundremover (https://github.com/nadermx/backgroundremover). But I can't find a solution to set the outline.

Image segmentation python opencv

I want to ask for some advice about the procedure that I should implement for image segmentation working with opencv in python.
I have this kind of image and my purpose is to detect the white fiber like here
Does anyone have a proposition of the steps of image processing that I should do?
Since I can notice that object's color is different than the background, I found this guide helpful. The concept is the following :
1.apply RGB filters to your image,
2.grab contours using OpenCV, then
3.apply some handcraft conditions to them so as to fit your desired output, and finally
4.produce the box.
If all of your images share the same color patterns, this should work.. If not, it will prove noisy ..

How to draw contours around black areas in pixeld image?

i am quite new to Python and i try to write some code for image analysing.
Here is my initial image:
Initial image
After splitting the image in to the rgb channels, converting in to gradient, using a threshold and merging them back together i get the following image:
Gradient/Threshold
Now i have to draw contours around the black areas and get the size of the surrounded areas. I just dont know how to do it, since my trials with find/draw.contours in opencv are not succesfull at all.
Maybe someone also knows an easier way to get that from the initial image.
Hope someone can help me here!
I am coding in Python 3.
Try adaptive thresholding on the grayscale image of the input image.
Also play with the last two parameters of the adaptive thresholding. You will find good results as I have shown in the image. (Tip: Create trackbar and play with value, this will be quick and easy method to get best values of these params.)

Remove background and noise from image

Im trying to remove the background from a video and get a binary images( or 8-bit) where value of the object that moves is 1 and static background is 0.
something like this:
at first I tried it with getting the difference absDiff() from running average accumulateWeighted() and the current frame but the result was not what I expected( only the edges was 1 and inside of the moving object was 0).
so I went for createBackgroundSubtractorMOG2 and createBackgroundSubtractorMOG but this is not good either( same problem ).
is there a way to get the whole moving object?
The Mixture of Gaussians method is not going to solve all your problems. Common problem is sensitivity to light conditions, e.g. attaching shadow to extracted foreground object . If the image scenario (background) is roughly the same you can refine your results with some image processing.
If the background is similar as in attached image, try to build color histogram in HSI space, create image of extracted foreground object (not mask, actual colored image) and remove pixels that color is similar to the floor (technique known from skin detection methods). In that way you could remove some shadows attached to the person/objects.
Also, if real-time processing is not crucial in your application, you could use more sophisticated background/foreground detection like SubSENSE.

Remove Captcha background

I entered a captcha-ed website I would like to get rid of. Here is some sample images
Since the background is static and the word is so computer-generated non distorted character, I believe it is very do-able. Since passing the image directly to Tesseract (OCR engine) doesn't come a positive result. I would like to remove the captcha background before OCR.
I tried multiple background removal methods using Python-PIL
Remove all non-black pixels, which remove the lines but it wouldn't remove the small solid black box.
Apply filter mentioned another StackOverflow post, which would not remove the small solid black box. Also it is less effective than method 1.
Method 1 and 2 would give me a image like this
It seems close but Tesseract couldn't recognize the character, even after the top and bottom dot row is removed.
Create a background mask, and apply the background mask to the image.
Here is the mask image
And this is the image with the mask applied and grey lines removed
However blindly applying this mask would generate some "white holes" in the captcha character. And still Tesseract failed to find out the words.
Are there any better methods removing the static background?
Lastly how could I split the filtered image into 6 image with single character? Thanks very much.
I can give you a few ideas to have a try.
After you have applied step 3, you may thicken the black edges in the images using PIL so as the fill the white holes. And I guess you are using python-tesseract. If so, please refer to Example 4 in https://code.google.com/p/python-tesseract/wiki/CodeSnippets
In order to extract the characters, you may refer to Numpy PIL Python : crop image on whitespace or crop text with histogram Thresholds. There are methods about analysing the histogram of the image so as to locate the position of the whitespaces from which you can infer the boundary.

Categories