Effacer les filtres
Effacer les filtres

How to find blob nearest to specified coordinate?

1 vue (au cours des 30 derniers jours)
Ivan Shorokhov
Ivan Shorokhov le 14 Juil 2015
Modifié(e) : Ivan Shorokhov le 14 Juil 2015
Given: I have following image:
Want: I want to find blob nearest to desired coordinate [160,138], and remove all other blobs, as show bellow:
Currently done:
I=imread('1_im.jpg');
BW= im2bw(I);
CC = bwconncomp(BW, 8);%Determine the connected components
stat_I = regionprops(CC,'Area','Centroid'); %Compute the area and centroid of CC
L = labelmatrix(CC); % Create label matrix
aprox_coor=[160,138]; % Coordinates of intrest
x_coor = aprox_coor(1);y_coor = aprox_coor(2);
for u = 1:length([stat_I.Area]) % Convert struct.Centoid into double
x_cent(u)=stat_I(u).Centroid(:,1);
y_cent(u)=stat_I(u).Centroid(:,2);
xy_cent=[x_cent' y_cent'];
end
if length([stat_I.Area])<1 %chek in check for empty cells within stat_I list
ind_xy = [];
else
%find index of wanted x coordinate +/- 10%
ind_x = find(x_cent >= x_coor*0.9 & x_cent <= x_coor*1.1);
ind_y = find(y_cent >= y_coor*0.9 & y_cent <= y_coor*1.1); % the same for y
ind_xy = intersect(ind_x,ind_y); % check if indexs are the same
stat_I(ind_xy).Area %Remove all other objects
BW2 = ismember(L, find([stat_I.Area] == stat_I(ind_xy).Area));
figure(ci); imshow(BW2);
end
Needed: I'm wondering how to simplify and make the code more robust.
[ACKNOWLEDGMENTS]
Thank you for any help.
I will vote for all your answers.
[MATLAB version]
R2014a

Réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by