Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BlobDetectorCCA.hh
1 #ifndef __BLOBDETECTOR_CCA_HH__
2 #define __BLOBDETECTOR_CCA_HH__
3 #include <vector>
4 #include <Base/Image/Image.hh>
5 #include <Base/Math/Vector2.hh>
6 #include <Filter/Label.hh>
7 #include "BlobDetectorBase.hh"
8 
9 namespace BIAS {
10 
11  /** @class BlobDetectorCCA
12  Does a Connected Component Analyis and gives information about regions
13  in an image, like centroid and bounding boxes.
14  Geometry
15  useful after morphological operators like Erosion or Dilation
16  The input image has to be segmented in only a few grey values,
17  best is black or white.
18  @ingroup g_feature
19  neighborhood 8 so far not implemented
20  @author grest, Aug. 2004, ischiller 08/08
21  */
22 
23  template <class StorageType>
24  class BIASFeatureDetector_EXPORT BlobDetectorCCA :
25  public BIAS::Label,public BlobDetectorBase<StorageType> {
26  public:
27 
29  virtual ~BlobDetectorCCA();
30 
31  /**
32  Does a Connected Component Analyis (4-neighborhood)
33  and deletes all regions, whose sizes are smaller
34  than p percent of the image.<br>
35  Use SetPercent and SetNeighborhoud4 before
36  If percent is negative, only the two largest regions are not deleted.
37  While there is no difference between fore- and background (see
38  BIAS::Label), so the largest region is usually the background.
39  One channel images only !<br>
40 
41  @author Daniel Grest, Aug. 2004
42  */
43  int Detect(Image<StorageType>& image,
44  std::vector<BIAS::BIASBlob>& blobs);
45 
46  /** call this afer Process() to get the medians of all regions.
47  Calculates the medians of each region, sorted by size of the region,
48  largest region first.
49  returns 0, in case of no error
50  @author Daniel Grest, June. 2003
51  */
52  int GetMedians(std::vector<BIAS::Vector2<unsigned int> > &medians);
53 
54  /** call this afer Process() to get the centroids of all regions.
55  Calculates the centroids of each region, sorted by size of the region,
56  largest region first.
57  returns 0, in case of no error
58  @author Daniel Grest, June. 2003
59  */
60  int GetCentroids(std::vector<BIAS::Vector2<double> > &centroids);
61 
62 
63  /**
64  @brief
65  */
66  void SetPercent(float percent){
67  fPercent_ = percent;
68  }
69 
70  /**
71  @brief If neighborHood4, then a max of 255 regions is possible, if there are
72  more it results in undefined behaviour (probably a segfault).
73  Best is to delete small regions before, e.g. with Erosion3Fast or
74  DeleteSingles() from BIAS::Morphology
75  */
76  void SetNeighborhoud4(bool neighborhoud4){
77  bNeighborHood4_ = neighborhoud4;
78  }
79 
80  protected:
81  /**
82  init is called before processing the first image
83  */
84  void Init_(const BIAS::Image<StorageType> &img);
85 
86  int Process_(BIAS::Image<StorageType> &img, float percent,
87  bool neighborHood4=true);
88 
89  bool bIsInited_;
90  float fPercent_;
92 
93  int Process8_(BIAS::Image<StorageType> &img, float percent);
94  std::vector<std::vector<BIAS::Vector2<int> > > allBlobs_;
95 
96 
97  };//class
98 }//namespace
99 
100 
101 
102 #endif //_BLOBDETECTOR_CCA_HH__
std::vector< std::vector< BIAS::Vector2< int > > > allBlobs_
purly virtual interface defining class for blob detectors
The image template class for specific storage types.
Definition: Image.hh:78
void SetPercent(float percent)
does a connected component analysis and labels all connected regions
Definition: Label.hh:84
Does a Connected Component Analyis and gives information about regions in an image, like centroid and bounding boxes.
void SetNeighborhoud4(bool neighborhoud4)
If neighborHood4, then a max of 255 regions is possible, if there are more it results in undefined be...