SEGMENTATION
Edge detection
Edge detection is the operation of finding the boundaries of objects present in an image. This is where the image intensity/color changes sharply. Classical methods use the image gradient or approximations of the image gradient to detect edge location. In MATLAB, the function edge detect edges in grayscale and binary images:
BW = edge(I);
If you have a noisy image it is a good practice to smooth it out before detecting the edges. The reason is that noise may produce unreliable oscillating derivative values across short distances.
Let's investigate the profile of rows of our sample image (its red channel):
I = imread('sample.TIF');
R = I(:,:,1);
figure, imshow(R);
figure, plot( R(128,:));
Smooth using a Gaussian filter and plot the same line after smoothing:
h = fspecial('gaussian',5,4);
G = imfilter(R, h);
figure, imshow(G);
figure, plot( G(128,:));
Experiment the edge detection methods provided by the edge function in the smoothed image G. Which one(s) works best?
So = edge(G, 'sobel');
Pr = edge(G, 'prewitt');
Ro = edge(G, 'roberts');
Lo = edge(G, 'log');
Ca = edge(G, 'canny');
Use the returned value for the gradient threshold to help you calibrate your edge detection:
[S t] = edge(G, 'sobel');
Snew = edge(G, 'sobel', t + 0.1 );
Edge detection is the operation of finding the boundaries of objects present in an image. This is where the image intensity/color changes sharply. Classical methods use the image gradient or approximations of the image gradient to detect edge location. In MATLAB, the function edge detect edges in grayscale and binary images:
BW = edge(I);
If you have a noisy image it is a good practice to smooth it out before detecting the edges. The reason is that noise may produce unreliable oscillating derivative values across short distances.
Let's investigate the profile of rows of our sample image (its red channel):
I = imread('sample.TIF');
R = I(:,:,1);
figure, imshow(R);
figure, plot( R(128,:));
Smooth using a Gaussian filter and plot the same line after smoothing:
h = fspecial('gaussian',5,4);
G = imfilter(R, h);
figure, imshow(G);
figure, plot( G(128,:));
Experiment the edge detection methods provided by the edge function in the smoothed image G. Which one(s) works best?
So = edge(G, 'sobel');
Pr = edge(G, 'prewitt');
Ro = edge(G, 'roberts');
Lo = edge(G, 'log');
Ca = edge(G, 'canny');
Use the returned value for the gradient threshold to help you calibrate your edge detection:
[S t] = edge(G, 'sobel');
Snew = edge(G, 'sobel', t + 0.1 );
K-Means
Kmeans is an iterative clustering technique that separates a data set into K mutually exclusive clusters, such that members within a cluster are closer to each other and to the cluster centroid (its mean) than to members and centroid of any other cluster. When applied to perform image segmentation, Kmeans partitions the image into regions of similar intensities. It works very well for images with similarly defined regions.
In MATLAB, use the function kmeans (note that kmeans is not part of the image processing toolbox as it can be used for general data sets; it is a function of the statistics toolbox):
doc kmeans
Let's use Kmeans to segment the red channel of the HELA image. We will need to reshape the image matrix to a format acceptable by kmeans (a flat array):
I = imread('HELA');
I = I(:,:,1);
num_rows = size(I, 1);
num_cols = size(I, 2);
R = reshape( I, num_rows*num_cols, 1 ); (or simply I(:) )
k = 2;
[IDX, C] = kmeans( double(R), k, 'Replicates', 4, 'start', 'sample' );
B = zeros(size(IDX));
B(IDX == 2) = 255;
S = reshape(B, num_rows, num_cols);
figure, imshow(S);
As it is, the kmeans segmentation seems to be a bit inferior when compared to the threshold segmentation we achieved in the previous lecture for the HELA nuclei image.
But we can easily adjust the kmeans result using morphological operations (try also with imfill to fill holes):
sel = strel('disk', 1);
C = bwareaopen( imclose(S, sel), 30 );
figure, imshow(C);
Watershed
The watershed algorithm is a powerful mathematical morphology based segmentation tool. Think of an image as a topographic map where bright regions represent mountain top ridges and dark regions represent valley plateaus. By flood filling this topographic map the watershed algorithm determines the catchment basins that are separated by the ridge lines.
A classical usage of the watershed approach is to separate overlapping, touching regions, a common scenario when imaging cell nuclei, moving bacteria, etc. The watershed method works very well when applied to the Euclidean distance transform of a binary image.
MATLAB provides the watershed function as part of the image processing toolbox:
doc watershed
Consider our HELA nuclei image to be a small piece of a much larger image where you had much success doing some morphological operations to segment the other nuclei but a few touching regions remained. We can try to use watershed to separate these touching regions.
I = imread('overlap-2.png');
D = bwdist(~I);
B = -D;
B(~I) = -Inf;
W = watershed(B, 8);
C = label2rgb( W, 'jet' );
figure, imshow(C);
Kmeans is an iterative clustering technique that separates a data set into K mutually exclusive clusters, such that members within a cluster are closer to each other and to the cluster centroid (its mean) than to members and centroid of any other cluster. When applied to perform image segmentation, Kmeans partitions the image into regions of similar intensities. It works very well for images with similarly defined regions.
In MATLAB, use the function kmeans (note that kmeans is not part of the image processing toolbox as it can be used for general data sets; it is a function of the statistics toolbox):
doc kmeans
Let's use Kmeans to segment the red channel of the HELA image. We will need to reshape the image matrix to a format acceptable by kmeans (a flat array):
I = imread('HELA');
I = I(:,:,1);
num_rows = size(I, 1);
num_cols = size(I, 2);
R = reshape( I, num_rows*num_cols, 1 ); (or simply I(:) )
k = 2;
[IDX, C] = kmeans( double(R), k, 'Replicates', 4, 'start', 'sample' );
B = zeros(size(IDX));
B(IDX == 2) = 255;
S = reshape(B, num_rows, num_cols);
figure, imshow(S);
As it is, the kmeans segmentation seems to be a bit inferior when compared to the threshold segmentation we achieved in the previous lecture for the HELA nuclei image.
But we can easily adjust the kmeans result using morphological operations (try also with imfill to fill holes):
sel = strel('disk', 1);
C = bwareaopen( imclose(S, sel), 30 );
figure, imshow(C);
Watershed
The watershed algorithm is a powerful mathematical morphology based segmentation tool. Think of an image as a topographic map where bright regions represent mountain top ridges and dark regions represent valley plateaus. By flood filling this topographic map the watershed algorithm determines the catchment basins that are separated by the ridge lines.
A classical usage of the watershed approach is to separate overlapping, touching regions, a common scenario when imaging cell nuclei, moving bacteria, etc. The watershed method works very well when applied to the Euclidean distance transform of a binary image.
MATLAB provides the watershed function as part of the image processing toolbox:
doc watershed
Consider our HELA nuclei image to be a small piece of a much larger image where you had much success doing some morphological operations to segment the other nuclei but a few touching regions remained. We can try to use watershed to separate these touching regions.
I = imread('overlap-2.png');
D = bwdist(~I);
B = -D;
B(~I) = -Inf;
W = watershed(B, 8);
C = label2rgb( W, 'jet' );
figure, imshow(C);
No comments:
Post a Comment