classPiiBoundaryFinder
#include <PiiBoundaryFinder.h>
An algorithm that traverses object boundaries.
Description
The typical use of this class is to detect the boundaries of objects in binary images. The algorithm extacts both outer and inner boundaries in the order they are first found in the image. Each boundary is represented as a matrix in which each row stores the (x,y) coordinates of a pixel on the boundary.
Constructors and destructor
|
Constructs a new boundary finder. |
|
Public member functions
|
PiiMatrix< unsigned char
>
|
( )
Returns the boundary mask. |
|
template<class T, class UnaryOp>
int
|
Extracts the boundary of an object. |
|
template<class T, class UnaryOp>
int
|
Finds the next unhandled boundary and stores its coordinates to points. |
|
template<class T, class UnaryOp>
PiiMatrix< int >
|
Finds the next unhandled boundary and returns its coordinates as a N-by-2 matrix. |
Static public member functions
|
template<class T, class UnaryOp>
|
Extracts all outer and inner boundaries of connected pixels that
match |
|
template<class T>
static PiiMatrix< int
>
|
A convenience function that returns the outer boundary of a single labeled object. |
Function details
-
PiiBoundaryFinder
Constructs a new boundary finder.
Parameters
- objects
-
find boundaries in this image. The image is only used for initializing the parameters of the algorithm and will not be stored.
- boundaryMask
-
draw boundaries to this mask as they are traversed. Right and bottom edges will be marked with ones, left and top edges with twos and double edges with three.
-
~PiiBoundaryFinder
() -
PiiMatrix< unsigned char > boundaryMask
()Returns the boundary mask.
After each iteration (findNextBoundary()), all detected boundaries are marked into this mask. Right and bottom edges are be marked with ones, left and top edges with twos and double edges with three.
-
template<class T, class UnaryOp>
int findBoundary
Extracts the boundary of an object.
The boundary is traversed clockwise, and the coordinates of found boundary points will be stored in the returned matrix.
Parameters
- objects
-
the detected objects. Each pixel to which
rulereturnstruewhen compared tovaluewill be treated as an object. Other pixels are treated as non-objects. - rule
-
the decision rule to match object pixels.
- startR
-
the row index of the starting point at the object's boundary.
- startC
-
the column index of the starting point at the object's boundary.
- points
-
the coordinates of the object's boundary pixels will be appended to this matrix. Each row of the matrix will contain the x and y coordinates of a boundary point, in this order. The last point will be equal to the first one. Thus, the points can be turned into vectors by calculating the difference between successive rows.
Returns
the number of boundary points found
-
template<class T, class UnaryOp>
int findNextBoundary
Finds the next unhandled boundary and stores its coordinates to points.
Returns the number of boundary points appended to points, or zero if no more boundaries can be found.
-
template<class T, class UnaryOp>
PiiMatrix< int > findNextBoundary
Finds the next unhandled boundary and returns its coordinates as a N-by-2 matrix.
Boundaries are searched from bottom to top.
Parameters
- objects
-
the detected objects. Each pixel to which
rulereturnstruewhen compared tovaluewill be treated as an object. Other pixels are treated as non-objects. - rule
-
the decision rule to match object pixels.
Returns
The coordinates of the object's boundary pixels. Each row of the matrix contains the x and y coordinates of a boundary point, in this order. The last point will be equal to the first one. Thus, the points can be turned into vectors by calculating the difference between successive rows. If no more boundaries can be found, an empty matrix will be returned.
-
Extracts all outer and inner boundaries of connected pixels that match
Rulewithvalue.PiiMatrix<int> objects(8,8, 0,1,2,0,1,1,0,0, 0,2,2,0,1,1,0,0, 0,2,2,0,0,0,0,0, 0,2,2,1,1,1,1,0, 0,2,2,0,0,0,1,0, 0,2,2,2,2,3,1,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0); // Everything other than zero is an object QList<PiiMatrix<int> > coordinates(findBoundaries(objects, std::bind2nd(std::not_equal_to<int>(), 0))); // The list now has 3 entries, one for the large L-shaped object // with a hole, another for the hole, and one for the small // square of ones.
Parameters
- objects
-
the detected objects. Each pixel to which
Rulereturnstruewhen compared tovaluewill be treated as an object. Other pixels are treated as non-objects. - rule
-
the decision rule to match object pixels.
- boundaryMask
-
draw boundaries to this mask as they are traversed. The size of the mask matrix will be adjusted to match
objects.
Returns
a list of boundary coordinate matrices. One matrix will be returned for each outer or inner boundary. Each row of a coordinate matrix will contain the x and y coordinates of a boundary point, in this order. The last point will be equal to the first one.
-
A convenience function that returns the outer boundary of a single labeled object.
Parameters
- objects
-
a labeled image
- label
-
the object label to look for
- boundaryMask
-
mark the outer edge to this matrix, if non-zero.
Returns
the boundary coordinates, or an empty matrix if the label is not found.
Add a note
Not a single note added yet. Be the first, add yours.