matlab - How can i remove overlaping circles after Hough Transform segmentation -


i'm working in image segmentation, testing lot of different segmentation algorithms, in order comparitive study. @ moment i'm using hough transform find circles in image. images i'm using have plenty objects, when Í count objects result hudge. think problem, overlaping circle. know how can maybe remove overlaping circles have result more close reality?

the code i'm using is:

    clear all, clc;  % image reading i=imread('0001_c3.png'); figure(1), imshow(i);set(1,'name','original') 

image used

% gaussian filter w = fspecial('gaussian',[10,10]); j = imfilter(i,w); figure(2);imshow(j);set(2,'name','filtrada média'); x = rgb2gray(j); figure(3);imshow(x);set(3,'name','grey');  % finding circular objects -- houng transform [centers, radii, metric] = imfindcircles(x,[10 20], 'sensitivity',0.92,'edge',0.03); % [parasites][5 30]  centersstrong = centers(1:60,:); % number of objects radiistrong = radii(1:60); metricstrong = metric(1:60); viscircles(centersstrong, radiistrong,'edgecolor','r'); length(centers)% result=404! 

you loop on circles , check if others "close" them. if so, ignore them.

idx_mask = ones(size(radii));  min_dist = 1; % relative value. tweak if slight overlap ok. = 2:length(radii)     cur_cent = centers(i, :);     j = 1:i-1         other_cent = centers(j,:);         x_dist = other_cent(1) - cur_cent(1);         y_dist = other_cent(2) - cur_cent(2);         if sqrt(x_dist^2+y_dist^2) < min_dist*(radii(i) + radii(j)) && idx_mask(j) == 1             idx_mask(i) = 0;             break         end     end end %%  idx_mask = logical(idx_mask); centers_use = centers(idx_mask, :); radii_use = radii(idx_mask, :); metric_use = metric(idx_mask, :);  viscircles(centers_use, radii_use,'edgecolor','b'); 

the picture shows circles in red, , filtered circles in blue.

disting circles

the if clause checks 2 things: - centers of circles closer sum of radii? - other circle still on list of considered circles? if answer both questions yes, ignore "current circle".

the way loop set up, keep circles higher up (have lower row index). is, circles ordered descending metric. in other words, code keep circles higher metric.

the code optimized loops run faster, don't think you'll have millions of circles in single picture. tried writing in way it's easier read humans.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -