Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help in connected component algorithm

Status
Not open for further replies.

mona:)

New Member
Hi
i've written a matlab code to count connected component for binary images. but matlab shows this eeror "Subscript indices must either be real positive integers or
logicals" Could u help me to correct it?(i know that bwlable do it easily but i must write an algorithm)
thank u.
Here is the code:
imagepath='C:\Documents and Settings\harry patter\My Documents\My Pictures\m.bmp'
[I map]=imread(imagepath);

Ig=I;
if ~isempty(map)
Ig=ind2gray(I,map);
elseif length(size(I))==3
Ig=RGB2gray(I);
else
Ig=I;
end;
Ig=logical(Ig);
Ig=~Ig;
Ig=im2double(Ig);
imshow(Ig);
n=1;
[M, N]=size(Ig);
for i=1:1:M ;
for j=1:1:N;
if Ig(i,j)==1
Ig(i,j)=n;
n=n+1;
end
for k=-1:1:1;
for s=-1:1:1;
if I(i+k,j+s)==1
I(i+k,j+s)=n;
end
end
end
if (Ig(i-1,j)==0 && Ig(i,j-1)==0)
n=n+1;
end
d=[Ig(i-1,j-1) Ig(i-1,j) Ig(i-1,j+1) ;Ig(i,j-1) Ig(i,j) Ig(i,j+1)];
V=min(sparse(d));
Ig(i,j)=V;
end
end
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top