## Colour Segmentation in LAB colour space

on 27 Jul 2013

### Image Analyst (view profile)

Please help. I need some help to do yellow segmentation from my retina images. The goal is to use the LAB colour space, and then by means of distance calculation, obtain the new image with everything that is yellow become white and the background black.

Here is my code. I used gtool to select the yellow, and then it must be that yellow that the user has clicked on to determine which are the nearest distance to that colour. What must I further do?

RGB2=im2double(OriginalRGB);

[X Y]=ginput(2);

x=round(X);

y=round(Y);

punt=[x y];

cform = makecform('srgb2lab');

lab = applycform(OriginalRGB,cform);

l=lab(:,:,1);

a=lab(:,:,2);

b=lab(:,:,3);

pixel=double(lab(x,y,:));

[d1 d2]=size(lab);

for i=1:d1

`    for j=1:d2`

euclidean_distance = norm(((pixel(:,:,2)-a).^2+ (pixel(:,:,3)-b).^2).^0.5);

`    end`

end I need to obtain the segmented image?

### Image Analyst (view profile)

on 27 Jul 2013

I have several color segmentation demos in my File Exchange. I doubt that LAB would be the best color space for finding yellow, though it could be depending on what your image's gamut looks like. But most likely, you're better off using hsv color space. Here's one demo of mine that finds yellow: http://www.mathworks.com/matlabcentral/fileexchange/28512-simple-color-detection-by-hue Check out the other segmentation tutorials I've uploaded also.

Valeska Pearson

### Valeska Pearson (view profile)

on 29 Jul 2013

thank you Image analyst, I appreciate it very much. May I ask other question.

Look at the following implementation, why does MATLAB have a problem with norm?

using lab from above code.

` punt=uint8(lab(x,y,:));`
` d1=size(RGB3,1);`
` d2=size(RGB3,2);`
` binaryImage=zeros(d1,d2);`
` punt=punt./256;`
` for i=1:d1`
`     for j=1:d2`
`         pixel=lab(i,j,:);`
`         afstand=(bsxfun(@minus,uint8(pixel),punt));`
`         %afstand=double(afstand);`
`          %afstand=norm(afstand);`
`         binaryImage(i,j) = afstand;`

end

end

Image Analyst

### Image Analyst (view profile)

on 30 Jul 2013

I don't know, but like I said, you don't want to do it that way anyway, unless you want your program to be inefficient and slow.

Valeska Pearson

### Valeska Pearson (view profile)

on 30 Jul 2013

thank you

on 27 Jul 2013

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi