Into

Modules

Documentation

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
(
  • const PiiMatrix< T > & objects
  • UnaryOp rule
  • int startR
  • int startC
  • PiiMatrix< int > & points
)

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 >
(
  • const PiiMatrix< T > & objects
  • UnaryOp rule
)

Finds the next unhandled boundary and returns its coordinates as a N-by-2 matrix.

Static public member functions

template<class T, class UnaryOp>
static QList< PiiMatrix< int > >
(
  • const PiiMatrix< T > & objects
  • UnaryOp rule
  • PiiMatrix< unsigned char > * boundaryMask = 0
)

Extracts all outer and inner boundaries of connected pixels that match Rule with value.

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

    (
    • const PiiMatrix< T > & objects
    • UnaryOp rule
    • int startR
    • int startC
    • PiiMatrix< int > & points
    )

    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 rule returns true when compared to value will 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

    (
    • const PiiMatrix< T > & objects
    • UnaryOp rule
    )

    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 rule returns true when compared to value will 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.

  • template<class T, class UnaryOp>

    static QList< PiiMatrix< int > > findBoundaries

    (
    • const PiiMatrix< T > & objects
    • UnaryOp rule
    • PiiMatrix< unsigned char > * boundaryMask = 0
    )
    [static]

    Extracts all outer and inner boundaries of connected pixels that match Rule with value.

     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 Rule returns true when compared to value will 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.

  • template<class T>

    static PiiMatrix< int > findBoundary

    ( )
    [static]

    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.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.