Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BlobDetectorLevelSet.hh
1 #ifndef __BLOBDETECTOR_LEVELSET_HH__
2 #define __BLOBDETECTOR_LEVELSET_HH__
3 
4 // bias include
5 #include <Base/Image/Image.hh>
6 #include <Base/Math/Vector2.hh>
7 #include "BlobDetectorBase.hh"
8 
9 namespace BIAS{
10 
11  /**
12  @class BlobDetectorLevelSet
13  @brief Evaluates a segementation into fore/back-ground.
14  Usage:
15  Initialise class with an image by calling Init(),
16  if the image roi has a valid mask it is used as evaluation area.
17  Set an initial level set square (use InitLevelSetSquare).
18  Set a evaluation square, if the image has no valid roi mask.
19  Than call Evolute() round about 100 times (or what ever
20  it will needs).
21 
22  What you get:
23  The segmentation of image is given by GetLevel(), but
24  GetSegmentation() creats an image much better for visalisation.
25 
26  ----
27 
28  Please take a look at example ExampleSegmentationLevelSet, which
29  visualises the Evolute() steps.
30  @test tested with ExampleBlobDetectorLevelSet.cpp
31  @author Dennis Herzog, 2005-07-28, edited ischiller 08/08
32  @ingroup g_feature
33  */
34  template <class StorageType>
35  class BIASFeatureDetector_EXPORT BlobDetectorLevelSet :
36  public BlobDetectorBase<StorageType>
37  {
38 
39  public:
41  virtual ~BlobDetectorLevelSet();
42 
43  int Detect(Image<StorageType>& image,
44  std::vector<BIAS::BIASBlob>& blobs);
45 
46 
47  /** @brief initialise this instance with given image,
48  note: image must not be modified until you delete
49  this instance or an other image is set,
50  the image's roi msk defines the evaluation area (if given)
51  @author Dennis Herzog, 2005-07-28 */
52  void Init(const BIAS::Image<StorageType> &image, bool useROI = true);
53 
54  /** @brief sets image to operate on,
55  note: image must not be modified until you delete
56  this instance or an other image is set,
57  the image's roi msk defines the evaluation area (if given)
58  @author Dennis Herzog, 2005-08-01 */
59  void Set(const BIAS::Image<StorageType> &image, bool useROI = true);
60 
61  /** @brief look at class discription
62  @author Dennis Herzog, 2005-07-28 */
63  void InitLevelSetSquare(const BIAS::Vector2<int>& p1,
64  const BIAS::Vector2<int>& p2);
65 
66  /** @brief can be used only, iff image's roi is not in use
67  (look at class discription)
68  @author Dennis Herzog, 2005-07-28 */
69  void SetEvaluationSquare(const BIAS::Vector2<int>& p1,
70  const BIAS::Vector2<int>& p2);
71  /// look at SetEvaluationSquare()
72  void AddEvaluationSquare(const BIAS::Vector2<int>& p1,
73  const BIAS::Vector2<int>& p2);
74 
75  /** @brief does the hole segmentation work by modifying the level set
76  (look at class discription)
77  @author Bodo Rosenhahn / ported and optimised by Dennis Herzog,
78  2005-07-28 */
79  void Evolute();
80 
81  public:
82  /** @brief returns reference of currently used image
83  @author Dennis Herzog, 2005-07-28 */
84  const BIAS::Image<StorageType>& GetImage() const { return *image_; }
85 
86  /** @brief returns (roi) msk (the evaluation array) as an image
87  @author Dennis Herzog, 2005-07-28 */
88  const BIAS::Image<StorageType>& GetEval() const { return eval_; }
89 
90  /** @brief returns (roi) msk (the evaluation array) as an image
91  (is allowed to be modified, iff image's roi is not in use)
92  @author Dennis Herzog, 2005-07-28 */
94  { BIASASSERT( eval_ownsdata_ == true ); return eval_; }
95 
96  /** @brief returns the actual level set, modified each time you call
97  Evolute()
98  @author Dennis Herzog, 2005-07-28 */
99  const BIAS::Image<StorageType>& GetLevel() const { return *level_; }
100 
101  /** @brief returns the actual level set, modified each time you call
102  Evolute(),
103  (is allowed to be modified),
104  (0 is background, != 0 is foreground)
105  @author Dennis Herzog, 2005-07-28 */
106  BIAS::Image<StorageType>& GetLevel() { return *level_; }
107 
108  /** @brief creates an image for visulalistion of the actual segmentation
109  given by actual level set
110  @author Dennis Herzog, 2005-07-28 */
111  void GetSegmentation(BIAS::Image<StorageType>& im) const;
112 
113  /** @returns histogram of foreground (hist=1) and background (hist=0)
114  @author Dennis Herzog, 2005-07-28 */
115  std::vector<int> GetHistogram(int hist);
116 
117  protected:
118  int _hist0[256];
119  int _hist1[256];
120 
122  BIAS::Image<StorageType> *level_; // level/level_s are swapped
123  BIAS::Image<StorageType> *level_s_; // used temporarily by Evolute()
124  BIAS::Image<StorageType> eval_; // encaps _image's msk
125  bool eval_ownsdata_; // does _eval owns the data it uses
126 
127  static void Resize(BIAS::Image<StorageType> &image,
128  const int w, const int h);
129  static void ClearHistogram(int hist[]);
130  void ClearHistograms();
131  void RecalcHistograms();
132  void AddSquare(BIAS::Image<StorageType>& image,
133  const BIAS::Vector2<int>& p1,
134  const BIAS::Vector2<int>& p2);
135 
136  };//class
137 
138 
139 
140 }//namespace
141 
142 
143 
144 #endif // __BLOBDETECTOR_LEVELSET_HH__
145 
const BIAS::Image< StorageType > * image_
const BIAS::Image< StorageType > & GetImage() const
returns reference of currently used image
BIAS::Image< StorageType > * level_
purly virtual interface defining class for blob detectors
Evaluates a segementation into fore/back-ground.
BIAS::Image< StorageType > eval_
The image template class for specific storage types.
Definition: Image.hh:78
const BIAS::Image< StorageType > & GetLevel() const
returns the actual level set, modified each time you call Evolute()
BIAS::Image< StorageType > & GetLevel()
returns the actual level set, modified each time you call Evolute(), (is allowed to be modified)...
BIAS::Image< StorageType > & GetEval()
returns (roi) msk (the evaluation array) as an image (is allowed to be modified, iff image&#39;s roi is n...
BIAS::Image< StorageType > * level_s_
const BIAS::Image< StorageType > & GetEval() const
returns (roi) msk (the evaluation array) as an image