www.gusucode.com > images 案例代码 matlab源码程序 > images/SegmentImageUsingFastMarchingMethodAlgorithmExample.m
%% Segment Image Using Fast Marching Method Algorithm % This example shows how to segment an object in an image using Fast % Marching Method based on differences in grayscale intensity as compared % to the seed locations. %% % Read image. % Copyright 2015 The MathWorks, Inc. I = imread('cameraman.tif'); imshow(I) title('Original Image') %% % Create mask and specify seed location. You can also use |roipoly| to % create the mask interactively. mask = false(size(I)); mask(170,70) = true; %% % Compute the weight array based on grayscale intensity differences. W = graydiffweight(I, mask, 'GrayDifferenceCutoff', 25); %% % Segment the image using the weights. thresh = 0.01; [BW, D] = imsegfmm(W, mask, thresh); figure imshow(BW) title('Segmented Image') %% % You can threshold the geodesic distance matrix |D| using different % thresholds to get different segmentation results. figure imshow(D) title('Geodesic Distances')