Image segmentation python opencv - python

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

Related

Refine edges of transparent image after removing background using backgroundmattingv2 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.

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.

Objects Extraction from an Image using Python

I'm trying to implement a python program to remove the background and extract the object/objects in the foreground from any given static image (as shown in the attached images). This is similar to "iPhoneX Portrait Effect" or "Bokeh Effect". However, instead of blurring the background one needs to completely remove it.
In short, I want to extract objects from any given image and also create a mask. Below are the examples of both respectively:
Object Extraction:
Image Mask:
I have somewhere listened to Google's DeepLab, but I don't know how to start with it.
Can someone help me, please!
Any step by step tutorial will be very appreciated.
Thanks in advance!
This is a really hard task, there is a reason there are basically no good software to do this already, even in photoshop this is a struggle. I can advice you to start with open Cv and their implemented facial tracking which you may need to configure to work with animals if thats your goal
resources
facial detection:
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html#face-detection
object detection:
https://docs.opencv.org/2.4/modules/contrib/doc/facerec/facerec_tutorial.html
Firstly you should collect data(image) for which object you want to detect or extract the object/objects in the foreground and also create a mask.
Then using tensorflow you can train an instance segmentation model Using your own dataset. (Ref : instance_segmentation)
After getting mask you can extract the foreground.

OCR on images using python and opencv

I am a newbie to computer vision, image processing and OCR. As a part of task, i need to perform the OCR on attached emails. However, the problem is ROI is not constant in all images. For example, in all images we need to extract the information related with patient Yadav.
This needs to be achieved in Python and OpenCV. Please help. I have already tried the approach as given below:
Change DPI
Grayscale
Binarize
However, facing the problem with layout or zone analysis.
Thanks for help.
Welcome to the computer vision world.
I think you're not understanding your problem well enough. Just trying something and check whether it work will never work.
At first read how tesseract (OCR engine) do to improve their accuracy at https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality
Ok, then what make OCR do not work on your data. As you can see your data is clean, and there is nearly none of noise. So it is the border of printed email (as "ROI" in your question) does not correctly line up.
So have can we make the ROI line up correctly . we could use some perspective transformation. i took an example from https://www.pyimagesearch.com/2014/08/25/4-point-opencv-getperspective-transform-example/
So how can we perform perspective transformation. We have to find the 4 corners of the ROI and move it back to corners of the image. To find 4 corner of the ROI you could find some contours .
So here the summary, here is the steps.
1. Find the ROI (white color) using color segmentation
2. Find the contour which cover the ROI
3. Find 4 corners of the ROI's contour
4. Apply perspective transform
5. Run tesseract on transformed image
Hope that help

Categories