#include <gevd_contour.h>
Public Member Functions | |
gevd_contour (float min_strength, int min_length, float min_jump, float max_gap=2.236068f) | |
Save parameters and create workspace for detecting contours. | |
~gevd_contour () | |
Free space allocated for detecting contours. | |
bool | FindNetwork (gevd_bufferxy &edgels, const int njunction, const int *junctionx, const int *junctiony, vcl_vector< vtol_edge_2d_sptr > *&edges, vcl_vector< vtol_vertex_2d_sptr > *&vertices) |
Find network of linked edges and vertices, from 8-connected edge elements. | |
void | SubPixelAccuracy (vcl_vector< vtol_edge_2d_sptr > &edges, vcl_vector< vtol_vertex_2d_sptr > &vertices, const gevd_bufferxy &locationx, const gevd_bufferxy &locationy) |
Insert subpixel accuracy into the pixels on the edges/vertices. | |
void | InsertBorder (vcl_vector< vtol_edge_2d_sptr > &edges, vcl_vector< vtol_vertex_2d_sptr > &vertices) |
Insert virtual edges and vertices to enforce closure of the regions beyond the rectangular image border. | |
int | CheckInvariants (vcl_vector< vtol_edge_2d_sptr > &edges, vcl_vector< vtol_vertex_2d_sptr > &vertices) |
Check a few obvious invariants, and return number of errors. | |
Static Public Member Functions | |
static void | EqualizeSpacing (vcl_vector< vtol_edge_2d_sptr > &chains) |
Make the spacing of the chain pixels nearly equal by smoothing their locations with the average filter [1 0 1]/2. | |
static void | Translate (vcl_vector< vtol_edge_2d_sptr > &edges, vcl_vector< vtol_vertex_2d_sptr > &vertices, const float tx=0.5, const float ty=0.5) |
Translate all the pixels in the edges and vertices by (tx, ty). | |
static void | ClearNetwork (vcl_vector< vtol_edge_2d_sptr > *&edges, vcl_vector< vtol_vertex_2d_sptr > *&vertices) |
Remove and delete all elements in global lists, and set the global lists to NULL. | |
static void | MaskEdgels (const gevd_bufferxy &mask, gevd_bufferxy &edgels, int &njunction, int *junctionx, int *junctiony) |
Mask the detected edge elements and junctions with a given mask array, using AND operation, for ROI with arbitrary shapes. | |
static void | SetEdgelData (gevd_bufferxy &grad_mag, gevd_bufferxy &angle, vcl_vector< vtol_edge_2d_sptr > &edges) |
Set the orientation at each edgel on all digital curves to a continuous orientation value, which is consistent with C. | |
static int | LengthCmp (vtol_edge_2d_sptr const &dc1, vtol_edge_2d_sptr const &dc2) |
Compare function to sort the edges by their length in pixels, largest first. | |
static vcl_vector < vtol_edge_2d_sptr > * | CreateLookupTable (vcl_vector< vtol_edge_2d_sptr > &) |
Create a 2-way lookup table from list elements in set, using array and get_id/set_id. | |
static void | LookupTableInsert (vcl_vector< vtol_edge_2d_sptr > &set, vtol_edge_2d_sptr elmt) |
Insert topology object in 2-way lookup table, using Id and dynamic array. | |
static void | LookupTableReplace (vcl_vector< vtol_edge_2d_sptr > &set, vtol_edge_2d_sptr deleted, vtol_edge_2d_sptr inserted) |
Replace deleted by inserted in 2-way lookup table. | |
static void | LookupTableRemove (vcl_vector< vtol_edge_2d_sptr > &set, vtol_edge_2d_sptr elmt) |
Remove topology object from 2-way lookup table leaving an empty hole. | |
static void | LookupTableCompress (vcl_vector< vtol_edge_2d_sptr > &set) |
Eliminate empty holes in the lookup table. | |
static vcl_vector < vtol_vertex_2d_sptr > * | CreateLookupTable (vcl_vector< vtol_vertex_2d_sptr > &) |
As above for vertices. | |
static void | LookupTableInsert (vcl_vector< vtol_vertex_2d_sptr > &set, vtol_vertex_2d_sptr elmt) |
As above for vertices. | |
static void | LookupTableReplace (vcl_vector< vtol_vertex_2d_sptr > &set, vtol_vertex_2d_sptr deleted, vtol_vertex_2d_sptr inserted) |
As above for vertices. | |
static void | LookupTableRemove (vcl_vector< vtol_vertex_2d_sptr > &set, vtol_vertex_2d_sptr elmt) |
As above for vertices. | |
static void | LookupTableCompress (vcl_vector< vtol_vertex_2d_sptr > &set) |
As above for vertices. | |
static void | BeSilent () |
static void | BeTalkative () |
Protected Member Functions | |
int | FindChains (gevd_bufferxy &edgels, const int njunction, const int *junctionx, const int *junctiony, vcl_vector< vtol_edge_2d_sptr > &edges) |
Trace and collect pixels on thin contours, stronger pixels first, and favoring 4-connected over 8-connected. | |
int | FindJunctions (gevd_bufferxy &edgels, vcl_vector< vtol_edge_2d_sptr > &edges, vcl_vector< vtol_vertex_2d_sptr > &vertices) |
Find junctions from end points touching at an interior point of a chain, with detectable jump in filter response. | |
Protected Attributes | |
float | minStrength |
int | minLength |
float | minJump |
int | maxSpiral |
vbl_array_2d< vtol_edge_2d_sptr > * | edgeMap |
vbl_array_2d < vtol_vertex_2d_sptr > * | vertexMap |
Static Protected Attributes | |
static bool | talkative = true |
Definition at line 77 of file gevd_contour.h.
gevd_contour::gevd_contour | ( | float | min_strength, |
int | min_length, | ||
float | min_jump, | ||
float | max_gap = 2.236068f |
||
) |
Save parameters and create workspace for detecting contours.
Each contour must have at least 1 pixel above min_strength, and its number of internal pixels must be above min_length. This is a heuristic hysteresis scheme that prunes weak or short isolated chains. To join a weaker contour to a stronger contour, a junction must have a change in response above min_jump on the stronger contour. This way, only strong junctions are detected.
Definition at line 73 of file gevd_contour.cxx.
gevd_contour::~gevd_contour | ( | ) |
Free space allocated for detecting contours.
Definition at line 116 of file gevd_contour.cxx.
static void gevd_contour::BeSilent | ( | ) | [inline, static] |
Definition at line 135 of file gevd_contour.h.
static void gevd_contour::BeTalkative | ( | ) | [inline, static] |
Definition at line 136 of file gevd_contour.h.
int gevd_contour::CheckInvariants | ( | vcl_vector< vtol_edge_2d_sptr > & | edges, |
vcl_vector< vtol_vertex_2d_sptr > & | vertices | ||
) |
Check a few obvious invariants, and return number of errors.
0. Network has closure of all vertices and edges. 1. No 2 vertices touch: endpt/endpt, endpt/junction or junction/junction 2. No vertex connecting 2 edges, each vertex has 1 or >= 3 edges, except the 4 corners of image border. 3. Each edge has >= 3 internal pixels. 4. A chain can touch/join with itself or with a stronger chain. Junction is created only if the local change in filter response is greater than some noise threshold, set by the user. Junction is created only if the 2 broken up chains have lengths >= 3.
Definition at line 2014 of file gevd_contour.cxx.
void gevd_contour::ClearNetwork | ( | vcl_vector< vtol_edge_2d_sptr > *& | edges, |
vcl_vector< vtol_vertex_2d_sptr > *& | vertices | ||
) | [static] |
Remove and delete all elements in global lists, and set the global lists to NULL.
Remove all digital chains of edges. Edges and vertices are removed with UnProtect().
Definition at line 1749 of file gevd_contour.cxx.
vcl_vector< vtol_edge_2d_sptr > * gevd_contour::CreateLookupTable | ( | vcl_vector< vtol_edge_2d_sptr > & | set | ) | [static] |
Create a 2-way lookup table from list elements in set, using array and get_id/set_id.
Definition at line 1867 of file gevd_contour.cxx.
vcl_vector< vtol_vertex_2d_sptr > * gevd_contour::CreateLookupTable | ( | vcl_vector< vtol_vertex_2d_sptr > & | set | ) | [static] |
As above for vertices.
Definition at line 1878 of file gevd_contour.cxx.
void gevd_contour::EqualizeSpacing | ( | vcl_vector< vtol_edge_2d_sptr > & | chains | ) | [static] |
Make the spacing of the chain pixels nearly equal by smoothing their locations with the average filter [1 0 1]/2.
This will reduce square grid tessellation artefacts, and lead to more accurate estimation of the tangent direction, and local curvature angle, from finite differences in location. It is also useful to avoid weight artefacts in curve fitting caused by the periodic clustering of pixels along the chain. Truncating the float locations with int() will no longer map to the original pixels of the discrete chains.
Definition at line 1658 of file gevd_contour.cxx.
int gevd_contour::FindChains | ( | gevd_bufferxy & | edgels, |
const int | njunction, | ||
const int * | junctionx, | ||
const int * | junctiony, | ||
vcl_vector< vtol_edge_2d_sptr > & | edges | ||
) | [protected] |
Trace and collect pixels on thin contours, stronger pixels first, and favoring 4-connected over 8-connected.
Thinning is not used, and so will avoid errors because of square grid tessellation. A chain can not cross itself. It can only touch itself or another chain, in which case a junction will be found later. The pixels of a chain include the 2 end points. End points and junctions are created in gevd_contour::FindJunctions. Return the number of chains found. Protected.
Definition at line 277 of file gevd_contour.cxx.
int gevd_contour::FindJunctions | ( | gevd_bufferxy & | edgels, |
vcl_vector< vtol_edge_2d_sptr > & | edges, | ||
vcl_vector< vtol_vertex_2d_sptr > & | vertices | ||
) | [protected] |
Find junctions from end points touching at an interior point of a chain, with detectable jump in filter response.
Localize these junctions on the stronger contour to pixel accuracy, and break stronger chain into subchains. Also merge end points touching another end point or junction. Return the number of end points and junctions bounding all chains/cycles detected in gevd_contour::FindChains. Deletion/insertion to the network must be done completely, so that the connectivity links are updated. Protected.
Definition at line 1007 of file gevd_contour.cxx.
bool gevd_contour::FindNetwork | ( | gevd_bufferxy & | edgels, |
const int | njunction, | ||
const int * | junctionx, | ||
const int * | junctiony, | ||
vcl_vector< vtol_edge_2d_sptr > *& | edges, | ||
vcl_vector< vtol_vertex_2d_sptr > *& | vertices | ||
) |
Find network of linked edges and vertices, from 8-connected edge elements.
The contours must be less than 2 pixel wide, for example found from non maximum suppression. Isolated edgels and short segments are erased.
Definition at line 128 of file gevd_contour.cxx.
void gevd_contour::InsertBorder | ( | vcl_vector< vtol_edge_2d_sptr > & | edges, |
vcl_vector< vtol_vertex_2d_sptr > & | vertices | ||
) |
Insert virtual edges and vertices to enforce closure of the regions beyond the rectangular image border.
The location of the border is at 3 pixels away from the real image border, because of kernel radius in convolution and non maximum suppression. Virtual border of image should be inserted after gevd_contour::FindChains() and gevd_contour::FindJunctions().
JLM - February 1999 Modified this routine extensively to move the border to the actual image ROI bounds. Chain endpoints are extended to intersect with the border. These changes were made to support region segmentation from edgels.
Definition at line 1318 of file gevd_contour.cxx.
int gevd_contour::LengthCmp | ( | vtol_edge_2d_sptr const & | dc1, |
vtol_edge_2d_sptr const & | dc2 | ||
) | [static] |
Compare function to sort the edges by their length in pixels, largest first.
Definition at line 1857 of file gevd_contour.cxx.
void gevd_contour::LookupTableCompress | ( | vcl_vector< vtol_edge_2d_sptr > & | set | ) | [static] |
Eliminate empty holes in the lookup table.
Definition at line 1957 of file gevd_contour.cxx.
void gevd_contour::LookupTableCompress | ( | vcl_vector< vtol_vertex_2d_sptr > & | set | ) | [static] |
As above for vertices.
Definition at line 1981 of file gevd_contour.cxx.
void gevd_contour::LookupTableInsert | ( | vcl_vector< vtol_edge_2d_sptr > & | set, |
vtol_edge_2d_sptr | elmt | ||
) | [static] |
Insert topology object in 2-way lookup table, using Id and dynamic array.
Protect it in the network.
Definition at line 1892 of file gevd_contour.cxx.
void gevd_contour::LookupTableInsert | ( | vcl_vector< vtol_vertex_2d_sptr > & | set, |
vtol_vertex_2d_sptr | elmt | ||
) | [static] |
As above for vertices.
Definition at line 1902 of file gevd_contour.cxx.
void gevd_contour::LookupTableRemove | ( | vcl_vector< vtol_edge_2d_sptr > & | set, |
vtol_edge_2d_sptr | elmt | ||
) | [static] |
Remove topology object from 2-way lookup table leaving an empty hole.
Also remove object from the network.
Definition at line 1939 of file gevd_contour.cxx.
void gevd_contour::LookupTableRemove | ( | vcl_vector< vtol_vertex_2d_sptr > & | set, |
vtol_vertex_2d_sptr | elmt | ||
) | [static] |
As above for vertices.
Definition at line 1948 of file gevd_contour.cxx.
void gevd_contour::LookupTableReplace | ( | vcl_vector< vtol_edge_2d_sptr > & | set, |
vtol_edge_2d_sptr | deleted, | ||
vtol_edge_2d_sptr | inserted | ||
) | [static] |
Replace deleted by inserted in 2-way lookup table.
Also remove object from the network.
Definition at line 1913 of file gevd_contour.cxx.
void gevd_contour::LookupTableReplace | ( | vcl_vector< vtol_vertex_2d_sptr > & | set, |
vtol_vertex_2d_sptr | deleted, | ||
vtol_vertex_2d_sptr | inserted | ||
) | [static] |
As above for vertices.
Definition at line 1927 of file gevd_contour.cxx.
void gevd_contour::MaskEdgels | ( | const gevd_bufferxy & | mask, |
gevd_bufferxy & | edgels, | ||
int & | njunction, | ||
int * | junctionx, | ||
int * | junctiony | ||
) | [static] |
Mask the detected edge elements and junctions with a given mask array, using AND operation, for ROI with arbitrary shapes.
Definition at line 1781 of file gevd_contour.cxx.
void gevd_contour::SetEdgelData | ( | gevd_bufferxy & | grad_mag, |
gevd_bufferxy & | angle, | ||
vcl_vector< vtol_edge_2d_sptr > & | edges | ||
) | [static] |
Set the orientation at each edgel on all digital curves to a continuous orientation value, which is consistent with C.
Rothwell's EdgeDetector. That is theta = (180/M_PI)*atan2(dI/dy, dI/dx)
Definition at line 1809 of file gevd_contour.cxx.
void gevd_contour::SubPixelAccuracy | ( | vcl_vector< vtol_edge_2d_sptr > & | edges, |
vcl_vector< vtol_vertex_2d_sptr > & | vertices, | ||
const gevd_bufferxy & | locationx, | ||
const gevd_bufferxy & | locationy | ||
) |
Insert subpixel accuracy into the pixels on the edges/vertices.
Truncating float locations with int(xy) should map to the original pixel locations. No interpolation is done at junctions of 3 or more contours, so a junction can have location error up to 1-2 pixel, tangential to the strong contour.
Definition at line 1232 of file gevd_contour.cxx.
void gevd_contour::Translate | ( | vcl_vector< vtol_edge_2d_sptr > & | edges, |
vcl_vector< vtol_vertex_2d_sptr > & | vertices, | ||
const float | tx = 0.5 , |
||
const float | ty = 0.5 |
||
) | [static] |
Translate all the pixels in the edges and vertices by (tx, ty).
If the image is extracted from an ROI, a translation of (roi->GetOrigX(), roi->GetOrigY()) must be done to have coordinates in the reference frame of the original image. Add 0.5 if you want to display location at center of pixel instead of upper-left corner.
Definition at line 1709 of file gevd_contour.cxx.
vbl_array_2d<vtol_edge_2d_sptr>* gevd_contour::edgeMap [protected] |
Definition at line 142 of file gevd_contour.h.
int gevd_contour::maxSpiral [protected] |
Definition at line 141 of file gevd_contour.h.
float gevd_contour::minJump [protected] |
Definition at line 140 of file gevd_contour.h.
int gevd_contour::minLength [protected] |
Definition at line 139 of file gevd_contour.h.
float gevd_contour::minStrength [protected] |
Definition at line 138 of file gevd_contour.h.
bool gevd_contour::talkative = true [static, protected] |
Definition at line 154 of file gevd_contour.h.
vbl_array_2d<vtol_vertex_2d_sptr>* gevd_contour::vertexMap [protected] |
Definition at line 143 of file gevd_contour.h.