www.gusucode.com > images 案例代码 matlab源码程序 > images/SegmentImageOverlayingMaskAndContourOnOriginalImageExample.m
%% Segment Image Overlaying Mask and Contour on Original Image % %% % Read image and display it. I = imread('toyobjects.png'); imshow(I) hold on title('Original Image'); %% % Specify initial contour location close to the object that is to be % segmented. mask = false(size(I)); mask(50:150,40:170) = true; %% % Display the initial contour on the original image in blue. visboundaries(mask,'Color','b'); %% % Segment the image using the |'edge'| method and 200 iterations. bw = activecontour(I, mask, 200, 'edge'); %% % Display the final contour on the original image in red. visboundaries(bw,'Color','r'); title('Initial contour (blue) and final contour (red)'); %% % Display segmented image. figure, imshow(bw) title('Segmented Image');