Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CannyEdge.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __CANNYEDGE_HH_
26 #define __CANNYEDGE_HH_
27 
28 #include "FilterBase.hh"
29 #include "Convolution.hh"
30 #include "Gauss.hh"
31 
32 namespace BIAS {
33  /** @class CannyEdge
34  @ingroup g_filter
35  @brief Canny edge detector
36 
37  uses gradient calculation on upsampled images<br>
38  Low and High thresholds for hysteresis can either be set manually or be determined by histogram segmentation.<br />
39  For the latter, use SetThresholdsRelative(low, high) to set the number of pixels in percent in the magnitude image to not<br />
40  be evaluated by hysteresis. Per default, the lowest 60 percent of all pixels define the lower threshold and the upper 10 percent<br />
41  of all pixels define the higher threshold.<br>
42  Implementation follows the online tutorial of http://www.pages.drexel.edu/~weg22/can_tut.html closely.
43  <br /><br />
44  Only tested for InputStorageType unsigned char, OutputStorageType float!
45 
46  @author fkellner 11/2008 */
47  template <class InputStorageType, class OutputStorageType>
48  class BIASFilter_EXPORT CannyEdge: public FilterBase<InputStorageType, OutputStorageType> {
49  public:
50 
51  /// @brief Constructor, setting default values
52  CannyEdge();
53 
54  virtual ~CannyEdge();
55 
56  /// @brief call for getting all intermediary results
57  virtual int Filter(const Image<InputStorageType>& src,
60  Image<OutputStorageType>& magnitude,
63 
64  /// @brief call for only getting the (binary) edge image
65  virtual int Filter(const Image<InputStorageType>& src,
67 
68  /// @brief get copy of this filter
71 
72  /// @brief not implemented
73  virtual void GetBordersValid_(int &border_x, int &border_y) const;
74 
75  /// @brief before edge detection, the input image is blurred with a gaussian. Set sigma here (defaults to 1.4)
76  int SetGaussSigma(float sigma);
77 
78  /// @brief set absolute value of low and high thresholds for hysteresis in magnitude gradient image
79  int SetThresholdsAbsolute(OutputStorageType lowAbs_, OutputStorageType highAbs_);
80 
81  /// @brief set value of low and high thresholds for hysteresis in magnitude gradient image in terms of percent of image pixels
82  int SetThresholdsRelative(unsigned int low_, unsigned int high_);
83 
84  /** @brief set edge width for hysteresis.
85  * In the hysteresis step, we walk along the detected edge pixels and look at the neighboring pixels in gradient direction to
86  * determine a pixel best suiting the edge (in terms of highest magnitude). edgeWidth defines the pixel offset to the neighbor
87  * pixels, so that the default value of 1 will result in a result image with one pixel wide edges. A value of 3 will result in
88  * a thicker edge, but might give more connectivity along the edges.
89  */
90  int SetEdgeWidth(unsigned int edgeWidth);
91 
92  protected:
93 
94  int SmoothImage_(const Image<InputStorageType>& src,
95  Image<OutputStorageType>& smoothed);
96 
97  int CalculateGradients_(const Image<OutputStorageType>& src,
100  Image<OutputStorageType>& magnitude,
103 
104  // gradient x direction filter
106  // gradient y direction filter
108 
109  // determine thresholds from given pixel percentage values low and high.
110  int DetermineThresholds_(const Image<OutputStorageType> &src, OutputStorageType &low, OutputStorageType &high);
111 
112  private:
114 
115  float gsigma_;
116 
117  unsigned int w_, h_;
118 
119  unsigned int thresLow_, thresHigh_;
120  OutputStorageType thresLowAbs_, thresHighAbs_;
121  bool useAbsThresholds_;
122 
123  unsigned int edgeWidth_;
124  };
125 
126 }
127 
128 #endif /* CANNYEDGE_HH_ */
virtual CannyEdge< InputStorageType, OutputStorageType > * Clone() const
get copy of this filter
Definition: CannyEdge.hh:69
virtual parent class for API definition of all (future) filters
Definition: FilterBase.hh:77
Convolution< OutputStorageType, OutputStorageType > ConvY_
Definition: CannyEdge.hh:107
Convolution< OutputStorageType, OutputStorageType > ConvX_
Definition: CannyEdge.hh:105
smoothing with gaussian kernel
Definition: Gauss.hh:51
Canny edge detector.
Definition: CannyEdge.hh:48