core/vil/algo/vil_blob.h
Go to the documentation of this file.
00001 #ifndef vil_blob_h_
00002 #define vil_blob_h_
00003 //:
00004 // \file
00005 // \brief Finds connected regions in a boolean image.
00006 // \author Ian Scott
00007 // Thes functions can be combined to get blobs as images, chorded regions, edge pixels lists, etc.
00008 // For example to get an edge pixel list of im_binary
00009 // \code
00010 // vil_blob_labels(im_binary, vil_blob_4_conn, im_labels);
00011 // vil_blob_labels_to_edge_labels(im_binary, vil_blob_4_conn, im_labels);
00012 // vil_blob_labels_to_pixel_lists(im_edges, pixel_lists);
00013 // \endcode
00014 // To get the area of a blob efficiently
00015 // \code
00016 // vil_blob_labels(im_binary, vil_blob_4_conn, im_labels);
00017 // vil_blob_labels_to_regions(im_edges, regions);
00018 // unsigned area_of_first_blob = vil_area(regions[0]);
00019 // \endcode
00020 
00021 #include <vcl_vector.h>
00022 #include <vcl_utility.h>
00023 #include <vil/vil_image_view.h>
00024 #include <vil/vil_chord.h>
00025 
00026 //: Specify 4- or 8- neighbour connectivity
00027 enum vil_blob_connectivity
00028 {
00029   vil_blob_4_conn,
00030   vil_blob_8_conn
00031 };
00032 
00033 
00034 //: Produce a label image that enumerates all disjoint blobs in a binary image
00035 void vil_blob_labels(const vil_image_view<bool>& src_binary,
00036                      vil_blob_connectivity conn,
00037                      vil_image_view<unsigned>& dest_label);
00038 
00039 //: Set all non-blob-edge pixels in a blob label image to zero.
00040 // A 4-conn edge is a 4-conn area itself, and not just those pixels which have dissimilar
00041 // 4-conn neighbours.
00042 void vil_blob_labels_to_edge_labels(const vil_image_view<unsigned>& src_label,
00043                                     vil_blob_connectivity conn,
00044                                     vil_image_view<unsigned>& dest_label);
00045 
00046 
00047 //: A region is a vector of chords that came from a connected blob.
00048 typedef vcl_vector<vil_chord> vil_blob_region;
00049 
00050 //: Convert a label image into a list of chorded regions.
00051 // A blob label value of n will be returned in dest_regions[n-1].
00052 void vil_blob_labels_to_regions(const vil_image_view<unsigned>& src_label,
00053                                 vcl_vector<vil_blob_region>& dest_regions);
00054 
00055 
00056 //: A pixel list is a vector of <i,j> pixel positions.
00057 typedef vcl_vector<vcl_pair<unsigned, unsigned> > vil_blob_pixel_list;
00058 
00059 //: Convert a label image into a list of pixel lists.
00060 // A blob label value of n will be returned in dest_pixels_lists[n-1].
00061 void vil_blob_labels_to_pixel_lists(const vil_image_view<unsigned>& src_label,
00062                                     vcl_vector<vil_blob_pixel_list>& dest_pixel_lists);
00063 
00064 #endif