Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BlobDetectorBFS.hh
1 #ifndef __BLOBDETECTOR_BFS_hh__
2 #define __BLOBDETECTOR_BFS_hh__
3 
4 // includes
5 #include <bias_config.h>
6 #include <Base/Math/Vector2.hh>
7 #include <Base/Image/Image.hh>
8 #include <Filter/Gauss.hh>
9 #include "BlobDetectorBase.hh"
10 
11 namespace BIAS {
12 
13  typedef std::vector<BIAS::Vector2<unsigned int> > PointQueue;
14 
15  /**
16  @class BlobDetectorBFS
17  Detects multiple blobs in an image, image has to be black
18  except blocks to detect
19  @author fkellner/ischiller 07/2008
20  @ingroup g_feature
21  */
22  template <class StorageType>
23  class BIASFeatureDetector_EXPORT BlobDetectorBFS :
24  public BlobDetectorBase<StorageType>
25  {
26  public:
27  /**
28  @brief standard constructor
29  */
31 
32  /**
33  @brief standard destructor
34  */
35  virtual ~BlobDetectorBFS();
36 
37  /**
38  @brief Detect and return blobs in an image
39  @param[in] image the image to detect blobs in
40  @param[out] corners vector where detected blobs are stored in
41  @return 0 on sucess, -1 on failure
42  */
43  int Detect(BIAS::Image<StorageType> &image,
44  std::vector<BIAS::BIASBlob> &blobs);
45 
46 
47  /**
48  @brief set a ROI (region of interest) in the image to detect
49  @param UL Vector2 containing upper left corner
50  @param LR Vector2 containing lower right corner
51  */
53  UL_ = UL;
54  LR_ = LR;
55  }
56 
57  /**
58  @brief return largest blob (bounding box)
59  @param corners largest detected blob
60  @return 0 on sucess, -1 on failure
61  */
63  if (maxCorners_.weight == 0)
64  return -1;
65  corners = maxCorners_;
66  return 0;
67  }
68 
69  /**
70  @brief draws the detected blobs in image
71  @param[in] image the blobs are drawn in here
72  @return 0 on sucess, -1 on failure
73  */
74  int DrawInImage(BIAS::Image<StorageType> &image);
75 
76 
77  /**
78  @brief set threshold for blobdetection
79  @param threshold difference between background (black) and blob content
80  */
81  void SetThreshold(StorageType threshold){
82  threshold_=threshold;
83  }
84 
85  /**
86  @brief set sigma for gaussian blurr before blobdetection
87  @param sigma the gauss sigma
88  */
89  void SetGaussSigma(double sigma){
90  gaussSigma_ = sigma;
91  }
92 
93  /**
94  @brief set minimum size of blobs
95  @param minsize minimum size in pixel
96  */
97  void SetMinSize(unsigned minSize){
98  minWeight_ = minSize;
99  }
100 
101  void SetMaxSize(unsigned maxSize){
102  maxWeight_ = maxSize;
103  }
104  /**
105  @brief setting this true will clear pixels (0) in clusters of weight < minWeight
106  @param erase true to clean up
107  */
108  void SetEraseBelowMinSize(bool erase){
109  eraseBelowMinWeight_ = erase;
110  }
111 
112  protected:
113  /**
114  @brief protected blobDetection function
115  @param[in] x start x pixel coordinate
116  @param[in] y start y pixel coordinate
117  @param[in] w width of search space
118  @param[in] h height of search space
119  @param[in] idaIn input image imageDataArray
120  @param[out] idaMark mark image imageDataArray (handled pixels are marked here)
121  @param[out] corners detected corners
122  @return int 0 on success -1 on failure
123  */
124  int ClusterDescent_(const unsigned int x, const unsigned int y,
125  const unsigned int w, const unsigned int h,
126  StorageType **idaIn, unsigned char **idaMark,
127  BIAS::BIASBlob &corners, StorageType **idaOrig);
128 
129  protected:
133  std::vector<BIAS::BIASBlob> corners_;
134  StorageType threshold_;
135  double gaussSigma_;
138  unsigned minWeight_,maxWeight_;
140 
141  private:
142  PointQueue queue;
143  PointQueue cluster;
144  unsigned int n[16];
145 
146  }; // class BlobDetectorBFS
147 
148 } // namespace
149 
150 #endif // __BLOBDETECTOR_BFS_hh__
std::vector< BIAS::Vector2< unsigned int > > PointQueue
void SetThreshold(StorageType threshold)
set threshold for blobdetection
BIAS::Vector2< unsigned > UL_
void SetEraseBelowMinSize(bool erase)
setting this true will clear pixels (0) in clusters of weight &lt; minWeight
BIAS::Image< StorageType > imageSmooth_
void SetMinSize(unsigned minSize)
set minimum size of blobs
void SetMaxSize(unsigned maxSize)
int GetLargestBoundingBox(BIAS::BIASBlob &corners)
return largest blob (bounding box)
BIAS::Image< unsigned char > markerBackup_
std::vector< BIAS::BIASBlob > corners_
Helper class to store blob corners.
purly virtual interface defining class for blob detectors
BIAS::BIASBlob maxCorners_
The image template class for specific storage types.
Definition: Image.hh:78
BIAS::Gauss< StorageType, StorageType > smoothFilter_
Detects multiple blobs in an image, image has to be black except blocks to detect.
void SetROI(const BIAS::Vector2< unsigned > &UL, const BIAS::Vector2< unsigned > &LR)
set a ROI (region of interest) in the image to detect
void SetGaussSigma(double sigma)
set sigma for gaussian blurr before blobdetection