seed growing region segmentation in matlab

Here's an example code to perform seed-based region growing segmentation for a grayscale image in MATLAB using the watershed transform:

main.m
% Read grayscale image
I = imread('image.jpg');

% Thresholding
bw = imbinarize(I);

% Compute Euclidean distance transform
D = bwdist(~bw);

% Compute regional minima of distance transform
D = -D;
D(~bw) = -inf;
L = watershed(D);

% Find the local minima of watershed image L
minima = imextendedmin(I, 2);

% Mark the watershed ridge lines using a marker-controlled watershed
L = watershed(imimposemin(D, minima));

% Display segmentation results
figure
imshow(label2rgb(L, 'spring', 'c'))
title('Watershed Segmentation')
523 chars
25 lines

The code above first threshold the input grayscale image and then compute its Euclidean distance transform. The regional minima of the distance transform are then computed and marked as markers for the watershed segmentation. Finally, the watershed transform is applied on the distance transform using the markers as seed regions to segment the grayscale image. The result is then displayed using different colors for each segmented region.

gistlibby LogSnag