JG ROOT Tools libraries  version 5.0 - august 2014
RHoughTransform.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file RHoughTransform.hh
3  *
4  * Include file for the class RHoughTransform
5  */
6 //======================================================================
7 
8 #ifndef R_HOUGH_TRANSFORM_HH
9 #define R_HOUGH_TRANSFORM_HH
10 
11 //======================================================================
12 
13 // GRootTools includes
14 #include "RBaseFunctions.hh"
15 
16 // ROOT includes
17 #include "TH2.h"
18 #include "TPoint.h"
19 #include "TMath.h"
20 #include "TLine.h"
21 
22 
23 //======================================================================
24 /*! \class RHoughTransform
25  *
26  * This class performs Hough transform analysis of the image given
27  * by a 2D histogram.
28  *
29  * The Hough transform is used to search for lines in an image.
30  *
31  * It is supposed to work on points cloud;
32  * here, the analysis is done by weighting the contribution of
33  * each pixel with the histogram content.
34  * The X and Y dimensions of the image histogram should be in the
35  * dimension units.
36  *
37  * The source image histogram is defined by a pointer to an histogram
38  * that is defined outside the RHoughTransform object.
39  *
40  */
42 {
43  //------------------------------------------------------------
44  /*! \object_doc{RHoughTransform} */
46  //------------------------------------------------------------
47 
48  /*! Option for reference point at the center of the image histogram*/
49  static const u_int optCenter = 0x00000001;
50 
51  /*! Option for threshold on histogram amplitude for contributing to the analysis*/
52  static const u_int optThreshold = 0x00000002;
53 
54  /*! Option for amplitude as weight of histogram point*/
55  static const u_int optAmplitude = 0x00000004;
56 
57  /*! Option for smoothing the Hough transform histogram*/
58  static const u_int optSmooth = 0x00000008;
59 
60  /*! Mode for line suppression: sharp cut*/
61  static const u_short modeCut = 0x0000;
62 
63  /*! Mode for line suppression: gauss shape reduction*/
64  static const u_short modeGaus = 0x0001;
65 
66 
67  protected:
68  TH2 * src_histo; ///< Pointer to the histogram to analyse
69  TPoint src_center; ///< Image histogram center
70  double threshold; ///< Threshold value
71 
72  TH2 * hough_histo; ///< Pointer to the Hough transform histogram
73  string hough_id; ///< Name for the transform (histogram name)
74 
75  TAttLine line_att; ///< Lines draw attributes (ROOT)
76 
77  u_int options; ///< Transform options
78 
79  u_short suppress_mode; ///< Mode for line suppression
80  double suppress_width; ///< Line width for suppression
81 
82  public:
83 
84  //------------------------------------------------------------
85  /** @name Constructors, affectation, destructor */
86  //@{
87  RHoughTransform ( TH2 * hptr = NULL,
88  u_int nth = 0, u_int nr = 0, double rmax = 0.,
89  double thr = 0., const string & id = "" );
90  virtual ~RHoughTransform ( );
91  //@}
92 
93  //------------------------------------------------------------
94  /** @name Transform analysis options */
95  //@{
96  u_int GetOptions ( ) const; // inline
97  bool GetOptionCenterRef ( ) const; // inline
98  bool GetOptionCornerRef ( ) const; // inline
99  bool GetOptionThreshold ( ) const; // inline
100  bool GetOptionAmplWeight ( ) const; // inline
101  bool GetOptionThresholdAmplWeight ( ) const; // inline
102  bool GetOptionSmooth ( ) const; // inline
103 
104  virtual void SetOptionCenterRef ( );
105  virtual void SetOptionCornerRef ( );
106 
107  virtual void SetOptionAmplWeight ( bool thr = false );
108  virtual void SetOptionUnitWeight ( );
109 
110  virtual void SetOptionSmooth ( ); // inline
111  virtual void SetOptionNoSmooth ( ); // inline
112  //@}
113 
114  //------------------------------------------------------------
115  /** @name Transform analysis functions */
116  //@{
117  TH2 * GetSourceHisto ( ) const; // inline
118  const TH2 * GetHoughHisto ( ) const; // inline
119  TH2 * GetHoughHisto ( ); // inline
120  TH2 * GetWeightHisto ( const string & hname = "" ) const;
121 
122 
123  const TPoint & GetSourceCenter ( ) const; // inline
124  TPoint & GetSourceCenter ( ); // inline
125 
126  virtual int SetSourceHisto ( TH2 * hptr, double thr = 0. );
127  virtual void SetThreshold ( double thr ); // inline
128 
129  virtual void ResetTransform ( );
130  virtual TH2 * SetTransform ( u_int nth, u_int nr, double rmax, const string & id = "", bool calc = false );
131  virtual int ComputeTransform ( );
132  virtual double GetWeight ( double pval ) const;
133 
134  double GetHoughMaximum ( double & theta, double & dist ) const;
135  virtual void SuppressSourceLine ( double theta, double dist, double width,
136  u_short mode = modeCut, u_short sdiv = 1 );
137 
138  virtual void SetSuppressMode ( u_short mode, double width ); // inline
139  virtual u_int SearchLineSuppress ( double hthr, u_int nlmax = 1,
140  double * thtab = NULL, double * rtab = NULL, double * htab = NULL,
141  u_short sdiv = 1 );
142  //@}
143 
144  //------------------------------------------------------------
145  /** @name ROOT related functions */
146  //@{
147  virtual void SetLineColor ( Color_t c ); // inline
148  virtual void SetLineWidth ( Width_t w ); // inline
149  virtual void SetLineStyle ( Style_t s ); // inline
150  virtual void SetLineAtt ( TAttLine & att ); // inline
151 
152  const TAttLine & GetLineAtt ( ) const; // inline
153  TAttLine & GetLineAtt ( ); // inline
154 
155  TLine * CreateLine ( ) const;
156  TLine * CreateLine ( double theta, double dist ) const;
157  TLine * CreateNormal ( ) const;
158  TLine * CreateNormal ( double theta, double dist ) const;
159 
160  /*! For ROOT dictionary.*/
162  //@}
163 };
164 
165 //----------------------------------------------------------------------
166 // Inline functions
167 #include "icc/RHoughTransform.icc"
168 
169 
170 //======================================================================
171 
172 #endif
const TAttLine & GetLineAtt() const
Definition: RHoughTransform.icc:115
bool GetOptionCornerRef() const
Definition: RHoughTransform.icc:19
virtual int SetSourceHisto(TH2 *hptr, double thr=0.)
Definition: RHoughTransform.cpp:168
static const u_int optSmooth
Definition: RHoughTransform.hh:58
bool GetOptionCenterRef() const
Definition: RHoughTransform.icc:15
double suppress_width
Line width for suppression.
Definition: RHoughTransform.hh:80
bool GetOptionThresholdAmplWeight() const
Definition: RHoughTransform.icc:32
bool GetOptionAmplWeight() const
Definition: RHoughTransform.icc:27
u_int options
Transform options.
Definition: RHoughTransform.hh:77
virtual void SetOptionNoSmooth()
Definition: RHoughTransform.icc:45
TH2 * src_histo
Pointer to the histogram to analyse.
Definition: RHoughTransform.hh:68
static const u_int optAmplitude
Definition: RHoughTransform.hh:55
static const u_int optThreshold
Definition: RHoughTransform.hh:52
bool GetOptionSmooth() const
Definition: RHoughTransform.icc:36
virtual void SetLineColor(Color_t c)
Definition: RHoughTransform.icc:93
TH2 * GetWeightHisto(const string &hname="") const
Definition: RHoughTransform.cpp:120
virtual ~RHoughTransform()
Definition: RHoughTransform.cpp:48
TLine * CreateLine() const
Definition: RHoughTransform.cpp:550
virtual TH2 * SetTransform(u_int nth, u_int nr, double rmax, const string &id="", bool calc=false)
Definition: RHoughTransform.cpp:206
const TH2 * GetHoughHisto() const
Definition: RHoughTransform.icc:55
virtual void SetOptionCenterRef()
Definition: RHoughTransform.cpp:62
double threshold
Threshold value.
Definition: RHoughTransform.hh:70
virtual void SetOptionUnitWeight()
Definition: RHoughTransform.cpp:108
double GetHoughMaximum(double &theta, double &dist) const
Definition: RHoughTransform.cpp:365
virtual u_int SearchLineSuppress(double hthr, u_int nlmax=1, double *thtab=NULL, double *rtab=NULL, double *htab=NULL, u_short sdiv=1)
Definition: RHoughTransform.cpp:494
static const u_short modeCut
Definition: RHoughTransform.hh:61
virtual void SuppressSourceLine(double theta, double dist, double width, u_short mode=modeCut, u_short sdiv=1)
Definition: RHoughTransform.cpp:397
TPoint src_center
Image histogram center.
Definition: RHoughTransform.hh:69
virtual void ResetTransform()
Definition: RHoughTransform.cpp:155
TH2 * hough_histo
Pointer to the Hough transform histogram.
Definition: RHoughTransform.hh:72
virtual void SetOptionAmplWeight(bool thr=false)
Definition: RHoughTransform.cpp:92
bool GetOptionThreshold() const
Definition: RHoughTransform.icc:23
string hough_id
Name for the transform (histogram name)
Definition: RHoughTransform.hh:73
TLine * CreateNormal() const
Definition: RHoughTransform.cpp:624
TH2 * GetSourceHisto() const
Definition: RHoughTransform.icc:51
virtual void SetSuppressMode(u_short mode, double width)
Definition: RHoughTransform.icc:85
virtual void SetLineStyle(Style_t s)
Definition: RHoughTransform.icc:105
virtual void SetThreshold(double thr)
Definition: RHoughTransform.icc:75
virtual void SetLineAtt(TAttLine &att)
Definition: RHoughTransform.icc:111
u_short suppress_mode
Mode for line suppression.
Definition: RHoughTransform.hh:79
ClassDef(RHoughTransform, 0)
GObject(RHoughTransform)
virtual void SetOptionCornerRef()
Definition: RHoughTransform.cpp:76
virtual double GetWeight(double pval) const
Definition: RHoughTransform.cpp:341
virtual void SetLineWidth(Width_t w)
Definition: RHoughTransform.icc:99
static const u_int optCenter
Definition: RHoughTransform.hh:49
Definition: RHoughTransform.hh:41
static const u_short modeGaus
Definition: RHoughTransform.hh:64
u_int GetOptions() const
Definition: RHoughTransform.icc:11
virtual int ComputeTransform()
Definition: RHoughTransform.cpp:269
virtual void SetOptionSmooth()
Definition: RHoughTransform.icc:41
TAttLine line_att
Lines draw attributes (ROOT)
Definition: RHoughTransform.hh:75
RHoughTransform(TH2 *hptr=NULL, u_int nth=0, u_int nr=0, double rmax=0., double thr=0., const string &id="")
Definition: RHoughTransform.cpp:24
const TPoint & GetSourceCenter() const
Definition: RHoughTransform.icc:63