필터 지우기
필터 지우기

How to find blob nearest to specified coordinate?

조회 수: 1 (최근 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 CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by