How to remove excess objects from background?
이전 댓글 표시
Hi,
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.

clc
clear all
close all
img= imread("C:\Users\017_14px.tif");

imshow (img)
b=imbinarize (img); %binary image
imshow(b)
img1 = xor(bwareaopen(b,45), bwareaopen(b,1000));
%img1= bwareaopen(b,10);
imshow(img1)
stats = regionprops('table',img1,'Centroid','MajorAxisLength','MinorAxisLength') %object detection
centers = stats.Centroid;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
hold on
viscircles(centers,radii); %drawing around the object
hold off
num_obj=height (stats)%finding the number of objects
댓글 수: 4
Image Analyst
2020년 5월 9일
What is your definition of "excess"? Maybe try bwareafilt()???
learningmatlab
2020년 5월 9일
Image Analyst
2020년 5월 9일
And what does a "fix" look like to you? Ignore 10 of the blobs on the right so now we'll only detect 25 blobs instead of 35? Try thresholding instead of using imbinarize():
thresholdValue = 80; % Whatever. Change until you get what you want.
b = img > thresholdValue; %binary image
You have to give some criteria as to what constitutes a blob? Is it the size? Is it the brightness? The shape?
learningmatlab
2020년 5월 9일
채택된 답변
추가 답변 (1개)
Ryan Comeau
2020년 5월 15일
Hello,
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:
image=imread('path/to/image');
image=medfilt2(image,[12 12]);
image=medfilt2(image,[6 6]);
Hope some of these help,
RC
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!