fchcode.m ( File view )

  • By yueqiaohuayuan 2014-11-17
  • View(s):3508
  • Download(s):7
  • Point(s): 3
			function  c = fchcode(b, conn, dir)
%FCHCODE Computes the Freeman chain code of a boundary.
%   C = FCHCODE(B) computes the 8-connected Freeman chain code of a
%   set of 2-D coordinate pairs contained in B, an np-by-2 array. C
%   is a structure with the following fields: 
%
%     c.fcc    = Freeman chain code (1-by-np)
%     c.diff   = First difference of code c.fcc (1-by-np)
%     c.mm     = Integer of minimum magnitude from c.fcc (1-by-np)
%     c.diffmm = First difference of code c.mm (1-by-np)
%     c.x0y0   = Coordinates where the code starts (1-by-2) 
%
%   C = FCHCODE(B, CONN) produces the same outputs as above, but
%   with the code connectivity specified in CONN. CONN can be 8 for
%   an 8-connected chain code, or CONN can be 4 for a 4-connected
%   chain code. Specifying CONN=4 is valid only if the input
%   sequence, B, contains transitions with values 0, 2, 4, and 6,
%   exclusively.
%       
%   C = FHCODE(B, CONN, DIR) produces the same outputs as above, but,
%   in addition, the desired code direction is specified. Values for
%   DIR can be: 
%
%     'same'      Same as the order of the sequence of points in b.
%                 This is the default.
%
%     'reverse'   Outputs the code in the direction opposite to the 
%                 direction of the points in B.  The starting point 
%                 for each DIR is the same.
%
%   The elements of B are assumed to correspond to a 1-pixel-thick,
%   fully-connected, closed boundary. B cannot contain duplicate
%   coordinate pairs, except in the first and last positions, which
%   is a common feature of boundary tracing programs. 
%
%   FREEMAN CHAIN CODE REPRESENTATION
%   The table on the left shows the 8-connected Freeman chain codes 
%   corresponding to allowed deltax, deltay pairs. An 8-chain is
%   converted to a 4-chain if (1) if conn = 4; and (2) only
%   transitions 0, 2, 4, and 6 occur in the 8-code.  Note that
%   dividing 0, 2, 4, and 6 by 2 produce the 4-code. 
%
%       -----------------------  ----------------
%       deltax | deltay | 8-code  corresp 4-code
%       -----------------------  ----------------
%         0        1       0            0
%        -1        1       1
%        -1        0       2            1
%        -1       -1       3
%         0       -1       4            2
%         1       -1       5
%         1        0       6            3
%         1        1       7
%       -----------------------  ----------------
%
%   The formula z = 4*(deltax + 2) + (deltay + 2) gives the following
%   sequence corresponding to rows 1-8 in the preceding table: z =
%   11,7,6,5,9,13,14,15. These values can be used as indices into the
%   table, improving the speed of computing the chain code. The
%   preceding formula is not unique, but it is based on the smallest
%   integers (4 and 2) that are powers of 2. 

%   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004
%   $Revision: 1.6 $  $Date: 2003/11/21 14:34:49 $

% Preliminaries.
if nargin == 1 
   dir = 'same'; 
   conn = 8;
elseif nargin == 2 
   dir = 'same';
elseif nargin == 3   
   % Nothing to do here.
else 
   error('Incorrect number of inputs.')
end
[np, nc] = size(b);
if np < nc 
   error('B must be of size np-by-2.'); 
end

% Some boundary tracing programs, such as boundaries.m, output a
% sequence in which the coordinates of the first and last points are
% the same. If this is the case, eliminate the last point. 
if isequal(b(1, :), b(np, :))
   np = np - 1;
   b = b(1:np, :);
end

% Build the code table using the single indices from the formula 
% for z given above:
C(11)=0; C(7)=1; C(6)=2; C(5)=3; C(9)=4;
C(13)=5; C(14)=6; C(15)=7;

% End of Preliminaries.

% Begin processing.
x0 = b(1, 1);
y0 = b(1, 2);
c.x0y0 = [x0, y0];

