vil_region_finder.h
Go to the documentation of this file.
1 #ifndef vil_region_finder_h_
2 #define vil_region_finder_h_
3 //:
4 // \file
5 // \verbatim
6 // Modifications
7 // March.2005 - Gehua Yang - template on predicate to make it generic
8 // \endverbatim
9 
10 #include <vector>
11 #include <functional>
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
15 #include <vil/vil_image_view.h>
16 
17 //: Type of connectivity to use in finding the regions
18 //
19 // \relatesalso vil_region_finder
20 //
22 {
25 };
26 
27 //: Extract regions from an image using a flood-fill.
28 //
29 // This class encapsulates a simple flood fill algorithm to extract a
30 // four or eight connected regions from an image. It uses an auxiliary
31 // bool image to mark pixels as processed. This mark is not reset
32 // between calls to the region extraction routine, so each region can
33 // be extracted only once.
34 //
35 template <class pix_type, class predicate_type = std::equal_to<pix_type> >
37 {
38  public:
39  //:
41 
42  //: Prepare to extract regions from \a image
45 
46  //: Extract the region containing (i,j)
47  //
48  // This will return the coordinates of all the pixels in the region
49  // around (i,j) where the predicate claims true compared with the intensity of
50  // pixel (i,j).
51  //
52  // This is a simple flood fill algorithm.
53  //
54  void
55  same_int_region( unsigned i, unsigned j,
56  std::vector<unsigned>& ri,
57  std::vector<unsigned>& rj );
58 
59 
60  //: Extract the region containing (i,j)
61  //
62  // This will return the coordinates of all the pixels in the region
63  // around (i,j) where the predicate claims true compared with the intensity p
64  //
65  // This is a simple flood fill algorithm.
66  //
67  void
68  same_int_region( unsigned i, unsigned j, pix_type p,
69  std::vector<unsigned>& ri,
70  std::vector<unsigned>& rj );
71 
72  //: The image from which the regions are being extracted
73  image_view const&
74  image() const;
75 
76  //: boolean mask on the region
78 
79  private:
80  //:
81  // Marks all pixels as unprocessed, and sets the neighbour deltas
82  // based on the requested connectivity.
83  //
84  void
86 
87  //: The image
89 
90  //: The marks
92 
93  //: The size of the nbr_delta_ array
94  unsigned num_nbrs_;
95 
96  //: The deltas to the neighbours.
97  int const (*nbr_delta_)[2];
98 
99  //: predicate
100  predicate_type predi_;
101 };
102 
103 // do the implicit template thing.
104 #include "vil_region_finder.hxx"
105 
106 #endif // vil_region_finder_h_
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
image_view const & image() const
The image from which the regions are being extracted.
vil_image_view< bool > const & boolean_region_image() const
boolean mask on the region.
vil_image_view< bool > processed_
The marks.
void same_int_region(unsigned i, unsigned j, std::vector< unsigned > &ri, std::vector< unsigned > &rj)
Extract the region containing (i,j).
vil_region_finder_connectivity
Type of connectivity to use in finding the regions.
void init(vil_region_finder_connectivity)
Marks all pixels as unprocessed, and sets the neighbour deltas based on the requested connectivity.
vil_image_view< pix_type > image_view
A base class reference-counting view of some image data.
image_view const image_
The image.
predicate_type predi_
predicate.
vil_region_finder(image_view const &image, vil_region_finder_connectivity conn=vil_region_finder_4_conn)
Prepare to extract regions from image.
Extract regions from an image using a flood-fill.
unsigned num_nbrs_
The size of the nbr_delta_ array.