%randvertex源程序
function [xn, yn] = randvertex(x, y, npix)
%RANDVERTEX Adds random noise to the vertices of a polygon.
% [XN, YN] = RANDVERTEX[X, Y, NPIX] adds uniformly distributed
% noise to the coordinates of vertices of a polygon. The
% coordinates of the vertices are input in X and Y, and NPIX is the
% maximum number of pixel locations by which any pair (X(i), Y(i))
% is allowed to deviate. For example, if NPIX = 1, the location of
% any X(i) will not deviate by more than one pixel location in the
% x-direction, and similarly for Y(i). Noise is added independently
% to the two coordinates.
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.4 $ $Date: 2003/06/14 16:31:17 $
% Convert to columns.
x = x(:);
y = y(:);
% Preliminary calculations.
L = length(x);
xnoise = rand(L, 1);
ynoise = rand(L, 1);
xdev = npix*xnoise.*sign(xnoise - 0.5);
ydev = npix*ynoise.*sign(ynoise - 0.5);
% Add noise and round.
xn = round(x + xdev);
yn = round(y + ydev);
% All pixel locations must be no less than 1.
xn = max(xn, 1);
yn = max(yn, 1);
randvertex.m
最新推荐文章于 2021-03-20 08:36:42 发布