Connected Components Analysis

 

 

Introduction

 

In this exercise you will get acquainted with some methods for doing connected components analysis in Matlab.

 

Labelling

 

In Matlab the function bwlabel is used for labelling a binary image. Find out how this function works using the help command.

 

> help bwlabel

 

Load the image from the file image1.mat (using the command load). Display the image (e.g. using imagesc).

 

Exercise 1

 

Apply bwlabel on image1 using both 4 and 8 neighbour connectivity. Explain the difference in the output.

 

Exercise 2

 

The Matlab function regionprops allows you to get different summary values of the labelled components. Read the help of this function. This function returns an array of structs. To get access to an element, e.g. element 1, use the following.

 

> b = regionprops(a,’Area’);

> val = b(1).Area;

 

Exercise 3

 

Using the functions in the two first exercises, make an m-file that detects which one is:

 

a)      The biggest component (Area)

b)      The smallest (Area)

c)      The longest

d)      The shortest

e)      Display the centers (Centroids) of all the components

 

Exercise 4

Calculate the Euler number of the image

 

Spatial Moments

 

Exercise 5

In the previous exercise you found some properties of the image using functions implemented in MatLab. In this exercise you will implement some of these functions yourself in order to get a better understanding of these functions.

 

Make an m-file that calculates the area and the centroids (centers) using the moments m00 and m10 and m01 according to the formulas found in Section 9.6 in the book.

 

Compare your results with the results obtained in exercise 3.

 

Exercise 6

 

Load the image image2

 

Make an m-file that calculates the 3 central moments: µ20, µ02, µ11 of the component of this image.

 

Calculate the eigen values λ1 and λ2 and the eigen vectors.

 

Plot the eigen vectors in the image and explain their relation to the structure of the image. (Hint: One way to plot a line is to create a number of points on that line and use the plot command.)

 

Application Exercise

 

The Goal of this exercise is to apply some of the methods that you have been taught during last week to some real image processing problems.

 

Fundus images are images taken with a special camera through the pupil of the retina. The idea is that you can diagnose diabetes 2 by looking at this kind of images but recent research shows that it might be possible to diagnose other kinds of illness using fundus images. One of the nicest properties of the fundus images is that they are obtained using a non-invasive procedure and are cheap. They are therefore a good way of doing screening on a huge amount of patients for a variety diseases.  

 

When using fundus images for diagnosing diabetes. One way of doing this is by looking for lesions on the retina but they can sometimes be mistaken for vessels. These lesions are a sure sign of diabetes and their development are monitored to see how the disease progresses. Another sign of diabetes is the way the vessels look especially around the optic nerve head.

 

The problem is now to segment the vessels from the rest of the image.

 

We suggest that you do it in the following way:

 

Read the image eye.jpg and visualize it (you read the image using the function imread)

 

> im = imread(‘eye.jpg’);

 

The image is quite large so make a smaller image by sub sampling the image. Sub sampling the image can be done like this:

 

> ims = im(1:8:end, 1:8:end);

 

Display the image.

 

Calculate the gradients at each pixel in the image.

 

> [fx,fy] = gradient(double(ims));

 

Make a new image using the length of the gradients.

 

> im2 = sqrt(fx.*fx + fy.*fy);

 

Display the image

 

Now make a threshold of the image using an appropriate threshold value (Play around with the value).

 

> im3 = im2>threshold;

 

Now label the components in the image

 

> im4 = bwlabel(im3,8);

 

There may be too many components to visualise using gray levels. It may therefore be necessary to convert the labels to RGB values.

 

> im5 = label2rgb(im4);

 

Display the image.

 

Now a function should be made that removes all the components that have an area less than a threshold value. This function will remove the noise components.

 

The following function could be used:

 

function res=remover(image, minarea)

 

res = image;

 

maxi=max(max(image));

areas=regionprops(image,'Area');

for i=1:maxi

    temp=areas(i).Area;

    if(temp<minarea)

        aux=find(image==i);

        res(aux)=0;

    end  

end

 

Finally plot the result agains the image. Hopefully you have removed the noise components.