An Example: Watershed Segmentation with Matlab. We load in the image that is the cropped part of the image pollens.tif of Figure 5.3 and implement the following steps: i) read in image; and enhance image by stretching the contrast; ii) detect intensity valleys iii) modify the image to contain only those valleys and iv) watershed segmentation. Following command are used to obtain the segmentation shown in Figure 5.X

>> I1 = imread('polcrop.tif'); //read in cropped and despeckled pollen image

>> figure, imshow(I1); //show image on screen

>> I2 = imadjust(I1,[0.24 0.76],[0 1]); //stretch the contrast

>> figure, imshow(I2); //show the contrast stretched image as new figure

>> Iec = imcomplement(I2); // taking the inverse of the contrast stretched image

>>Iemin = imextendedmin(Iec, 40); //detect all the intensity valleys deeper than 40

>>Iimpose = imimposemin(Iec, Iemin);//modify the image to contain only the valleys found

>> wat = watershed(Iimpose);	//watershed on the valleys.

>> rgb = label2rgb(wat);	//color up for visualization

>> figure, imshow(rgb); //display the watershed segmentation

In Step 1, the contrast between the pollens are maximize so that the pollens are more separated from each other. In Step 2, since the watershed function in Matlab works with intensity "valleys", location of mimima rather than maxima, we take the complement of the enhanced image to convert the maxima to "valleys" before we apply the imextendedmin function to look for the "valleys".

Figure 5.X