solve the code for label assigning

1 view (last 30 days)
asthana
asthana on 3 Apr 2014
hello this is the code for find the connectivity but still i didnt get the answer please tell me wats the wrong
Image=imread('rice.png'); [M, N]=size(Image); Connected = zeros(M,N); Mark = []; Offsets = [-1: M; 1: -M]; Index = []; No_of_Objects = 0;
for i= 1:M
for j= 1:N
if(Image(i,j)==1)
No_of_Objects = No_of_Objects +1;
Index = [((j-1)*M + i)];
Connected(Index)=Mark;
while ~isempty(Index)
Image(Index)=0;
Neighbors = bsxfun(@plus, Index, Offsets');
Neighbors = unique(Neighbors(:));
Index = Neighbors(find(Image(Neighbors)));
Connected(Index)=Mark;
end
Mark = Mark + Difference;
end
end
end

Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!