labeling

6 visualizaciones (últimos 30 días)
Syahrul Niezam
Syahrul Niezam el 2 de Feb. de 2012
Editada: dave el 2 de Oct. de 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:
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

Respuestas (2)

Walter Roberson
Walter Roberson el 2 de Feb. de 2012
There is no MATLAB routine named "unit8". Perhaps you meant "uint8".
  5 comentarios
Image Analyst
Image Analyst el 4 de Feb. de 2012
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.
Syahrul Niezam
Syahrul Niezam el 7 de Feb. de 2012
I'm sorry, which line should i change the codes?

Iniciar sesión para comentar.


Syahrul Niezam
Syahrul Niezam el 4 de Feb. de 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!

Translated by