Graphic STI
logo EPFL
Text EPFL
english only
Biomedical Imaging Group
IP-LAB: Image Processing Laboratories
BIG > IP-LAB > Sessions > Image Analysis IV

Image Analysis

Java Notes
Number Π: double pi = Math.PI; AND logical operator: if (a==b && b>c)
Largest positive value: double max = Double.MAX_VALUE; Maximum value of a image: int max = (int)im.getMaximum();
Largest negative value: double min = -Double.MAX_VALUE; Minimum value of a image: int min = (int)im.getMinimum();

1. Labeling of objects

Labeling is a function that identifies and labels the connected components inside an image. The input is a binary image containing white objects (255) on a black background (0). The output is a labeled image, where each object has a pixel intensity corresponding to its label number (see figure on the right) from 1 to n (n is the number of objects) and 0 inside the background.

Write a method counting() giving the number of objects from a labeled image (use IJ.write(""+n) to display the result).

Open the image blobs.tif, adjust the threshold to obtain a binary image (cells in white, background in black) and apply a median filter (Process → Filters → Median) to suppress the noise. Then, label the image with the plugin Labeling and use Counting to display the number of cells in the image. Fill in the report.

 

2. Calculation of object features

2.1 Area

The method area() computes an estimation of the area of the objects by counting the number of pixels inside an object. This routine is provided. Read and understand the code of this function in Code.java.

Apply this method to test.tif using the plugin Area and fill in the report.

2.2 Center of gravity

Write the methods xGravityCenter() and yGravityCenter() which return the center of gravity of every object in a labeled image.

Apply this method to test.tif using the plugin Gravity Center and fill in the report.

2.3 Perimeter

Write the method perimeter() which computes an estimation of the discrete perimeter of every object in a labeled image. For every object, it scans the image to identify pixels belonging to the current object. Then, it sums the number of pixels having at least one neighbour (4-connected components) belonging to the background. We assume there is no object on edge.

Apply this method to test.tif using the plugin Perimeter and fill in the report.

2.4 Circularity

A common compactness measure, called the circularity ratio, is the ratio of the area of the object to the area of a circle (the most compact shape) having the same perimeter. That ratio is expressed mathematically as C = 4*Π*(Area)/(Perimeter)2. For a circle, this ratio is 1; for an infinitely long and narrow shape, it tends to 0. Note that due to the error on the perimeter estimation, the circularity ratio may be greater than 1.

Write a method circularity() that computes the circularity ratio of every object in a labeled image.

Apply this method to test.tif using the plugin Circularity and fill in the report.

2.5 Width/Height ratio

Write a method wh() that computes the width/height ratio of every object in a labeled image.

Apply this method to test.tif using the plugin WH and fill in the report.

 

3. Classification based on shape features

a. Comparison of features

We propose to determine the best features to discriminate the 0s from the 1s. The plugin Features plots the value of the features for every object in the image. The dialog box allows you to define the ground truth. For example, if you have three objects, a 0 and then two 1 in the image, enter "0 1 1" as training vector in the dialog box (blank space as separator); the order of the sequence must correspond to the labeling order which may be different from the position in the image. The plot shows the value of the computed features for 0s (red) and 1s (blue). Note: the values are normalized to the maximum value.

Repeat these steps for numbers2.tif and numbers3.tif.

Insert the three plots in the report and comment. Which is the best feature to discriminate the 0s from the 1s? Explain your choice.

b. Classification of objects

The classification is a procedure in which individual objects are placed into classes based on quantitative information on one or more characteristics inherent in the objects (features) and based on a training set of previously labeled items.

Training

In what follows we use the image squares-circles.tif as a training set of two classes: squares S (red) and circles C (blue).

Label the image squares-circles.tif and run the plugin Features. Comment the distribution of samples for the circularity. Run the Circularity to obtain the circularity for each object, compute the mean and the standard deviation for each class and fill the corresponding table in the report.

Recognition

Suppose we have three objects in the image unknowns.tif, that we want to classify as squares or circles.

Method 1: A simple way to classify the unknown objects is to compute the minimal distance between the object value and the mean of each class (|x-μi|). Classify the three unknown objects in the report.

Method 2: A more efficient way to classify the objects is to compute the minimal Mahalanobis distance, given in our case by (|x-μi|)/σi, with σi the standard deviation of the class. Classify the three unknown objects in the report.

4. Challenge

a. Propagation from a seed pixel

Write a method prop() that returns a binary image containing the object located in (x,y). Hint: Think recursively!
Put the pixel (x,y) of the output to 1. Then for each of the four neighbours, if the corresponding pixel in is non-zero in the input image and zero in the output, run the method prop() from a specific pixel.
Warning: do not forget to test for the limit of the image.

 

b. Implementation of labeling

The method labeling() scans the pixels of the input image, and every time the value is non zero, it runs prop() to identify the object. Then, this object is added to the output with a unique label, and it is suppressed from the input image.


webmaster.big@epfl.ch • 14.06.2007