How to remove excess objects from background?
4 views (last 30 days)
Show older comments
Answered: Image Analyst on 20 May 2020
I am trying to match the objects from the image on left hand side to the image on right hand side. But I am unable to do it accurately. I have attached the image and the code that I am using. I have also attached the original image. Please help me on how can I go about fixing this. Thanks.
b=imbinarize (img); %binary image
img1 = xor(bwareaopen(b,45), bwareaopen(b,1000));
stats = regionprops('table',img1,'Centroid','MajorAxisLength','MinorAxisLength') %object detection
centers = stats.Centroid;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
viscircles(centers,radii); %drawing around the object
num_obj=height (stats)%finding the number of objects
Image Analyst on 20 May 2020
There is an algorithm called the Clean algorithm. Basically it works by finding the biggest peak and fitting a Gaussian to it. Then put the fit on the output image and subtract the fit from the input image. Keep going until the peaks are so small that you don't care about them anymore.
There is also another astronomony algorithm - the Groth algorithm. They've even reapplied it to look at spots on whale sharks:
More Answers (1)
Ryan Comeau on 15 May 2020
So in order to to fix you problem, there is an algorithm that peforms great for background removal, which is what you probably want here. I unfortunately cannot share it with you as I have programmed it professionally. I can however explain briefly how it works and link some scientific papers for you. The algorithm was desingned by a man called Martin Levesque (paper titled ...iterative background removal...) to remove background from space based image sensors. It involved removing the background of sub images within the image. We calculate the average of the sub image and then subtract the average for that region. You can customize the window size to your purpose. The point is the mean of the region will be removed and the bright pointy objects you have will remain there. Here is a paper for your reading and building of this algorithm:
The second thing that you can attempt is the built in median filter function that MATLAB has. You can use a variety of these sequentially as you will want to tune the performance. You will need to select a varying range of window sizes to use. here is some sample code:
Hope some of these help,
Find more on Get Started with Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!