source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/kovesi/canny.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1% CANNY - Canny edge detection
2%
3% Function to perform Canny edge detection. Code uses modifications as
4% suggested by Fleck (IEEE PAMI No. 3, Vol. 14. March 1992. pp 337-345)
5%
6% Usage: [gradient or] = canny(im, sigma)
7%
8% Arguments:   im    - image to be procesed
9%              sigma - standard deviation of Gaussian smoothing filter
10%                      (typically 1)
11%
12% Returns:     gradient - edge strength image (gradient amplitude)
13%              or       - orientation image (in degrees 0-180, positive
14%                         anti-clockwise)
15%
16% See also:  NONMAXSUP, HYSTHRESH
17
18% Copyright (c) 1999-2003 Peter Kovesi
19% School of Computer Science & Software Engineering
20% The University of Western Australia
21% http://www.csse.uwa.edu.au/
22%
23% Permission is hereby granted, free of charge, to any person obtaining a copy
24% of this software and associated documentation files (the "Software"), to deal
25% in the Software without restriction, subject to the following conditions:
26%
27% The above copyright notice and this permission notice shall be included in all
28% copies or substantial portions of the Software.
29%
30% The Software is provided "as is", without warranty of any kind.
31
32% April 1999    Original version
33% January 2003  Error in calculation of d2 corrected
34
35function [gradient, or] = canny(im, sigma)
36
37[rows, cols] = size(im);
38im = double(im);         % Ensure double
39
40hsize = [6*sigma+1, 6*sigma+1];   % The filter size.
41
42gaussian = fspecial('gaussian',hsize,sigma);
43im = filter2(gaussian,im);        % Smoothed image.
44
45h =  [  im(:,2:cols)  zeros(rows,1) ] - [  zeros(rows,1)  im(:,1:cols-1)  ];
46v =  [  im(2:rows,:); zeros(1,cols) ] - [  zeros(1,cols); im(1:rows-1,:)  ];
47d1 = [  im(2:rows,2:cols) zeros(rows-1,1); zeros(1,cols) ] - ...
48                               [ zeros(1,cols); zeros(rows-1,1) im(1:rows-1,1:cols-1)  ];
49d2 = [  zeros(1,cols); im(1:rows-1,2:cols) zeros(rows-1,1);  ] - ...
50                               [ zeros(rows-1,1) im(2:rows,1:cols-1); zeros(1,cols)   ];
51
52X = h + (d1 + d2)/2.0;
53Y = v + (d1 - d2)/2.0;
54
55gradient = sqrt(X.*X + Y.*Y); % Gradient amplitude.
56
57or = atan2(-Y, X);            % Angles -pi to + pi.
58neg = or<0;                   % Map angles to 0-pi.
59or = or.*~neg + (or+pi).*neg;
60or = or*180/pi;               % Convert to degrees.
Note: See TracBrowser for help on using the repository browser.