www.gusucode.com > images 案例代码 matlab源码程序 > images/CalculateGrayscaleIntensityDifferenceWeightsExample.m
%% Calculate Grayscale Intensity Difference Weights % This example segments an object in an image using Fast Marching Method % using grayscale intensity difference weights calculated from the % intensity values at the seed locations. %% % Read image and display it. % Copyright 2015 The MathWorks, Inc. I = imread('cameraman.tif'); imshow(I) title('Original Image') %% % Specify row and column index of pixels for use a reference grayscale % intensity value. seedpointR = 159; seedpointC = 67; %% % Calculate the grayscale intensity difference weight array for the image % and display it. The example does log-scaling of |W| for better % visualization. W = graydiffweight(I, seedpointC, seedpointR,'GrayDifferenceCutoff',25); figure, imshow(log(W),[]) %% % Segment the image using the grayscale intensity difference weight array. % Specify the same seed point vectors you used to create the weight array. thresh = 0.01; BW = imsegfmm(W, seedpointC, seedpointR, thresh); figure, imshow(BW) title('Segmented Image')