dip::ChainCode struct

The contour of an object as a chain code sequence.

Public types

class Code
Encodes a single chain code, as used by dip::ChainCode. Chain codes are between 0 and 3 for connectivity = 1, and between 0 and 7 for connectivity = 2. The border flag marks pixels at the border of the image.
struct CodeTable
Provides data that are helpful when processing chain codes.

Public functions

void Push(Code const& code)
Adds a code to the end of the chain.
auto PrepareCodeTable(IntegerArray const& strides) const -> CodeTable
Returns a table that is useful when processing the chain code.
auto ConvertTo8Connected() const -> ChainCode
Creates a new chain code object that is 8-connected and represents the same shape.
auto Length() const -> dfloat
Returns the length of the chain code using the method by Vossepoel and Smeulders.
auto Feret(dfloat angleStep = 5.0/180.0*pi) const -> FeretValues
Returns the Feret diameters, using an angular step size in radian of angleStep. It is better to use dip::ConvexHull::Feret.
auto BendingEnergy() const -> dfloat
auto Area() const -> dfloat
Computes the area of the solid object described by the chain code. Uses the result of dip::ChainCode::Polygon, so if you plan to do multiple similar measures, extract the polygon and compute the measures on that.
auto Centroid() const -> VertexFloat
Computes the centroid of the solid object described by the chain code. Uses the result of dip::ChainCode::Polygon, so if you plan to do multiple similar measures, extract the polygon and compute the measures on that.
auto BoundingBox() const -> BoundingBoxInteger
Finds the bounding box for the object described by the chain code.
auto LongestRun() const -> dip::uint
Returns the length of the longest run of identical chain codes.
auto Polygon() const -> dip::Polygon
Returns a polygon representation of the object.
auto ConvexHull() const -> dip::ConvexHull
Returns the convex hull of the object, see dip::ChainCode::Polygon.
void Image(dip::Image& out) const
Paints the pixels traced by the chain code in a binary image. The image has the size of the dip::ChainCode::BoundingBox.
auto Offset() const -> ChainCode
Create a new chain code that goes around the object in the same direction, but traces the background pixels that are 4-connected to the object. That is, it grows the object by one pixel. Only defined for 8-connected chain codes.

Public variables

std::vector<Code> codes
The chain codes.
VertexInteger start
The coordinates of the start pixel.
dip::uint objectID
The label of the object from which this chain code is taken.
bool is8connected
Is false when connectivity = 1, true when connectivity = 2.

Public static functions

static auto PrepareCodeTable(dip::uint connectivity, IntegerArray const& strides) -> CodeTable
Returns a table that is useful when processing the chain code.

Function documentation

dfloat dip::ChainCode::Length() const

Returns the length of the chain code using the method by Vossepoel and Smeulders.

If the chain code represents the closed contour of an object, add π to the result to determine the object's perimeter.

Any portions of the chain code that run along the image edge are not measured. That is, for an object that is only partially inside the image, the portion of the object's perimeter that is inside of the image is measured, the edge created by cutting the object is not.

dfloat dip::ChainCode::BendingEnergy() const

Computes the bending energy.

Computes the bending energy directly from the chain code. The algorithm is rather imprecise. It is better to use dip::Polygon::BendingEnergy.

dip::Polygon dip::ChainCode::Polygon() const

Returns a polygon representation of the object.

Creates a polygon by joining the mid-points between an object pixel and a background pixel that are edge-connected neighbors. The polygon follows the "crack" between pixels, but without the biases one gets when joining pixel vertices into a polygon. The polygon always has an area exactly half a pixel smaller than the solid binary object it represents.

This idea comes from Steve Eddins: http://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/