% Make sure the coordinates are organized sequentially:
% Get the deltax and deltay between successive points in b. The 
% last row of a is the first row of b.
a = circshift(b, [-1, 0]);

% DEL = a - b is an nr-by-2 matrix in which the rows contain the
% deltax and deltay between successive points in b. The two 
% components in the kth row of matrix DEL are deltax and deltay 
% between point (xk, yk) and (xk+1, yk+1).  The last row of DEL 
% contains the deltax and deltay between (xnr, ynr) and (x1, y1),
% (i.e., between the last and first points in b).
DEL = a - b;

% If the abs value of either (or both) components of a pair 
% (deltax, deltay) is greater than 1, then by definition the curve 
% is broken (or the points are out of order), and the program 
% terminates.
if any(abs(DEL(:, 1)) > 1) | any(abs(DEL(:, 2)) > 1);
   error('The input curve is broken or points are out of order.')
end

% Create a single index vector using the formula described above.
z = 4*(DEL(:, 1) + 2) + (DEL(:, 2) + 2);

% Use the index to map into the table. The following are
% the Freeman 8-chain codes, organized in a 1-by-np array.
fcc = C(z);

% Check if direction of code sequence needs to be reversed.
if strcmp(dir, 'reverse')
   fcc = coderev(fcc); % See below for function coderev.
end

% If 4-connectivity is specified, check that all components
% of fcc are 0, 2, 4, or 6.
if conn == 4
   val = find(fcc == 1 | fcc == 3 | fcc == 5 | fcc ==7 );
   if isempty(val)
      fcc = fcc./2;
   else
      warning('The specified 4-connected code cannot be satisfied.')
   end
end

% Freeman chain code for structure output.
c.fcc = fcc;

% Obtain the first difference of fcc.
c.diff = codediff(fcc,conn); % See below for function codediff.

% Obtain code of the integer of minimum magnitude.
c.mm = minmag(fcc); % See below for function minmag.

