#include <vil_blob_finder.h>
Class to iterate through image, finding boundaries of all regions (connected true pixels).
Can deal with both 4-connected and 8-connected regions.
Note that the usual use of the class copies the boolean image input, then erases the true pixels as it goes through finding the blobs (in order to avoid finding the same blob twice). If the image is expendable, then the deep copy can be avoided using set_work_image(im). In this case the supplied image (im) will be erased as the blob finder goes about it's humble task.
Where a blob has holes, only the outside of the blob is located. The algorithm will locate nested blobs (ie a blob within a hole inside another blob).
vcl_vector<int> bi,bj; vil_blob_finder finder(bool_image); while (finder.next_4con_region(bi,bj)) { vcl_cout<<"Blob boundary length: "<<bi.size()<<vcl_endl; }
Alternatively we can get the internal pixels (including the boundary) of each blob. A region is represented as a vcl_vector<vil_chord>, a set of rows of pixels which make up all the pixels in the region.
vcl_vector<vil_chord> region; vil_blob_finder finder(bool_image); while (finder.next_4con_region(region)) { vcl_cout<<"Blob area: "<<vil_area(region)<<vcl_endl; }
Definition at line 52 of file vil_blob_finder.h.
Public Member Functions | |
| vil_blob_finder () | |
| Default constructor. | |
| vil_blob_finder (const vil_image_view< bool > &image) | |
| Construct to work on image (takes deep copy). | |
| void | set_image (const vil_image_view< bool > &image) |
| Define image to work on (deep copy taken). | |
| void | set_work_image (vil_image_view< bool > &image) |
| Define image to work on and use as workspace. | |
| bool | next_4con_region (vcl_vector< int > &bi, vcl_vector< int > &bj) |
| Get boundary pixels of next blob in current image. | |
| bool | next_4con_region (vcl_vector< vil_chord > ®ion) |
| Get pixels of next blob in current image. | |
| void | longest_4con_boundary (vcl_vector< int > &bi, vcl_vector< int > &bj) |
| Get longest blob boundary in current image. | |
| unsigned | largest_4con_region (vcl_vector< vil_chord > ®ion) |
| Get largest blob region in current image. | |
| unsigned | n_4con_regions (const vil_image_view< bool > &image) |
| Get number of blobs in given image. | |
| bool | next_8con_region (vcl_vector< int > &bi, vcl_vector< int > &bj) |
| Get boundary pixels of next blob in current image. | |
| bool | next_8con_region (vcl_vector< vil_chord > ®ion) |
| Get pixels of next blob in current image. | |
| void | longest_8con_boundary (vcl_vector< int > &bi, vcl_vector< int > &bj) |
| Get longest blob boundary in current image. | |
| unsigned | largest_8con_region (vcl_vector< vil_chord > ®ion) |
| Get largest blob region in current image. | |
| unsigned | n_8con_regions (const vil_image_view< bool > &image) |
| Get number of blobs in given image. | |
Private Attributes | |
| vil_image_view< bool > | image_ |
| Workspace (may be view of external image). | |
| unsigned int | i_ |
| Current point of interest. | |
| unsigned int | j_ |
| vil_blob_finder::vil_blob_finder | ( | ) |
| vil_blob_finder::vil_blob_finder | ( | const vil_image_view< bool > & | image | ) |
| void vil_blob_finder::set_image | ( | const vil_image_view< bool > & | image | ) |
| void vil_blob_finder::set_work_image | ( | vil_image_view< bool > & | image | ) |
Define image to work on and use as workspace.
Image will be erased during process. Avoids the deep copy in set_image()
Image will be erased during process. Avoids the copy in set_image()
Definition at line 31 of file vil_blob_finder.cxx.
| bool vil_blob_finder::next_4con_region | ( | vcl_vector< int > & | bi, | |
| vcl_vector< int > & | bj | |||
| ) |
Get boundary pixels of next blob in current image.
Uses four connected boundary representation. Return false if no more regions
Uses four connected boundary representation. Return false if no more regions
Definition at line 60 of file vil_blob_finder.cxx.
| bool vil_blob_finder::next_4con_region | ( | vcl_vector< vil_chord > & | region | ) |
Get pixels of next blob in current image.
Uses 4 connected representation. Return false if no more regions
Uses four connected boundary representation. Return false if no more regions
Definition at line 83 of file vil_blob_finder.cxx.
| void vil_blob_finder::longest_4con_boundary | ( | vcl_vector< int > & | bi, | |
| vcl_vector< int > & | bj | |||
| ) |
Get longest blob boundary in current image.
Assumes image has been initialised, and that next_4con_region not yet called. Erases internal image during this call, so any subsequent calls will not work.
bi,bj empty if no blobs found.
Assumes image has been initialised, and that next_4con_region not yet called. Erases internal image during this call, so any subsequent calls will not work.
Definition at line 130 of file vil_blob_finder.cxx.
| unsigned vil_blob_finder::largest_4con_region | ( | vcl_vector< vil_chord > & | region | ) |
Get largest blob region in current image.
Assumes image has been initialised, and that next_8con_region not yet called. Erases internal image during this call, so any subsequent calls will not work.
region empty if no blobs found. Returns area of largest region
Definition at line 217 of file vil_blob_finder.cxx.
| unsigned vil_blob_finder::n_4con_regions | ( | const vil_image_view< bool > & | image | ) |
Get number of blobs in given image.
Overrides any internal state
Definition at line 145 of file vil_blob_finder.cxx.
| bool vil_blob_finder::next_8con_region | ( | vcl_vector< int > & | bi, | |
| vcl_vector< int > & | bj | |||
| ) |
Get boundary pixels of next blob in current image.
Uses 8 connected boundary representation. Return false if no more regions
Uses four connected boundary representation. Return false if no more regions
Definition at line 160 of file vil_blob_finder.cxx.
| bool vil_blob_finder::next_8con_region | ( | vcl_vector< vil_chord > & | region | ) |
Get pixels of next blob in current image.
Uses 8 connected representation. Return false if no more regions
Uses 8 connected boundary representation. Return false if no more regions
Definition at line 106 of file vil_blob_finder.cxx.
| void vil_blob_finder::longest_8con_boundary | ( | vcl_vector< int > & | bi, | |
| vcl_vector< int > & | bj | |||
| ) |
Get longest blob boundary in current image.
Assumes image has been initialised, and that next_8con_region not yet called. Erases internal image during this call, so any subsequent calls will not work.
bi,bj empty if no blobs found.
Assumes image has been initialised, and that next_8con_region not yet called. Erases internal image during this call, so any subsequent calls will not work.
Definition at line 184 of file vil_blob_finder.cxx.
| unsigned vil_blob_finder::largest_8con_region | ( | vcl_vector< vil_chord > & | region | ) |
Get largest blob region in current image.
Assumes image has been initialised, and that next_8con_region not yet called. Erases internal image during this call, so any subsequent calls will not work.
region empty if no blobs found. Returns area of largest region
Definition at line 199 of file vil_blob_finder.cxx.
| unsigned vil_blob_finder::n_8con_regions | ( | const vil_image_view< bool > & | image | ) |
Get number of blobs in given image.
Overrides any internal state
Definition at line 235 of file vil_blob_finder.cxx.
vil_image_view<bool> vil_blob_finder::image_ [private] |
unsigned int vil_blob_finder::i_ [private] |
unsigned int vil_blob_finder::j_ [private] |
Definition at line 59 of file vil_blob_finder.h.
1.5.5