Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ContourDetectorBSpline.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 __CONTOURDETECTORBSPLINE_HH_
26 #define __CONTOURDETECTORBSPLINE_HH_
27 
28 
29 #include <cstring>
30 #include <cmath>
31 #include <vector>
32 
33 #include <Base/Debug/Debug.hh>
34 #include <Base/Math/Vector.hh>
35 #include <Base/Math/Vector2.hh>
36 #include <Base/Image/Image.hh>
37 
38 #include "ContourBSplineData.hh"
39 #include "ContourBSplineShapeMatrix.hh"
40 #include "ContourBSplineType.hh"
41 #include "ContourDetectorBase.hh"
42 
43 
44 #define D_CONTOURBSPLINE_DEBUG 1<<0
45 #define D_CONTOURBSPLINE_INIT 1<<1
46 #define D_CONTOURBSPLINE_INITFIT 1<<2
47 #define D_CONTOURBSPLINE_FIT 1<<3
48 #define D_CONTOURBSPLINE_BOUNDINGBOX 1<<4
49 
50 namespace BIAS{
51  /**
52  @class ContourDetectorBSpline
53  @brief represents a special B-Spline and holds functions to handle
54  fitting
55 
56 
57  This class represents a special B-Spline curve for "Active Contours".
58  Based on book: "Active Contours" by Andrew Blake and Michael Isard.
59  (http://www.robots.ox.ac.uk/~contours/)
60 
61  Class offers functions to manipulate Position, Orientation and Scale of
62  Curve, Drawing and Fitting Curve to gradient features in images.
63 
64 
65 
66  USAGE construction:
67  ContourBSpline bspline; //call constructor
68  bspline.Init(...); //initialise B-Spline
69 
70  The call of the Init(...) function looksup if the basis of the B-Spline
71  is already computed. If not, a new ContourBSplineData Objects becomes
72  generated, which holds data of this Object. If a B-Spline with same
73  basis is available the pointer to the available ContourBSplineData gets
74  copied. The purpose is to save/share memory.
75  This is hidden to users of this class.
76  After the Init(..) call, you can draw and manipulate
77  the B-Spline.
78 
79 
80 
81  For fitting you have to set (nonrecurring) Shape-Space,
82  invariant Shape-Space (SubShapeSpace) and compute the
83  Regularisation-Matrix. Look at "Active Contours" chapter 6 for details.
84  In common cases you want to set Shape-Space to identity
85  (SetShapeSpaceIdentity()) and invariant Shape-Space to planar affin
86  transformations (SetSubShapeSpacePlanarAffin()).
87 
88  USAGE fitting:
89  bspline.SetShapeSpace...(...);
90  bspline.SetSubShapeSpace...(...);
91  bspline.ComputeRegularisationMatrix();
92  bspline.Fit(...);
93 
94  The functions Set*ShapeSpace...(...) and ComputeRegulatisationMatrix()
95  register/generate a ContourBSplineShapeMatrix object.
96  The purpose is to save/share memory. This should be
97  transparent to users of this class.
98 
99  @ingroup g_feature
100  @author Marcel Lilienthal, 2005
101  */
102  template <class StorageType>
103  class BIASFeatureDetector_EXPORT ContourDetectorBSpline :
104  ContourDetectorBase<StorageType>
105  {
106  public:
107 
108  /**
109  * @brief standard constructor
110  *
111  * Sets pointers to NULL and initialises some default values for Drawing
112  * and Fitting.
113  */
115 
116  /**
117  * @brief copy constructor
118  * @param[in] toCopy object to copy
119  *
120  * Uses operator= to copy referred B-Spline as new Object.
121  *
122  */
124  operator=(toCopy);
125  }
126 
127  /**
128  * @brief destructor
129  *
130  * Unregisters ContourBSplineData object (with reference counting).
131  * Unregisters ContourBSplineShapeMatrix objects (with reference
132  * counting).
133  *
134  */
135  virtual ~ContourDetectorBSpline();
136 
137  /**
138  * @brief detect function, unfinished
139  *
140  */
141  int Detect(Image<StorageType>& image,
142  std::vector<BIAS::BIASContour>& contour);
143 
144  /**
145  * @brief builds a new ContourBspline object from given vector of
146  * ContourBSpline objects
147  * @param[in] bSplines vector of ContourBSpline objects to cluster
148  *
149  * With this function you can cluster B-Spline curves in one B-Spline
150  * curve. For example you can represent the contour of glasses with one
151  * B-Spline curve constructed of two closed B-Spline curves.
152  *
153  */
154  static ContourDetectorBSpline
155  Cluster(const std::vector<ContourDetectorBSpline<StorageType> >& bSplines);
156 
157 
158  /**
159  * @brief copy operator
160  * @param[in] toCopy object to copy
161  */
162  inline ContourDetectorBSpline& operator=
163  (const ContourDetectorBSpline<StorageType> &toCopy);
164 
165  /**
166  * @brief initialisation function for simple curve without edges
167  * @param[in] order order of B-Spline curve (implies degree)
168  * @param[in] bType type of curve: Open or Closed
169  * @param[in] cPnts control points of curve with x,y-coordinates
170  *
171  * Generates/registers basis for B-Spline curve without edges
172  * transparently.
173  *
174  * Example:
175  * bspline.Init(order,BIAS::ContourBSplineType::Open,cPnts);
176  */
177  void Init(const unsigned int order,
178  const ContourBSplineType::Type bType,
179  const std::vector<BIAS::Vector2<double> > &cPnts);
180 
181  /**
182  * @brief initialisation function for curve with edges
183  * @param[in] order order of B-Spline curve (implies degree)
184  * @param[in] bType type of curve: Open or Closed
185  * @param[in] mPnts multiplicity of control points
186  * @param[in] cPnts control points of curve with x,y-coordinates
187  *
188  * Generates/registers basis for B-Spline curve with edges
189  * transparently.
190  *
191  **
192  *
193  * Param vector mPnts must have same length as vector of
194  * control points. A multiplicity of "order-1" at index "i" implies an
195  * edge in the curve at control point with index "i".
196  *
197  * If type of the curve is "Open" the first control point with an edge
198  * is only possible at index "order-1" (begin counting with zero).
199  * Last possible control point with an edge is "last index - (order-1)".
200  * Edges in control points must have distance in indices of "order-1".
201  * Example: If order==3 (quadratic B-Spline) and there is an edge in
202  * control point with index 2 (mPnts[2]=2) then the next possible edge
203  * is in control point with index 4 (mPnts[4]=2).
204  *
205  * If type of curve is "Closed" the indicies of control points with edges
206  * must have periodic distance of "order-1".
207  * Exampe: If order==3 (quadratic B-Spline) and there is an edge in
208  * control point with index 0 (mPnts[0]=2) then the next possible edge
209  * is in control point with index 2 (mPnts[2]=2). Periodic distance means
210  * that the last possible edge is at index "last index - 1" in this case.
211  *
212  */
213  void Init(const unsigned int order,
214  const ContourBSplineType::Type bType,
215  const std::vector<unsigned int> &mPnts,
216  const std::vector<BIAS::Vector2<double> > &cPnts);
217 
218  /**
219  * @brief initialisation function for simple curve without edges
220  * @param[in] order order of B-Spline curve (implies degree)
221  * @param[in] bType type of curve: Open or Closed
222  * @param[in] Q control points of curve first all x-coordinates then all
223  * y-coordinates (adopted from book "Active Contours")
224  * Q= (x) - vector of x-coordinates
225  * (y) - vector of y-coordinates
226  *
227  * Generates/registers basis for B-Spline curve without edges
228  * transparently.
229  *
230  */
231  void Init(const unsigned int order,
232  const ContourBSplineType::Type bType,
233  const BIAS::Vector<double>& Q);
234 
235  /**
236  * @brief initialisation function for curve with edges
237  * @param[in] order order of B-Spline curve (implies degree)
238  * @param[in] bType type of curve: Open or Closed
239  * @param[in] mPnts multiplicity of control points
240  * @param[in] Q control points of curve first all x-coordinates then all
241  * y-coordinates (adopted from book "Active Contours")
242  * Q= (x) - vector of x-coordinates
243  * (y) - vector of y-coordinates
244  *
245  * Generates/registers basis for B-Spline curve with edges
246  * transparently.
247  *
248  **
249  *
250  * Param vector mPnts must have same length as vector of
251  * control points. A multiplicity of "order-1" at index "i" implies an
252  * edge in the curve at control point with index "i".
253  *
254  * If type of the curve is "Open" the first control point with an edge
255  * is only possible at index "order-1" (begin counting with zero).
256  * Last possible control point with an edge is "last index - (order-1)".
257  * Edges in control points must have distance in indices of "order-1".
258  * Example: If order==3 (quadratic B-Spline) and there is an edge in
259  * control point with index 2 (mPnts[2]=2) then the next possible edge
260  * is in control point with index 4 (mPnts[4]=2).
261  *
262  * If type of curve is "Closed" the indicies of control points with edges
263  * must have periodic distance of "order-1".
264  * Exampe: If order==3 (quadratic B-Spline) and there is an edge in
265  * control point with index 0 (mPnts[0]=2) then the next possible edge
266  * is in control point with index 2 (mPnts[2]=2). Periodic distance means
267  * that the last possible edge is at index "last index - 1" in this case.
268  *
269  */
270  void Init(const unsigned int order,
271  const ContourBSplineType::Type bType,
272  const std::vector<unsigned int>& mPnts,
273  const BIAS::Vector<double>& Q);
274 
275  /**
276  * @brief fits B-Spline curve to gradient features found in the image
277  * @param[in] greyImg input image
278  * @param[in] alpha regularisation factor for fitting
279  * @param[in] normalWidth width of normal for searching gradient features
280  *
281  * The input image gets converted to a single gradient image. A ROI gets
282  * computed from controlpoints and the width to search for features
283  * (normalWidth).
284  *
285  * Along the curve normals get computed. Number of normals depends
286  * on variable fitSampleWidth_ (SetFitSampleWidth(...)).
287  * Along the normals the feature points get assigned by the image
288  * points width highest gradient and distance less then normalWidth
289  * from curve (in both directions). Thus a feature curve is given.
290  *
291  * The fitting algorithm is described in the book "Active Contours",
292  * chapter 6. The parameter alpha determines the regularisation of the
293  * fitting. For numeric stability alpha has to be greater than 0 even if
294  * no regularisation is forced. the regularisation determines how the
295  * curve should be fitted to the feature curve. high values of alpha
296  * cause the fitted curve to keep the ground shape and only adapt
297  * position, orientation and scale. small values causes a possibly
298  * distorted shape which could have nothing in common with the initial
299  * curve.
300  *
301  */
302  void Fit(BIAS::Image<StorageType>& greyImg, const double& alpha,
303  const unsigned int normalWidth);
304 
305  /**
306  * @brief fits B-Spline curve to gradient features found in the image
307  * @param[in] greyImg input image
308  * @param[in] alpha regularisation factor for fitting
309  * @param[in] normalWidth width of normal for searching gradient features
310  * @param[in] minClip value of image gradients which are discarded in
311  * the search after feature points
312  *
313  * The input image gets converted to a single gradient image. A ROI gets
314  * computed from controlpoints and the width to search for features
315  * (normalWidth).
316  *
317  * Along the curve normals get computed. Number of normals depends
318  * on variable fitSampleWidth_ (SetFitSampleWidth(...)).
319  * Along the normals the feature points get assigned by the image
320  * points width highest gradient and distance less then normalWidth
321  * from curve (in both directions). Image gradients with a value less
322  * than parameter minClip are discarded.
323  * Thus a feature curve is given.
324  *
325  * The fitting algorithm is described in the book "Active Contours",
326  * chapter 6. The parameter alpha determines the regularisation of the
327  * fitting. For numeric stability alpha has to be greater than 0 even if
328  * no regularisation is forced. the regularisation determines how the
329  * curve should be fitted to the feature curve. high values of alpha
330  * cause the fitted curve to keep the ground shape and only adapt
331  * position, orientation and scale. small values causes a possibly
332  * distorted shape which could have nothing in common with the initial
333  * curve.
334  *
335  */
336  void Fit(BIAS::Image<StorageType>& greyImg, const double& alpha,
337  const unsigned int normalWidth, const double& minClip);
338 
339  /**
340  * @brief fits B-Spline curve to gradient features found in the image
341  * @param[in] featImg input gradient image
342  * @param[in] alpha regularisation factor for fitting
343  * @param[in] normalWidth width of normal for searching gradient features
344  *
345  * Along the curve normals get computed. Number of normals depends
346  * on variable fitSampleWidth_ (SetFitSampleWidth(...)).
347  * Along the normals the feature points get assigned by the image
348  * points width highest gradient and distance less then normalWidth
349  * from curve (in both directions). Thus a feature curve is given.
350  *
351  * The fitting algorithm is described in the book "Active Contours",
352  * chapter 6. The parameter alpha determines the regularisation of the
353  * fitting. For numeric stability alpha has to be greater than 0 even if
354  * no regularisation is forced. the regularisation determines how the
355  * curve should be fitted to the feature curve. high values of alpha
356  * cause the fitted curve to keep the ground shape and only adapt
357  * position, orientation and scale. small values causes a possibly
358  * distorted shape which could have nothing in common with the initial
359  * curve.
360  *
361  */
362  void Fit(const BIAS::Image<float>& featImg, const double& alpha,
363  const unsigned int normalWidth);
364 
365  /**
366  * @brief fits B-Spline curve to gradient features found in the image
367  * @param[in] featImg input gradient image
368  * @param[in] alpha regularisation factor for fitting
369  * @param[in] normalWidth width of normal for searching gradient features
370  * @param[in] minClip value of image gradients which are discarded in
371  * the search after feature points
372  *
373  * Along the curve normals get computed. Number of normals depends
374  * on variable fitSampleWidth_ (SetFitSampleWidth(...)).
375  * Along the normals the feature points get assigned by the image
376  * points width highest gradient and distance less then normalWidth
377  * from curve (in both directions). Image gradients with a value less
378  * than parameter minClip are discarded.
379  * Thus a feature curve is given.
380  *
381  * The fitting algorithm is described in the book "Active Contours",
382  * chapter 6. The parameter alpha determines the regularisation of the
383  * fitting. For numeric stability alpha has to be greater than 0 even if
384  * no regularisation is forced. the regularisation determines how the
385  * curve should be fitted to the feature curve. high values of alpha
386  * cause the fitted curve to keep the ground shape and only adapt
387  * position, orientation and scale. small values causes a possibly
388  * distorted shape which could have nothing in common with the initial
389  * curve.
390  *
391  */
392  void Fit(const BIAS::Image<float>& featImg, const double& alpha,
393  const unsigned int normalWidth, const double& minClip);
394 
395  /**
396  * @brief saves all values which are needed to reinitialise the object
397  * to a binary file
398  * @param[in] filename name of destination file
399  */
400  bool Save(const std::string& filename);
401 
402  /**
403  * @brief load/initialise a ContourBSpline object from an given binary
404  * file
405  * @param[in] filename name of source file
406  */
407  bool Load(const std::string& filename);
408 
409  //setter
410 
411  /**
412  * @brief sets new control points
413  * @param[in] controlPoints vector of control points with x,y-coordinates
414  */
415  inline void SetControlPoints(
416  const std::vector<BIAS::Vector2<double> >& controlPoints);
417 
418  /**
419  * @brief sets new control points
420  * @param[in] Q vector of control points consisting of vector of
421  * x-coordinates and of vector of y-coordinates
422  * Q= (x) vector of x-coordinates
423  * (y) vector of y-coordinates
424  */
425  inline void SetControlPoints(const BIAS::Vector<double>& Q);
426 
427  /**
428  * @brief displace all control points
429  * @param[in] x x-offset to x-coordinates of control points
430  * @param[in] y y-offset to y-coordinates of control points
431  */
432  inline void Displace(const double& x, const double&y);
433 
434  /**
435  * @brief scales curve isotropic
436  * @param[in] scale scaling factor
437  *
438  * Scales the curve by factor "scale". Curve must have its origin at
439  * zero! There is no test!
440  */
441  inline void Scale(const double& scale);
442 
443  /**
444  * @brief scales curve in x-direction (horizontally)
445  * @param[in] scale scaling factor
446  *
447  * Scales the curve by factor "scale" horizontally. Curve must have
448  * its origin at zero! There is no test!
449  */
450  inline void ScaleX(const double& scale);
451 
452  /**
453  * @brief scales curve in y-direction (vertically)
454  * @param[in] scale scaling factor
455  *
456  * Scales the curve by factor "scale" vertically. Curve must have
457  * its origin at zero! There is no test!
458  */
459  inline void ScaleY(const double& scale);
460 
461  /**
462  * @brief rotates curve by angle (rad)
463  * @param[in] angle rotation angle
464  *
465  * Rotates curve by angle. Curve must have its origin at zero! There is
466  * no test!
467  */
468  void Rotate(const double& angle);
469 
470  /**
471  * @brief centers the curve by computing center over control points
472  * (not accurate!)
473  */
474  inline void CenterOverControlPoints();
475 
476  /**
477  * @brief sets spape-space for regularised fitting
478  * @param[in] shapeSpace matrix of shape-space
479  *
480  * Read book "Active Contours" chapter 6 for details.
481  */
482  inline void SetShapeSpaceMatrix(BIAS::Matrix<double>& shapeSpace);
483 
484  /**
485  * @brief sets spape-space for regularised fitting to identity
486  *
487  * Read book "Active Contours" chapter 6 for details.
488  * If youre not sure which shape-space to set... set this.
489  */
490  inline void SetShapeSpaceIdentity();
491 
492  /**
493  * @brief sets spape-space for regularised fitting to euclidian
494  * similarities
495  *
496  * Read book "Active Contours" chapter 6 for details.
497  */
498  inline void SetShapeSpaceEuclidian();
499 
500  /**
501  * @brief sets spape-space for regularised fitting to planar affine
502  * transformations
503  *
504  * Read book "Active Contours" chapter 6 for details.
505  */
506  inline void SetShapeSpacePlanarAffin();
507 
508  /**
509  * @brief set invariant shape-space for regularised fitting
510  * @param[in] subShapeSpace matrix of invariant shape-space
511  *
512  * Read book "Active Contours" chapter 6 for details.
513  */
514  inline void SetSubShapeSpaceMatrix(BIAS::Matrix<double>& subShapeSpace);
515 
516  /**
517  * @brief set invariant shape-space for regularised fitting to identity
518  *
519  * Read book "Active Contours" chapter 6 for details.
520  */
521  inline void SetSubShapeSpaceIdentity();
522 
523  /**
524  * @brief set invariant shape-space for regularised fitting to euclidian
525  * similarities
526  *
527  * Read book "Active Contours" chapter 6 for details.
528  */
529  inline void SetSubShapeSpaceEuclidian();
530 
531  /**
532  * @brief set invariant shape-space for regularised fitting to planar
533  * affine transformation
534  *
535  * Read book "Active Contours" chapter 6 for details.
536  */
537  inline void SetSubShapeSpacePlanarAffin();
538 
539  /**
540  * @brief set invariant shape-space for regularised fitting to zero
541  *
542  * If you set invariant shape-space matrix to zero, you have to set
543  * the normal shape-space before (SetShapeSpace...(...))!
544  *
545  * Read book "Active Contours" chapter 6 for details.
546  */
547  inline void SetSubShapeSpaceZero();
548 
549  /**
550  * @brief computes the regularisation matrix needed for fitting
551  * algorithm.
552  *
553  * The regularisation matrix for the fitting algorithm gets computed.
554  * You have to set shape-space and invariant shape-space before!
555  * Different to the book "Active Contours" the regularisation factor
556  * alpha isnt included in the resulting matrix.
557  *
558  **
559  *
560  * Usage:
561  * bspline.SetShapeSpace...(...);
562  * bspline.SetSubShapeSpace...(...);
563  * bspline.ComputeRegularisationMatrix();
564  *
565  */
566  inline void ComputeRegularisationMatrix();
567 
568  /**
569  * @brief sets the amount of samples used to search
570  * features along the curve in fitting algorithm.
571  * @param[in] width distance of sample points along the curve (<1.0)
572  *
573  * Computes the amount of samples which are used to search features
574  * along the curve in the fitting algorithm. These sample points have
575  * distance "width". "width" should be considerably <1.0.
576  * the sample width is equidistant in sampling the basis of the curve,
577  * but not in sampling the curve points!
578  *
579  */
580  inline void SetFitSampleWidth(double width);
581 
582  /**
583  * @brief sets the amount of samples used to search features along the
584  * curve in fitting algorithm.
585  * @param[in] samples amount of samples used to search features
586  *
587  * Sets amount of samples which are used to search features along the
588  * curve in the fitting algorithm. Distance between sample points
589  * gets computed (sample width).
590  * the sample width is equidistant in sampling the basis of the curve,
591  * but not in sampling the curve points!
592  *
593  */
594  inline void SetFitSamples(unsigned int samples);
595 
596  /**
597  * @brief sets the amount of sample points used to draw the B-Spline
598  * curve.
599  * @param[in] width distance of sample points along the curve (<1.0)
600  *
601  * Computes the amount of samples which are used to draw the curve.
602  * These sample points have distance "width". "width" should be
603  * considerably <1.0.
604  * the sample width is equidistant in sampling the basis of the curve,
605  * but not in sampling the curve points!
606  *
607  */
608  inline void SetDrawSampleWidth(double width);
609 
610  /**
611  * @brief sets the amount of sample points used to draw the B-Spline
612  * curve.
613  * @param[in] samples amount of samples used to draw curve
614  *
615  * Sets amount of samples which are used to draw the curve. Distance
616  * between sample points gets computed (sample width).
617  * the sample width is equidistant in sampling the basis of the curve,
618  * but not in sampling the curve points!
619  *
620  */
621  inline void SetDrawSamples(unsigned int samples);
622 
623  //getter
624 
625  /**
626  * @brief returns a vector of control points; first entries are
627  * x-coordinates; last entries are y-coordinates
628  * @param[out] Q vector of control points
629  */
630  inline void GetControlPoints(BIAS::Vector<double>& Q){Q=Q_;};
631 
632  /**
633  * @brief returns a vector of control points in x,y-coordinates
634  * @param[out] cPnts vector of control points in x,y-coordinates
635  */
636  inline void GetControlPoints(std::vector<BIAS::Vector2<double> >& cPnts){
637  QToCPnts_(cPnts);
638  };
639 
640  /**
641  * @brief returns order of B-Spline curve
642  */
643  inline unsigned int GetOrder();
644 
645  /**
646  * @brief returns type of B-Spline curve - possible values are Open,
647  * Closed or Cluster.
648  */
649  inline ContourBSplineType::Type GetBType();
650 
651  /**
652  * @brief returns vector of multiple points; indicates which
653  * control points are modelled as edges
654  */
655  inline std::vector<unsigned int> GetMultiplePoints();
656 
657  /**
658  * @brief returns point on the curve
659  * @param[in] t sample point in [0,1]
660  * @param[out] res resulting point
661  *
662  * Parameter "t" is used to sample the basis of curve and compute
663  * the curve point at "t".
664  *
665  */
666  void GetPoint(const double& t, BIAS::Vector2<double>& res);
667 
668  /**
669  * @brief returns normal in curve point
670  * @param[in] t sample point in [0,1]
671  * @param[out] res resulting normal
672  *
673  * Parameter "t" is used to sample the basis of curve and compute the
674  * normal in curve point at "t".
675  *
676  */
677  void GetNormal(const double& t, BIAS::Vector2<double>& res);
678 
679  /**
680  * @brief returns the feature point with highest gradient along the
681  * normal in curve point located at "t"
682  * @param[in] greyImg input grey image
683  * @param[in] t sample point in [0,1]
684  * @param[in] normalWidth length of normal for searching gradient
685  * feature along normal in curve point at "t"
686  * @param[out] res resulting feature point
687  *
688  *
689  * The input image gets converted to a single gradient image. A ROI gets
690  * computed from controlpoints and the width to search for feature
691  * (normalWidth).
692  *
693  * Parameter "t" is used to sample the basis of the curve and computing
694  * the curve point at "t". the normal at this curve point gets computed.
695  * Along this normal (in both directions) the image point width the
696  * highest gradient gets determined. The resulting features point
697  * has distance less equal than "normalWidth" to curve point.
698  *
699  */
700  void GetFeature(BIAS::Image<StorageType>& greyImg,
701  const double& t, const unsigned int normalWidth,
702  BIAS::Vector2<double>& res);
703 
704  /**
705  * @brief returns the feature point with highest gradient along the
706  * normal in curve point located at "t"
707  * @param[in] greyImg input grey image
708  * @param[in] t sample point in [0,1]
709  * @param[in] normalWidth length of normal for searching gradient
710  * feature along normal in curve point at "t"
711  * @param[in] minClip value of image gradients which are discarded in
712  * the search after the feature point
713  * @param[out] res resulting feature point
714  *
715  *
716  * The input image gets converted to a single gradient image. A ROI gets
717  * computed from controlpoints and the width to search for feature
718  * (normalWidth).
719  *
720  * Parameter "t" is used to sample the basis of the curve and computing
721  * the curve point at "t". the normal at this curve point gets computed.
722  * Along this normal (in both directions) the image point width the
723  * highest gradient gets determined. image gradients less than "minClip"
724  * get discarded. The resulting features point has distance less equal
725  * then "normalWidth" to curve point.
726  *
727  */
728  void GetFeature(BIAS::Image<StorageType>& greyImg,
729  const double& t, const unsigned int normalWidth,
730  const double& minClip,
731  BIAS::Vector2<double>& res);
732 
733  /**
734  * @brief returns the feature point with highest gradient along the
735  * normal in curve point located at "t"
736  * @param[in] featImg input gradient image
737  * @param[in] t sample point in [0,1]
738  * @param[in] normalWidth length of normal for searching gradient
739  * feature along normal in curve point at "t"
740  * @param[out] res resulting feature point
741  *
742  * Parameter "t" is used to sample the basis of the curve and computing
743  * the curve point at "t". the normal at this curve point gets computed.
744  * Along this normal (in both directions) the image point width the
745  * highest gradient gets determined. The resulting feature point
746  * has distance less equal than "normalWidth" to curve point.
747  *
748  */
749  void GetFeature(const BIAS::Image<float>& featImg,
750  const double& t, const unsigned int normalWidth,
751  BIAS::Vector2<double>& res);
752 
753  /**
754  * @brief returns the feature point with highest gradient along the
755  * normal in curve point located at "t"
756  * @param[in] featImg input gradient image
757  * @param[in] t sample point in [0,1]
758  * @param[in] normalWidth length of normal for searching gradient
759  * feature along normal at curve point at "t"
760  * @param[in] minClip value of image gradients which are discarded in
761  * the search after the feature point
762  * @param[out] res resulting feature point
763  *
764  *
765  * Parameter "t" is used to sample the basis of the curve and computing
766  * the curve point at "t". the normal at this curve point gets computed.
767  * Along this normal (in both directions) the image point width the
768  * highest gradient gets determined. image gradients less than "minClip"
769  * get discarded. The resulting feature point has distance less equal
770  * than "normalWidth" to curve point.
771  *
772  */
773  void GetFeature(const BIAS::Image<float>& featImg,
774  const double& t, const unsigned int normalWidth,
775  const double& minClip,
776  BIAS::Vector2<double>& res);
777 
778  /**
779  * @brief returns the feature point with highest gradient along
780  * the normal in curve point "curvePnt"
781  * @param[in] greyImg input grey image
782  * @param[in] normalWidth length of normal for searching gradient
783  * feature along normal at curve point "curvePnt"
784  * @param[in] curvePnt point on the curve which is start point for the
785  * search for feature point
786  * @param[in] normal normal at curve point "curvePnt"
787  * @param[out] res resulting feature point
788  *
789  * The input image gets converted to a single gradient image. A ROI gets
790  * computed from controlpoints and the width to search for feature
791  * (normalWidth).
792  *
793  * Along the normal (in both directions) at curve point "curvePnt"
794  * the image point width the highest gradient gets determined. The
795  * resulting feature point has distance less equal than "normalWidth"
796  * to the curve point.
797  *
798  */
799  inline void GetFeature(BIAS::Image<StorageType>& greyImg,
800  const unsigned int normalWidth,
801  const BIAS::Vector2<double>& curvePnt,
802  const BIAS::Vector2<double>& normal,
803  BIAS::Vector2<double> & res);
804 
805  /**
806  * @brief returns the feature point with highest gradient along
807  * the normal in curve point "curvePnt"
808  * @param[in] greyImg input grey image
809  * @param[in] normalWidth length of normal for searching gradient
810  * feature along normal at curve point "curvePnt"
811  * @param[in] curvePnt point on the curve which is start point for the
812  * search for feature point
813  * @param[in] normal normal at curve point "curvePnt"
814  * @param[in] minClip value of image gradients which are discarded in
815  * the search for the feature point
816  * @param[out] res resulting feature point
817  *
818  * The input image gets converted to a single gradient image. A ROI gets
819  * computed from controlpoints and the width to search for feature
820  * (normalWidth).
821  *
822  * Along the normal (in both directions) at curve point "curvePnt"
823  * the image point width the highest gradient gets determined.
824  * Image gradients less than "minClip"get discarded.The
825  * resulting feature point has distance less equal than "normalWidth"
826  * to the curve point.
827  *
828  */
829  inline void GetFeature(BIAS::Image<StorageType>& greyImg,
830  const unsigned int normalWidth,
831  const BIAS::Vector2<double>& curvePnt,
832  const BIAS::Vector2<double>& normal,
833  const double& minClip,
834  BIAS::Vector2<double> & res);
835 
836  /**
837  * @brief returns the feature point with highest gradient along
838  * the normal in curve point "curvePnt"
839  * @param[in] featImg input gradient image
840  * @param[in] normalWidth length of normal for searching gradient
841  * feature along normal at curve point "curvePnt"
842  * @param[in] curvePnt point on the curve which is start point for the
843  * search for feature point
844  * @param[in] normal normal at curve point "curvePnt"
845  * @param[out] res resulting feature point
846  *
847  * Along the normal (in both directions) at curve point "curvePnt"
848  * the image point width the highest gradient gets determined. The
849  * resulting feature point has distance less equal than "normalWidth"
850  * to the curve point.
851  *
852  */
853  void GetFeature(const BIAS::Image<float>& featImg,
854  const unsigned int normalWidth,
855  const BIAS::Vector2<double>& curvePnt,
856  const BIAS::Vector2<double>& normal,
857  BIAS::Vector2<double> & res);
858 
859  /**
860  * @brief returns the feature point with highest gradient along
861  * the normal in curve point "curvePnt"
862  * @param[in] greyImg input gradient image
863  * @param[in] normalWidth length of normal for searching gradient
864  * feature along normal at curve point "curvePnt"
865  * @param[in] curvePnt point on the curve which is start point for the
866  * search for feature point
867  * @param[in] normal normal at curve point "curvePnt"
868  * @param[in] minClip value of image gradients which are discarded in
869  * the search for the feature point
870  * @param[out] res resulting feature point
871  *
872  * Along the normal (in both directions) at curve point "curvePnt"
873  * the image point width the highest gradient gets determined.
874  * Image gradients less than "minClip"get discarded.The
875  * resulting feature point has distance less equal than "normalWidth"
876  * to the curve point.
877  *
878  */
879  void GetFeature(const BIAS::Image<float>& featImg,
880  const unsigned int normalWidth,
881  const BIAS::Vector2<double>& curvePnt,
882  const BIAS::Vector2<double>& normal,
883  const double& minClip,
884  BIAS::Vector2<double> & res);
885 
886  /**
887  * @brief returns the parameter of the bounding box of the curve
888  * @param[out] minX x-coordinate of top left corner of bounding box
889  * @param[out] minY y-coordinate of top left corner of bounding box
890  * @param[out] maxX x-coordinate of bottom right corner of bounding box
891  * @param[out] maxX y-coordinate of bottom right corner of bounding box
892  */
893  void GetBoundingBox(int& minX, int& minY, int& maxX, int& maxY);
894 
895  //drawing
896 
897  /**
898  * @brief draws the control points of the B-Spline curve into image
899  * @param[out] img output image
900  * @param[in] color
901  */
902  void DrawControlPoints(BIAS::Image<StorageType>& img,
903  const StorageType color[3]);
904 
905  /**
906  * @brief draws B-Spline curve into image
907  * @param[out] img output image
908  * @param[in] color
909  *
910  * Draws B-Spline curve into given image. Uses amount of samples given
911  * by SetDrawSampleWidth(...) of SetDrawSamples(...). If amount of
912  * samples isnt given by these function a default amount is used.
913  *
914  */
915  void DrawCurve(BIAS::Image<StorageType> &img,
916  const StorageType color[3]);
917 
918  /**
919  * @brief draws B-Spline curve into image
920  * @param[out] img output image
921  *
922  * Draws B-Spline curve into given image. Uses amount of samples given
923  * by SetDrawSampleWidth(...) or SetDrawSamples(...). If amount of
924  * samples isnt given by these function a default amount is used.
925  *
926  */
927  void DrawCurve(BIAS::Image<float> &img);
928 
929  /**
930  * @brief draws B-Spline normals into image
931  * @param[out] img output image
932  *
933  * Draws normals along the B-Spline curve into given image. Uses
934  * amount of samples given by SetFitSampleWidth(...) or
935  * SetFitSamples(...). If amount of samples isnt given a default amount
936  * is used.
937  *
938  */
939  void DrawNormals(const unsigned int normalWidth,
941  const StorageType color[3]);
942 
943 
944  protected:
945  //methods
946 
947  /**
948  * @brief initializes curve for drawing or for getting points on it
949  *
950  * Computes curve vectors needed for determine the shape of the curve.
951  * Depends on the basis and the current controlpoints.
952  */
953  void InitCurve_();
954 
955  /**
956  * @brief converts a given control point vector in x,y-coordinates to
957  * the internal used flat control point vector Q whose first
958  * entries are x-coordinates and last entries are y-coordinates
959  * @param[in] cPnts vector of control points in x,y-coordinates
960  */
961  void CPntsToQ_(const std::vector<BIAS::Vector2<double> >& cPnts);
962 
963  /**
964  * @brief converts a given control point vector in x,y-coordinates to
965  * the internal used flat control point vector Q whose first
966  * entries are x-coordinates and last entries are y-coordinates
967  * @param[in] cPnts vector of control points in x,y-coordinates
968  * @param[out] Q vector of control points; first entries are
969  * x-coordinates; last entries are y-coordinates
970  */
971  void CPntsToQ_(const std::vector<BIAS::Vector2<double> >& cPnts,
973 
974  /**
975  * @brief converts a flat control point vector Q whose first entries
976  * are x-coordinates and last entries are y-coordinates to a
977  * control point vector with x,y-coordinates
978  * @param[out] cPnts control point vector with x,y-coordinates
979  */
980  void QToCPnts_(std::vector<BIAS::Vector2<double> >& cPnts);
981 
982  /**
983  * @brief converts a flat control point vector Q whose first entries
984  * are x-coordinates and last entries are y-coordinates to a
985  * control point vector with x,y-coordinates
986  * @param[in] Q vector of control points; first entries are
987  * x-coordinates; last entries are y-coordinates
988  * @param[out] cPnts control point vector with x,y-coordinates
989  */
990  void QToCPnts_(const BIAS::Vector<double>& Q,
991  std::vector<BIAS::Vector2<double> >& cPnts);
992 
993  /**
994  * @brief computes a point on curve and a parameter vector (byproduct)
995  * which can be used for computing a special matrix (U) in
996  * the fitting algorithm
997  * @param[in] numSpan span of curve in which point is located
998  * @param[in] s sample point of span in [0,1]
999  * @param[out] resParamVec special parameter vector (byproduct) used in
1000  * fitting algorithm
1001  * @param[out] res resulting point on curve
1002  *
1003  * This function is internal used to compute a point on a curve. Each
1004  * B-Spline-Curve consist of a number of spans. Parameter "numSpan" and
1005  * "s" are used to sample the curve basis.
1006  * Parameter "resParamVec" is a byproduct of curve point computation. It
1007  * is build up on basis of "s" and can be used to compute the special
1008  * matrix "U" in fitting algorihm.
1009  * More information about "U" can be found in the book "Active Contours".
1010  *
1011  */
1012  void GetPointAndParamVec_(const unsigned int numSpan, const double& s,
1013  BIAS::Vector<double>& resParamVec,
1014  BIAS::Vector2<double>& res);
1015 
1016  /**
1017  * @brief computes a point on curve
1018  * @param[in] numSpan span of curve in which point is located
1019  * @param[in] s sample point of span in [0,1]
1020  * @param[out] res resulting point on curve
1021  *
1022  * This function is internal used to compute a point on a curve. Each
1023  * B-Spline-Curve consist of a number of spans. Parameter "numSpan" and
1024  * "s" are used to sample the curve basis.
1025  */
1026  inline void GetPoint_(const unsigned int numSpan, const double& s,
1027  BIAS::Vector2<double>& res);
1028 
1029  /**
1030  * @brief computes a normal at curve point which is parametrized by
1031  * "numSpan" and "s"
1032  * @param[in] numSpan span of curve in which normal is located
1033  * @param[in] s sample point of span in [0,1]
1034  * @param[out] res resulting normal
1035  *
1036  * This function is internal used to compute a normal at a curve point.
1037  * Each B-Spline-Curve consists of a number of spans.
1038  * The curve point is parameterized by "numSpan" and "s".
1039  */
1040  void GetNormal_(const unsigned int numSpan, const double& s,
1041  BIAS::Vector2<double>& res);
1042 
1043  /**
1044  * @brief converts given grey image to gradient image with ROI
1045  * @param[in] greyImg input grey image
1046  * @param[out] featImg output gradient image
1047  * @param[in] normalWidth used to determine ROI
1048  *
1049  * Converts a given grey image to a gradient image. gradient image is
1050  * needed for the fitting algorithm. In the fitting algorithm only a
1051  * small region of the image is of interest for searching feature points.
1052  * Thus a ROI gets computed from a bounding box of the curve and the
1053  * parameter "normalWidth". Parameter "normalWidth" determines how
1054  * far along curve normal a feature point gets searched.
1055  *
1056  */
1057  void GetFeatImage_(BIAS::Image<StorageType>& greyImg,
1058  BIAS::Image<float>& featImg,
1059  const unsigned int normalWidth);
1060 
1061  /**
1062  * @brief fits the curve to a features curve with regularized fitting
1063  * @param[in] featImage input gradient image
1064  * @param[in] alpha regularisation factor
1065  * @param[in] normalWidth length of normal used to search for feature
1066  * curve
1067  *
1068  * Internal used function to fit the B-Spline curve to a feature curve.
1069  * The feature curve is determined by searching for image points with
1070  * highest gradients along the normals at the curve. Parameter
1071  * "normalWidth" determines the maximal distance of feature point to
1072  * curve (in both directions).
1073  *
1074  * More details in function Fit(..) and book "Active Contours" chapter 6.
1075  *
1076  */
1077  void Fit_(const BIAS::Image<float>& featImg, const double& alpha,
1078  const unsigned int normalWidth);
1079 
1080  /**
1081  * @brief fits the curve to a features curve with regularized fitting
1082  * @param[in] featImage input gradient image
1083  * @param[in] alpha regularisation factor
1084  * @param[in] normalWidth length of normal used to search for feature
1085  * curve
1086  * @param[in] minClip gradients less than "minClip" are discarded in
1087  * search for feature points
1088  *
1089  * Internal used function to fit the B-Spline curve to a feature curve.
1090  * The feature curve is determined by searching for image points with
1091  * highest gradients along the normals at the curve. Parameter
1092  * "normalWidth" determines the maximal distance of feature point to
1093  * curve (in both directions).
1094  *
1095  * More details in function Fit(..) and book "Active Contours" chapter 6.
1096  *
1097  */
1098  void Fit_(const BIAS::Image<float>& featImg, const double& alpha,
1099  const unsigned int normalWidth, const double& minClip);
1100 
1101  //DEBUG methods
1102 
1103 #ifdef BIAS_DEBUG
1104  /**
1105  * @brief tests if B-Spline curve with given parameter can get
1106  * initialized.
1107  * @param[in] order order of B-Spline curve
1108  * @param[in] bType type of B-Spline curve (Open or Closed)
1109  * @param[in] mPnts vector of multiplicities - determines which control
1110  * points are modelled as edges
1111  * @param[in] Q vector of control points
1112  *
1113  * Test if B-Spline curve with given parameter can get initialised.
1114  * Most important test if mPnts is correct. That means if edges could
1115  * be generated in these control points.
1116  */
1117  void TestInit_(const unsigned int order,
1118  const ContourBSplineType::Type bType,
1119  const std::vector<unsigned int>& mPnts,
1120  const BIAS::Vector<double>& Q);
1121 #endif
1122 
1123 
1124 
1125  //class variables
1126 
1127  /**
1128  * vector of control points; first entries are x-coordinates; last
1129  * entries are y-coordinates
1130  */
1131  BIAS::Vector<double> Q_; //control points
1132 
1133  //! pointer to data of B-Spline curve initialised by call of Init(...)
1135 
1136  //! vectors needed to draw curve (determined by InitCurve_)
1137  std::vector<std::vector<BIAS::Vector<double> > > curveVectors_;
1138  //! bool to indicate a change of control points
1140 
1141  //! pointer to shape-space matrix object
1143  //! pointer to invariant shape-space matrix object
1145  //! pointer to regularisation matrix object
1146  ContourBSplineShapeMatrix* pRegMatrix_;//regularisation Matrix
1147 
1148  //! distance of sample points in basis used in fitting algorithm
1150  //! distance of sample points in basis used in drawing algorithm
1152  //! amount of samples used in fitting algorithm
1153  unsigned int fitSamples_;
1154  //! amount of samples used in drawing algorithm
1155  unsigned int drawSamples_;
1156 
1157  };//class ContourBSpline
1158 
1159  template <class StorageType> ContourDetectorBSpline<StorageType>&
1162  //copies all important class member variables from object toCopy
1163  Q_=toCopy.Q_;
1164  pData_=toCopy.pData_;
1165  if(pData_!=NULL){
1166  (pData_->reference_)++; //increase data reference counter
1167  }
1168  curveInitialised_=false; //curveVectors_ get not copied
1169  pShapeSpaceMatrix_=toCopy.pShapeSpaceMatrix_;
1170  if(pShapeSpaceMatrix_!=NULL){
1171  (pShapeSpaceMatrix_->reference_)++;//increase ref counter
1172  }
1173  pSubShapeSpaceMatrix_=toCopy.pSubShapeSpaceMatrix_;
1174  if(pSubShapeSpaceMatrix_!=NULL){
1175  (pSubShapeSpaceMatrix_->reference_)++;//increase ref counter
1176  }
1177  pRegMatrix_=toCopy.pRegMatrix_;
1178  if(pRegMatrix_!=NULL){
1179  (pRegMatrix_->reference_)++;//increase ref counter
1180  }
1181  fitSampleWidth_=toCopy.fitSampleWidth_;
1182  drawSampleWidth_=toCopy.drawSampleWidth_;
1183  fitSamples_=toCopy.fitSamples_;
1184  drawSamples_=toCopy.drawSamples_;
1185 
1186  return *this;
1187  }
1188 
1189  template <class StorageType> void
1191  SetControlPoints(const std::vector<BIAS::Vector2<double> >& controlPoints){
1192  //convert vector of control points into internal used format
1193  CPntsToQ_(controlPoints);
1194  curveInitialised_=false;
1195  }
1196 
1197 
1198  template <class StorageType> void
1201  Q_=Q;
1202  curveInitialised_=false;
1203  }
1204 
1205 
1206  template <class StorageType> void
1208  Displace(const double& x, const double&y){
1209  unsigned int i; //counter variable
1210  for(i=0;i<(pData_->numBasePolynoms_);i++){
1211  Q_[i]+=x;
1212  Q_[i+(pData_->numBasePolynoms_)]+=y;
1213  }
1214  curveInitialised_=false;
1215  }
1216 
1217  template <class StorageType> void
1219  Scale(const double& scale){
1220  //curve must have origin at zero!
1221  int i; // counter variable;
1222  for(i=0;i<Q_.size();i++){
1223  Q_[i]*=scale;
1224  }
1225  }
1226 
1227  template <class StorageType> void
1229  ScaleX(const double& scale){
1230  //curve must have origin at zero!
1231  int i; // counter variable;
1232  for(i=0;i<(Q_.size()/2);i++){
1233  Q_[i]*=scale;
1234  }
1235  }
1236 
1237  template <class StorageType> void
1239  ScaleY(const double& scale){
1240  //curve must have origin at zero!
1241  int i; // counter variable;
1242  for(i=(Q_.size()/2);i<Q_.size();i++){
1243  Q_[i]*=scale;
1244  }
1245  }
1246 
1247  template <class StorageType> void
1250  unsigned int i; //counter variable
1251  double x,y;
1252  x=0;y=0;
1253  for(i=0; i<pData_->numBasePolynoms_; i++){
1254  x+=Q_[i];
1255  y+=Q_[i+pData_->numBasePolynoms_];
1256  }
1257  x/=(double) pData_->numBasePolynoms_;
1258  y/=(double) pData_->numBasePolynoms_;
1259  Displace(-x,-y);
1260  }
1261 
1262  template <class StorageType> void
1265  BIAS::Matrix<double>& shapeSpace){
1267  shapeSpace);
1268  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "shapeSpaceMatrix: " <<
1269  (BIAS::Matrix<double>)*pShapeSpaceMatrix_ <<std::endl<<
1270  std::flush);
1271  }
1272 
1273  template <class StorageType> void
1277  pData_->numBasePolynoms_);
1278  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "shapeSpaceMatrix: " <<
1279  (BIAS::Matrix<double>)*pShapeSpaceMatrix_ <<std::endl<<
1280  std::flush);
1281  }
1282 
1283  template <class StorageType> void
1287  pData_->numBasePolynoms_,Q_);
1288  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "shapeSpaceMatrix: " <<
1289  (BIAS::Matrix<double>)*pShapeSpaceMatrix_ <<std::endl<<
1290  std::flush);
1291  }
1292 
1293  template <class StorageType> void
1297  (pData_->numBasePolynoms_,Q_);
1298  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "shapeSpaceMatrix: " <<
1299  (BIAS::Matrix<double>)*pShapeSpaceMatrix_ <<std::endl<<
1300  std::flush);
1301  }
1302 
1303  template <class StorageType> void
1306  BIAS::Matrix<double>& subShapeSpace){
1307  pSubShapeSpaceMatrix_ = ContourBSplineShapeMatrix::SetShapeSpaceMatrix(
1308  subShapeSpace);
1309  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "subShapeSpaceMatrix: " <<
1310  (BIAS::Matrix<double>)*pSubShapeSpaceMatrix_ <<std::endl<<
1311  std::flush);
1312  }
1313 
1314  template <class StorageType> void
1317  pSubShapeSpaceMatrix_ = ContourBSplineShapeMatrix::SetShapeSpaceIdentity
1318  (pData_->numBasePolynoms_);
1319  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "subShapeSpaceMatrix: " <<
1320  (BIAS::Matrix<double>)*pSubShapeSpaceMatrix_ <<std::endl<<
1321  std::flush);
1322  }
1323 
1324  template <class StorageType> void
1327  pSubShapeSpaceMatrix_ = ContourBSplineShapeMatrix::
1328  SetShapeSpaceEuclidian(pData_->numBasePolynoms_,Q_);
1329  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "subShapeSpaceMatrix: " <<
1330  (BIAS::Matrix<double>)*pSubShapeSpaceMatrix_ <<std::endl<<
1331  std::flush);
1332  }
1333 
1334  template <class StorageType> void
1337  pSubShapeSpaceMatrix_ = ContourBSplineShapeMatrix::
1338  SetShapeSpacePlanarAffin(pData_->numBasePolynoms_,Q_);
1339  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "subShapeSpaceMatrix: " <<
1340  (BIAS::Matrix<double>)*pSubShapeSpaceMatrix_ <<std::endl<<
1341  std::flush);
1342  }
1343 
1344  template <class StorageType> void
1347  pSubShapeSpaceMatrix_ =
1349  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "subShapeSpaceMatrix: " <<
1350  (BIAS::Matrix<double>)*pSubShapeSpaceMatrix_ <<std::endl<<
1351  std::flush);
1352  }
1353 
1354  template <class StorageType> void
1357  if(pData_==NULL)
1358  BIASERR("ComputeRegularisationMatrix: pData_ NULL pointer\r\n");
1359  if(pShapeSpaceMatrix_==NULL)
1360  BIASERR("ComputeRegularisationMatrix: "<<
1361  "pShapeSpaceMatrix_ NULL pointer\r\n");
1362  if(pSubShapeSpaceMatrix_==NULL)
1363  BIASERR("ComputeRegularisationMatrix: "<<
1364  "pSubShapeSpaceMatrix_ NULL pointer\r\n");
1366  pData_, pShapeSpaceMatrix_, pSubShapeSpaceMatrix_ );
1367  BIASCDOUT(D_CONTOURBSPLINE_INITFIT, "regMatrix: " <<
1368  (BIAS::Matrix<double>)*pRegMatrix_ <<std::endl<<std::flush);
1369  }
1370 
1371  template <class StorageType> void
1373  SetFitSampleWidth(double width){
1374  if(fitSampleWidth_==NULL){
1375  fitSampleWidth_= new double;
1376  }
1377  fitSamples_=(unsigned int)(1./width);
1378  *fitSampleWidth_=1./(double)fitSamples_;
1379  }
1380 
1381  template <class StorageType> void
1383  SetFitSamples(unsigned int samples){
1384  if(fitSampleWidth_==NULL){
1385  fitSampleWidth_= new double;
1386  }
1387  fitSamples_=samples;
1388  *fitSampleWidth_=1./(double)fitSamples_;
1389  }
1390 
1391  template <class StorageType> void
1393  SetDrawSampleWidth(double width){
1394  if(drawSampleWidth_==NULL){
1395  drawSampleWidth_= new double;
1396  }
1397  drawSamples_=(unsigned int)(1./width);
1398  *drawSampleWidth_=1./(double)drawSamples_;
1399  }
1400 
1401  template <class StorageType> void
1403  SetDrawSamples(unsigned int samples){
1404  if(drawSampleWidth_==NULL){
1405  drawSampleWidth_= new double;
1406  }
1407  drawSamples_=samples;
1408  *drawSampleWidth_=1./(double)drawSamples_;
1409  }
1410 
1411  template <class StorageType> unsigned int
1413  BIASASSERT(pData_!=NULL);
1414  return pData_->order_;
1415  }
1416 
1417  template <class StorageType> ContourBSplineType::Type
1419  BIASASSERT(pData_!=NULL);
1420  return pData_->bType_;
1421  }
1422 
1423  template <class StorageType> std::vector<unsigned int>
1425  BIASASSERT(pData_!=NULL);
1426  return pData_->mPnts_;
1427  }
1428 
1429  template <class StorageType> void
1432  const unsigned int normalWidth,
1433  const BIAS::Vector2<double>& curvePnt,
1434  const BIAS::Vector2<double>& normal,
1435  BIAS::Vector2<double> & res){
1436  BIAS::Image<float> featImg;
1437  GetFeatImage_(greyImg, featImg, normalWidth);
1438  GetFeature(featImg,normalWidth,curvePnt,normal,res);
1439  }
1440 
1441  template <class StorageType> void
1444  const unsigned int normalWidth,
1445  const BIAS::Vector2<double>& curvePnt,
1446  const BIAS::Vector2<double>& normal,
1447  const double& minClip,
1448  BIAS::Vector2<double> & res){
1449  BIAS::Image<float> featImg;
1450  GetFeatImage_(greyImg, featImg, normalWidth);
1451  GetFeature(featImg,normalWidth,curvePnt,normal,minClip,res);
1452  }
1453 
1454  template <class StorageType> void
1456  GetPoint_(const unsigned int numSpan,
1457  const double& s,
1458  BIAS::Vector2<double>& res){
1459  BIAS::Vector<double> param;
1460  GetPointAndParamVec_(numSpan, s, param, res);
1461  }
1462 
1463 }//namespace BIAS
1464 #endif//__CONTOURDETECTORBSPLINE_HH_
void Scale(const double &scale)
scales curve isotropic
void GetFeature(BIAS::Image< StorageType > &greyImg, const double &t, const unsigned int normalWidth, BIAS::Vector2< double > &res)
returns the feature point with highest gradient along the normal in curve point located at &quot;t&quot; ...
void SetFitSampleWidth(double width)
sets the amount of samples used to search features along the curve in fitting algorithm.
void GetControlPoints(std::vector< BIAS::Vector2< double > > &cPnts)
returns a vector of control points in x,y-coordinates
void SetSubShapeSpaceIdentity()
set invariant shape-space for regularised fitting to identity
ContourBSplineData * pData_
pointer to data of B-Spline curve initialised by call of Init(...)
data object which holds a shape matrix or regularisation matrix for a b-spline curve; could be shared...
void GetPoint_(const unsigned int numSpan, const double &s, BIAS::Vector2< double > &res)
computes a point on curve
unsigned int drawSamples_
amount of samples used in drawing algorithm
void ScaleY(const double &scale)
scales curve in y-direction (vertically)
void SetShapeSpaceIdentity()
sets spape-space for regularised fitting to identity
ContourDetectorBSpline & operator=(const ContourDetectorBSpline< StorageType > &toCopy)
copy operator
data object which holds all infomations of a B-Spline curve (ContourBSpline); its shared by B-Spline ...
ContourBSplineType::Type GetBType()
returns type of B-Spline curve - possible values are Open, Closed or Cluster.
double * fitSampleWidth_
distance of sample points in basis used in fitting algorithm
ContourBSplineShapeMatrix * pSubShapeSpaceMatrix_
pointer to invariant shape-space matrix object
bool curveInitialised_
bool to indicate a change of control points
static ContourBSplineShapeMatrix * ComputeRegularisationMatrix(ContourBSplineData *data, ContourBSplineShapeMatrix *shapeSpace, ContourBSplineShapeMatrix *subShapeSpace)
generates a new regularisation matrix as ContourBSplineShapeMatrix object and returns pointer to it ...
static ContourBSplineShapeMatrix * SetShapeSpacePlanarAffin(const unsigned int numBasePolynoms, const BIAS::Vector< double > &Q)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
void SetShapeSpaceEuclidian()
sets spape-space for regularised fitting to euclidian similarities
void SetShapeSpacePlanarAffin()
sets spape-space for regularised fitting to planar affine transformations
void SetFitSamples(unsigned int samples)
sets the amount of samples used to search features along the curve in fitting algorithm.
BIAS::Vector< double > Q_
vector of control points; first entries are x-coordinates; last entries are y-coordinates ...
double * drawSampleWidth_
distance of sample points in basis used in drawing algorithm
std::vector< unsigned int > GetMultiplePoints()
returns vector of multiple points; indicates which control points are modelled as edges ...
void SetSubShapeSpacePlanarAffin()
set invariant shape-space for regularised fitting to planar affine transformation ...
void SetDrawSamples(unsigned int samples)
sets the amount of sample points used to draw the B-Spline curve.
void SetDrawSampleWidth(double width)
sets the amount of sample points used to draw the B-Spline curve.
static ContourBSplineShapeMatrix * SetShapeSpaceMatrix(const BIAS::Matrix< double > &matrix)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
The image template class for specific storage types.
Definition: Image.hh:78
void GetControlPoints(BIAS::Vector< double > &Q)
returns a vector of control points; first entries are x-coordinates; last entries are y-coordinates ...
represents a special B-Spline and holds functions to handle fitting
void ScaleX(const double &scale)
scales curve in x-direction (horizontally)
unsigned int GetOrder()
returns order of B-Spline curve
void SetSubShapeSpaceZero()
set invariant shape-space for regularised fitting to zero
void SetControlPoints(const std::vector< BIAS::Vector2< double > > &controlPoints)
sets new control points
static ContourBSplineShapeMatrix * SetShapeSpaceIdentity(const unsigned int numBasePolynoms)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
void SetSubShapeSpaceEuclidian()
set invariant shape-space for regularised fitting to euclidian similarities
std::vector< std::vector< BIAS::Vector< double > > > curveVectors_
vectors needed to draw curve (determined by InitCurve_)
static ContourBSplineShapeMatrix * SetSubShapeSpaceZero(ContourBSplineShapeMatrix *shapeSpace)
generates a new invariant shape-matrix as ContourBSplineShapeMatrix object and returns a pointer to i...
unsigned int fitSamples_
amount of samples used in fitting algorithm
void Displace(const double &x, const double &y)
displace all control points
void SetSubShapeSpaceMatrix(BIAS::Matrix< double > &subShapeSpace)
set invariant shape-space for regularised fitting
void SetShapeSpaceMatrix(BIAS::Matrix< double > &shapeSpace)
sets spape-space for regularised fitting
static ContourBSplineShapeMatrix * SetShapeSpaceEuclidian(const unsigned int numBasePolynoms, const BIAS::Vector< double > &Q)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
ContourBSplineShapeMatrix * pRegMatrix_
pointer to regularisation matrix object
ContourBSplineShapeMatrix * pShapeSpaceMatrix_
pointer to shape-space matrix object
ContourDetectorBSpline(const ContourDetectorBSpline< StorageType > &toCopy)
copy constructor
purely virtual interface defining class for contour detectors
void CenterOverControlPoints()
centers the curve by computing center over control points (not accurate!)
void ComputeRegularisationMatrix()
computes the regularisation matrix needed for fitting algorithm.