How to find blob nearest to specified coordinate?

2 ビュー (過去 30 日間)
Ivan Shorokhov
Ivan Shorokhov 2015 年 7 月 14 日
編集済み: Ivan Shorokhov 2015 年 7 月 14 日
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

回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by