Refine edges of transparent image after removing background using backgroundmattingv2 python - python

I have come across this BackgroundMattingV2 AI library to remove background of an image. So, I have tried their example and it is working as shown. I watched this video to learn how to setup.
So far so good it is removing background, I tried other images as well and it working.
However, I can see some noise on the edges.
I tried Image number 12 form here.
And here is the output
I have tried a few different settings with model type mattingrefine
refine mode - full with backbone scale 0.125
refine mode - sampling with sample pixcel 320000 and backbone scale 0.125
refine mode - thresholding with threshold value as 0.7 and backbone scale 0.125
I can see some difference in the noise but it's not removed completely. Hence, I could conclude that the background matting is designed to work in this way and it is correct output.
Note that I am using python 3.9 on windows 10 OS.
So here are my questions:
Am I thinking right that the best solution here is to apply feathers to the edges?
I believe that this is possible using image processing library like openCV. But I could not find a good example that can show me how can I use openCV to apply feathers to the edges of the image. Can someone please provide sample code to soften the edges of the image. Attached image can be used as reference.
The backgroundmatting can return the transparent image as numpy.ndarray or a PIL Image object.
Any other option alternative to remove that unwanted noise and make edges cleaner?
Update
Thanks fmw42
I have applied the filter (Gaussian Blur) after searching in the forum this and this. I got better results and the noise was removed. Now, I am getting greedy and want the perfect edge.

Related

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 ..

What is the best way to track an object in a video?

I'm trying to learn computer vision and more specifically open-cv in python.
I want to make a program that would track my barbell in a video and show me its path. (I know apps like this exists but I want to make it myself). I tried using the Canny edge detection and the HoughCircles functions but I seem to get everything but a good result.
I have been using this code to find the edges of my image:
gray = cv.cvtColor(src=img, code=cv.COLOR_BGR2GRAY)
blur = cv.blur(gray, (2,2))
canny = cv.Canny(blur, 60, 60)
And then this code to find the circle:
circles = cv.HoughCircles(canny, cv.HOUGH_GRADIENT, dp=2, minDist=1000, circles=None,maxRadius=50)
This is the result:
Result
left = original image with detected circle // right = canny image
Is this the right way to go or should I use another method?
Train the YOLO model for the barbell to detect barbel object is better than anything you tried with OpenCV. You need at least 500 images. Those images can be found on the internet easily. This tutorial is kick start tutorial on YOLO. Let's give a try.
If you tweak the parameters of HoughCircles it may recognize the barbell [EDIT: but with more preprocessing, gamma correction, blurring etc., so better not], however OpenCV has many algorithms for such object tracking - only a region from the image has to be specified first (if that's OK).
In your case the object is always visible and is not changing much, so I guess many of the available algorithms would work fine.
OpenCV has a built-in function for selection:
initBB = cv2.selectROI("Frame", frame, fromCenter=False, showCrosshair=True)
See this tutorial for tracking: https://www.pyimagesearch.com/2018/07/30/opencv-object-tracking/
The summary from the author suggestion is:
CSRT Tracker: Discriminative Correlation Filter (with Channel and Spatial Reliability). Tends to be more accurate than KCF but slightly slower. (minimum OpenCV 3.4.2)
Use CSRT when you need higher object tracking accuracy and can tolerate slower FPS throughput
I guess accuracy is what you want, if it is for offline usage.
Can you share a sample video?
What's your problem exactly? Why do you track the barbell? Do you need semantic segmentation or normal detection? These are important questions. Canny is a very basic approach It' needs a very stable background to use it. That's why there is deep learning to handle that kind of problem If we need to talk about deep learning you can use MaskRCNN, yolvoV4, etc. there are many available solutions out there.

Computer Vision: Removing noise from an image

I need to delete the noise from this image. My problem is that I need a neat contour without all the lines like in this image.
Do you have any suggestions how to do that using python?
Looking at your example images, I suppose you are looking for an image processing algorithm that finds the edges of your image (in your case, the border lines of the ground plan).
Have a look the Canny edge detection algorithm which might be a well-suited for this task. A tutorial with an example implementation in python can be found here.

Best way to find background - Image processing Python

I am working on a project where I have to find the background of a given gray-scale image.
I did several kinds of research on the internet and I've found some algorithms using OpenCV library (like the following: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html#py-background-subtraction).
This kind of approach doesn't work for me.
The image I want to elaborate is:
As you can see it is in gray-scale and we see the "gray static" background. I would love to see only the nucleus of the cell (the image will improve resolution and quality in the time, this is a pretty raw one)
I tried to subtract the 2D magnitude FFT of the background from the main image but the results is not good:
What I am asking is: What kind of process do you suggest to use to eliminate background?
Did you already try watershed algorithm ? I saw on a paper it's already used and improved for cell image segmentation.
Background subtraction won't work for your images because your background is not consistent. image's SNR is too low!
So you have 2 options:
1) Using deep learning method (like UNET) if you have enough data
2) Using bilateral filter then, some methods like active contour or GLCM Texture Feature or k-means clustering.

Remove bright streak from image using python

I have a set of images I'm using to perform a 3D reconstruction using mayavi in python, unfortunately there is a bright streak through most images over the features of interest that is screwing my reconstruction up, as shown in the figure below. The features of interest in this case are the 'holes' in the structure.
I've attempted to use scikit-image erode and dilate functions to remove the feature, unfortunately the distorts the rest of the image a little too much, whilst failing to remove the feature completely, as shown below.
Does anyone know how I can simply remove this bright streak, without distorting the rest of the image?

Categories