Home > freetb4matlab > image > poly2mask.m



% Convert a polygon to a region mask.


function BW = poly2mask(x, y, m, n)


% -*- texinfo -*-
% @deftypefn {Function File} {@var{BW} = } poly2mask (@var{x},@var{y},@var{m},@var{n})
% Convert a polygon to a region mask.
% BW=poly2mask(x,y,m,n) converts a polygon, specified by a list of
% vertices in @var{x} and @var{y} and returns in a @var{m}-by-@var{n}
% logical mask @var{BW} the filled polygon. Region inside the polygon
% is set to 1, values outside the shape are set to 0.
% @var{x} and @var{y} should always represent a closed polygon, first
% and last points should be coincident. If they are not poly2mask will
% close it for you. If @var{x} or @var{y} are fractional they are
% nearest integer.
% If all the polygon or part of it falls outside the masking area
% (1:m,1:n), it is discarded or clipped.
% This function uses scan-line polygon filling algorithm as described
% in http://www.cs.rit.edu/~icss571/filling/ with some minor
% modifications: capability of clipping and scan order, which can
% affect the results of the algorithm (algorithm is described not to
% reach ymax, xmax border when filling to avoid enlarging shapes). In
% this function we scan the image backwards (we begin at ymax and end
% at ymin), and we don't reach ymin, xmin, which we believe should be
% compatible with MATLAB.
% @end deftypefn


This function calls: This function is called by:
Generated on Sat 16-May-2009 00:04:49 by m2html © 2003