labeling
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!