labeling

3 views (last 30 days)
Syahrul Niezam
Syahrul Niezam on 2 Feb 2012
Edited: daveon 2 Oct 2013
I'm trying to do labeling after segmentation into four regions (white, light gray, dark gray and black) according to threshold method. This is the code:
clearall;
c = imread('image1_069.jpg');
a=double(c);
b = zeros(size(a));
b = uint8(a<90);
b(a >= 110) = 180;
b(a >= 150) = 200;
b(a >= 200) = 255;
figure(1);
imshow(b);
%Labeling
ImgLB = b;
ImgLB(1,:)=0; ImgLB(xsize,:)=0; ImgLB(:,1)=0;
ImgLB(:,ysize)=0;
label=0;
forkx=2:xsize-1
forky=2:ysize-1
W=zeros(3);
W(1:3, 1:3)=ImgLB(kx-1:kx+1,ky-1:ky+1);
maxW=max(W(:));
ifImgLB(kx, ky)==1 & ImgLB(kx,ky-1)==0 & maxW==1
label=label+1;
ImgLB(kx,ky)=label;
end
ifImgLB(kx,ky)==1 & maxW>=1
ImgLB(kx,ky)=maxW;
end
end
end
figure(1)
subplot(1,3,1), imagesc(c),title ('Input')
subplot(1,3,2), imagesc(b), title('Threshold')
subplot(1,3,3), imagesc(unit8(ImgLB*255/max(max(ImgLB)))), title('Label')
colormap('gray');
loop=1;
whileloop
flag=0;
forkx=2:xsize-1
forky=2:ysize-1
ifImgLB(kx,ky)~=0 & ImgLB(kx+1,ky)~=0 & ImgLB(kx,ky)~=ImgLB(kx+1,ky)
old=ImgLB(kx,ky);
new=ImgLB(kx+1,ky);
flag=1;
break;
end
end
end
ifflag==0
break;
end
forkx=2:xsize-1
forky=2:ysize-1
ifImgLB(kx,ky)==old
ImgLB(kx,ky)==new;
end
end
end
end
But, there is error at the line subplot(1,3,3), imagesc(unit8(ImgLB*255/max(max(ImgLB)))), title('Label')
I have no idea what's the mistake in that line. Is there any suggestion. This is the image I used: http://i41.tinypic.com/243glli.jpg

Answers (2)

Walter Roberson
Walter Roberson on 2 Feb 2012
There is no MATLAB routine named "unit8". Perhaps you meant "uint8".
5 Comments
Syahrul Niezam
Syahrul Niezam on 7 Feb 2012
I'm sorry, which line should i change the codes?

Sign in to comment.


Syahrul Niezam
Syahrul Niezam on 4 Feb 2012
Thanks for your help. However, there is error in line;
ImgLB(1,:)=0; ImgLB(xsize,:)=0; ImgLB(:,1)=0;
Is there anything mistake?

Community Treasure Hunt

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

Start Hunting!