You are here : matlabImage Processingactivecontour

activecontour() - Image Processing

bw = activecontour(A,mask) segments the 2-D grayscale image A into foreground (object) and background regions using active contour based segmentation.

The output image bw is a binary image where the foreground is white (logical true) and the background is black (logical false). mask is a binary image that specifies the initial state of the active contour.

The boundaries of the object region(s) (white) in mask define the initial contour position used for contour evolution to segment the image.

To obtain faster and more accurate segmentation results, specify an initial contour position that is close to the desired object boundaries.

bw = activecontour(A,mask,n) segments the image by evolving the contour for a maximum of n iterations.

bw = activecontour(A,mask,method) specifies the active contour method used for segmentation, either 'Chan-Vese' or ‘edge'.

bw = activecontour(A,mask,n,method) segments the image by evolving the contour for a maximum of n iterations using the specified method.

bw = activecontour(___,Name,Value) specifies parameters that control various aspects of the segmentation.

Parameter names can be abbreviated, and case does not matter.


Syntax

bw = activecontour(A,mask)
bw = activecontour(A,mask,n)
bw = activecontour(A,mask,method) 
bw = activecontour(A,mask,n,method)
bw = activecontour(___,Name,Value)


Example

%collapse all Segment an Image Specifying the MaskRead image and display it.
I = imread('coins.png');
imshow(I)
title('Original Image');

%Specify initial contour and display it.
mask = zeros(size(I));
mask(25:end-25,25:end-25) = 1;
figure, imshow(mask);
title('Initial Contour Location');

%Segment the image using the default method and 300 iterations.
bw = activecontour(I,mask,300);  
figure, imshow(bw);
title('Segmented Image');

%Segment Image Overlaying Mask and Contour on Original ImageOpen This Example 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('Intial contour (blue) and final contour (red)');

%Display segmented image.
imshow(bw)
title('Segmented Image');

%Segment an Image Specifying a Polygonal Mask Created InteractivelyRead image and display it, along with instructions to specify initial contour location.
I = imread('toyobjects.png');
imshow(I)
str = 'Click to select initial contour location. Double-click to confirm and proceed.';
title(str,'Color','b','FontSize',12);
disp(sprintf('
Note: Click close to object boundaries for more accurate result.'))

%Specify initial contour interactively.
mask = roipoly;  
imshow(mask)
title('Initial MASK');

%Segment the image, specifying 200 iterations.
maxIterations = 200; 
bw = activecontour(I, mask, maxIterations, 'Chan-Vese');
  
% Display segmented image
figure(0) 
imshow(bw)
title('Segmented Image');


Output / Return Value


Limitations


Alternatives / See Also


Reference