labeling
조회 수: 7 (최근 30일)
이전 댓글 표시
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:
clear all;
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;
for kx=2:xsize-1
for ky=2:ysize-1
W=zeros(3);
W(1:3, 1:3)=ImgLB(kx-1:kx+1,ky-1:ky+1);
maxW=max(W(:));
if ImgLB(kx, ky)==1 & ImgLB(kx,ky-1)==0 & maxW==1
label=label+1;
ImgLB(kx,ky)=label;
end
if ImgLB(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;
while loop
flag=0;
for kx=2:xsize-1
for ky=2:ysize-1
if ImgLB(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
if flag==0
break;
end
for kx=2:xsize-1
for ky=2:ysize-1
if ImgLB(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
답변 (2개)
Walter Roberson
2012년 2월 2일
There is no MATLAB routine named "unit8". Perhaps you meant "uint8".
댓글 수: 5
Image Analyst
2012년 2월 4일
There's a mistake there. You're confusing rows and columns with x and y. The size function gives rows and columns, in that order, which would be ysize and xsize. So the corrected code would be:
[ySize xSize numberOfColorChannels] = size(c);
if numberOfColorChannels > 1
a=double(c(:,:,2))/255.0;
else
a=double(c)/255.0;
end
You can learn about debugging in the help file somewhere, I'm sure.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!