Contents
Lab 2
Lab space colour segmentation examples
close all %close all figures clear %clear varibles
Read the image
Read the image and convert to type double. Use the readDoubleImage function from last week. Note that Matlab lets us read images from websites so we can do this rather than download it first!
url = 'http://blogs.mathworks.com/images/steve/2010/mms.jpg';
rgb = readDoubleImage(url);
imshow(rgb)
Generate the Lab image
lab = applycform(rgb, makecform('srgb2lab'));
lab = lab2double(lab);
Split the 3D image into seperate channels
a = lab(:,:,2); b = lab(:,:,3);
Display the image histogram
LabHistPlot(a,b);
Select the colour
By zooming in, find the bounadries for one of the blobs use this to segment the image
amin=-71; amax=-50; bmin=55; bmax=75; in = inpolygon(a, b, [amin,amax], [bmin bmax]); figure(3) imshow(in)
Morphological operators
Now lets clean the segmentation mask by removing the holes with dilation and erode
figure(4) im2=imdilate(in,ones(7)); im3=imerode(im2,ones(7)); imshow(im3) % Or I could have used imfill figure(5) im4=imfill(in,'holes'); imshow(im4) % Or some other mixture figure(6) im5=imdilate(in,ones(7)); im5=imerode(im5,ones(7)); im5=imfill(im5,'holes'); imshow(im5)