00001 #ifndef sdet_watershed_region_proc_h_ 00002 #define sdet_watershed_region_proc_h_ 00003 //--------------------------------------------------------------------- 00004 //: 00005 // \file 00006 // \brief a processor for extracting watershed regions 00007 // 00008 // uses a watershed algorithm to define regions 00009 // 00010 // \author 00011 // J.L. Mundy - July 11, 2004 00012 // 00013 // \verbatim 00014 // Modifications 00015 // none 00016 // \endverbatim 00017 // 00018 //------------------------------------------------------------------------- 00019 #include <vcl_vector.h> 00020 #include <vcl_map.h> 00021 #include <vbl/vbl_array_2d.h> 00022 #include <vil1/vil1_memory_image_of.h> 00023 #include <vil1/vil1_image.h> 00024 #include <brip/brip_roi_sptr.h> 00025 #include <vsol/vsol_box_2d_sptr.h> 00026 #include <vsol/vsol_polygon_2d_sptr.h> 00027 #include <sdet/sdet_region_sptr.h> 00028 #include <sdet/sdet_watershed_region_proc_params.h> 00029 00030 class sdet_watershed_region_proc : public sdet_watershed_region_proc_params 00031 { 00032 public: 00033 enum priority_code{DARK=0, LIGHT, BIG, SMALL}; 00034 //Constructors/destructor 00035 sdet_watershed_region_proc(sdet_watershed_region_proc_params& wrpp); 00036 00037 ~sdet_watershed_region_proc(); 00038 //Accessors 00039 //:set image and potentially clip 00040 void set_image(vil1_image const& image, 00041 vsol_box_2d_sptr const& box = vsol_box_2d_sptr()); 00042 //:set image roi 00043 void set_roi(brip_roi_sptr const& roi); 00044 brip_roi_sptr roi(){return roi_;} 00045 00046 //:clip image assuming image and roi are set 00047 void clip_image(); 00048 00049 vil1_memory_image_of<float> image() const {return image_;} 00050 vil1_memory_image_of<float> clip() const {return clip_;} 00051 00052 //clear region array 00053 void clear(); 00054 00055 vcl_vector<sdet_region_sptr>& regions(){return regions_;} 00056 00057 //Utility Methods 00058 bool extract_regions(); 00059 bool merge_regions(); 00060 vil1_image get_residual_image(); 00061 00062 //Debug methods 00063 void print_region_info(); 00064 vil1_image overlay_image(){return overlay_image_;} 00065 vil1_image region_image(); 00066 vcl_vector<vsol_polygon_2d_sptr> boundaries(); 00067 protected: 00068 //protected methods 00069 void chip_out_roi(vil1_image& image); 00070 void scan_region_data(vbl_array_2d<unsigned int> const & lab_array); 00071 00072 bool add_adjacency(sdet_region_sptr const& reg, 00073 sdet_region_sptr const& adj_reg); 00074 bool remove_adjacencies(sdet_region_sptr const& reg); 00075 bool adjacent_regions(sdet_region_sptr const& reg, 00076 vcl_vector<sdet_region_sptr>& adj_regs); 00077 bool compute_region_image(); 00078 void compute_boundaries(); 00079 //members 00080 int x0_; 00081 int y0_; 00082 int xs_; 00083 int ys_; 00084 bool regions_valid_; //process state flag 00085 bool region_image_valid_; 00086 bool boundaries_valid_; 00087 unsigned int min_label_; 00088 unsigned int max_label_; 00089 vil1_memory_image_of<float> image_; //input image 00090 vil1_memory_image_of<float> clip_; //clipped input image 00091 brip_roi_sptr roi_; 00092 vil1_image overlay_image_; // for display of original watershed regions 00093 vil1_memory_image_of<unsigned char> region_image_; //for display of digital regions 00094 vcl_vector<sdet_region_sptr> regions_; //resulting intensity faces 00095 vcl_map<sdet_region_sptr, vcl_vector<sdet_region_sptr>* > region_adjacency_; 00096 vcl_vector<vsol_polygon_2d_sptr> boundaries_; 00097 }; 00098 00099 #endif // sdet_watershed_region_proc_h_