1 #ifndef vil_region_finder_hxx_ 2 #define vil_region_finder_hxx_ 7 # include <vcl_msvc_warnings.h> 13 template <
class pix_type,
class predicate_type>
18 processed_( image_.ni(), image_.nj(), image_.nplanes() )
27 template <
class pix_type,
class predicate_type>
32 static int const nbrs4_delta[4][2] = { { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1} };
33 static int const nbrs8_delta[8][2] = { { 1, 0}, { 1,-1}, { 0,-1}, {-1,-1},
34 {-1, 0}, {-1, 1}, { 0, 1}, { 1, 1} };
35 processed_.fill(
false );
39 nbr_delta_ = nbrs4_delta;
43 nbr_delta_ = nbrs8_delta;
46 assert(!
"Invalid connectivity type");
54 template <
class pix_type,
class predicate_type>
58 std::vector<unsigned>& ri,
59 std::vector<unsigned>& rj )
62 pix_type p = image_(i,j);
65 same_int_region( i, j, p, ri, rj );
72 template <
class pix_type,
class predicate_type>
76 std::vector<unsigned>& ri,
77 std::vector<unsigned>& rj )
80 if ( processed_(i,j) )
88 processed_(i,j) =
true;
92 for (
unsigned cur_pos = 0; cur_pos<ri.size(); ++cur_pos )
99 for (
unsigned c = 0; c < num_nbrs_; ++c )
101 unsigned nbr_i = (unsigned)( (
signed)i + nbr_delta_[c][0] );
102 unsigned nbr_j = (unsigned)( (
signed)j + nbr_delta_[c][1] );
104 if (nbr_i < image_.ni() &&
105 nbr_j < image_.nj() &&
106 !processed_(nbr_i, nbr_j) &&
107 predi_( image_( nbr_i, nbr_j ), p ) )
110 processed_(nbr_i, nbr_j) =
true;
111 ri.push_back( nbr_i );
112 rj.push_back( nbr_j );
122 template <
class pix_type,
class predicate_type>
130 template <
class pix_type,
class predicate_type>
138 #endif // vil_region_finder_hxx_
Concrete view of image data of type T held in memory.
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.
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_region_finder(image_view const &image, vil_region_finder_connectivity conn=vil_region_finder_4_conn)
Prepare to extract regions from image.