% Obtain the first
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 3

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.97 kB
0_Read_Me_First.txt5.00 kB2012-02-29|09:51
Contents.m5.98 kB2012-02-29|09:51
Readme.m5.30 kB2012-02-29|09:51
adpmedian.m1.54 kB2012-02-29|09:51
average.m651.00 B2012-02-29|09:51
bayesgauss.m2.96 kB2012-02-29|09:51
bound2eight.m2.99 kB2012-02-29|09:51
bound2four.m2.42 kB2012-02-29|09:51
bound2im.m2.17 kB2012-02-29|09:51
boundaries.m5.64 kB2012-02-29|09:51
bsubsamp.m3.87 kB2012-02-29|09:51
changeclass.m592.00 B2012-02-29|09:51
colorgrad.m2.30 kB2012-02-29|09:51
colorseg.m2.37 kB2012-02-29|09:51
compare.m1.15 kB2012-02-29|09:51
connectpoly.m1.02 kB2012-02-29|09:51
conwaylaws.m799.00 B2012-02-29|09:51
covmatrix.m977.00 B2012-02-29|09:51
dftcorr.m687.00 B2012-02-29|09:51
dftfilt.m882.00 B2012-02-29|09:51
dftuv.m736.00 B2012-02-29|09:51
diameter.m6.47 kB2012-02-29|09:51
endpoints.m874.00 B2012-02-29|09:51
entropy.m1.00 kB2012-02-29|09:51
fchcode.m8.55 kB2012-02-29|09:51
frdescp.m1.42 kB2012-02-29|09:51
fwtcompare.m992.00 B2012-02-29|09:51
gmean.m447.00 B2012-02-29|09:51
gscale.m2.04 kB2012-02-29|09:51
histroi.m920.00 B2012-02-29|09:51
hough.m2.64 kB2012-02-29|09:51
houghlines.m2.82 kB2012-02-29|09:51
houghpeaks.m2.65 kB2012-02-29|09:51
houghpixels.m1.02 kB2012-02-29|09:51
hpfilter.m1.23 kB2012-02-29|09:51
hsi2rgb.m1.94 kB2012-02-29|09:51
huff2mat.m2.46 kB2012-02-29|09:51
huffman.m2.82 kB2012-02-29|09:51
ice.fig45.71 kB2012-02-29|09:51
ice.m26.30 kB2012-02-29|09:51
ice_stand_alone.m46.55 kB2012-02-29|09:51
ifrdescp.m1.38 kB2012-02-29|09:51
ifwtcompare.m1.12 kB2012-02-29|09:51
im2jpeg.m2.90 kB2012-02-29|09:51
im2jpeg2k.m3.97 kB2012-02-29|09:51
imnoise2.m4.20 kB2012-02-29|09:51
imnoise3.m2.12 kB2012-02-29|09:51
improd.m791.00 B2012-02-29|09:51
imratio.m1.30 kB2012-02-29|09:51
imstack2vectors.m1.83 kB2012-02-29|09:51
intline.m1.20 kB2012-02-29|09:51
intrans.m3.25 kB2012-02-29|09:51
invmoments.m3.24 kB2012-02-29|09:51
jpeg2im.m2.41 kB2012-02-29|09:51
jpeg2k2im.m1.90 kB2012-02-29|09:51
lpc2mat.m1.42 kB2012-02-29|09:51
lpfilter.m1.44 kB2012-02-29|09:51
mahalanobis.m1.97 kB2012-02-29|09:51
manualhist.m1.75 kB2012-02-29|09:51
mat2huff.m2.75 kB2012-02-29|09:51
mat2lpc.m1.28 kB2012-02-29|09:51
minperpoly.m7.15 kB2012-02-29|09:51
paddedsize.m1.29 kB2012-02-29|09:51
pixeldup.m950.00 B2012-02-29|09:51
polyangles.m6.14 kB2012-02-29|09:51
princomp.m2.88 kB2012-02-29|09:51
quantize.m1.33 kB2012-02-29|09:51
randvertex.m1.15 kB2012-02-29|09:51
regiongrow.m1.66 kB2012-02-29|09:51
rgb2hsi.m1.46 kB2012-02-29|09:51
rgbcube.m1.98 kB2012-02-29|09:51
signature.m4.45 kB2012-02-29|09:51
specxture.m2.57 kB2012-02-29|09:51
spfilt.m3.78 kB2012-02-29|09:51
splitmerge.m4.13 kB2012-02-29|09:51
statmoments.m1.72 kB2012-02-29|09:51
statxture.m1.55 kB2012-02-29|09:51
strsimilarity.m1.78 kB2012-02-29|09:51
subim.m713.00 B2012-02-29|09:51
twodsin.m1.04 kB2012-02-29|09:51
twomodegauss.m1.16 kB2012-02-29|09:51
unravel.dll7.00 kB2012-02-29|09:51
unravel.m967.00 B2012-02-29|09:51
unravel.mexaxp24.00 kB2012-02-29|09:51
unravel.mexglx18.97 kB2012-02-29|09:51
unravel.mexhpux12.00 kB2012-02-29|09:51
unravel.mexmac8.68 kB2012-02-29|09:51
unravel.mexrs62.71 kB2012-02-29|09:51
unravel.mexsg24.44 kB2012-02-29|09:51
unravel.mexsol8.54 kB2012-02-29|09:51
vistformfwd.m1.66 kB2012-02-29|09:51
wave2gray.m4.67 kB2012-02-29|09:51
waveback.m4.52 kB2012-02-29|09:51
wavecopy.m940.00 B2012-02-29|09:51
wavecut.m1.06 kB2012-02-29|09:51
wavefast.m4.14 kB2012-02-29|09:51
wavefilter.m4.77 kB2012-02-29|09:51
wavepaste.m1.04 kB2012-02-29|09:51
wavework.m3.45 kB2012-02-29|09:51
wavezero.m696.00 B2012-02-29|09:51
x2majoraxis.m3.59 kB2012-02-29|09:51
...
Sponsored links

fchcode.m (160.12 kB)

Need 3 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D