dip::ChainCode struct

The contour of an object as a chain code sequence.

Contents

This class supports 4-connected and 8-connected chain codes, see the Code definition for a description of the chain codes.

A default-initialized ChainCode represents no object (Empty returns true). Set the start value to represent a 1-pixel object. Larger objects have at least two values in the chain code. A chain code with a single value is illegal.

Classes

struct CodeTable
Provides data that are helpful when processing chain codes. more...
class Code
Encodes a single chain code, as used by dip::ChainCode.

Functions

void Push(dip::ChainCode::Code const& code)
Adds a code to the end of the chain.
auto PrepareCodeTable(dip::IntegerArray const& strides) const -> dip::ChainCode::CodeTable
Returns a table that is useful when processing the chain code
static auto PrepareCodeTable(dip::uint connectivity, dip::IntegerArray const& strides) -> dip::ChainCode::CodeTable
Returns a table that is useful when processing the chain code
auto ConvertTo8Connected() const -> dip::ChainCode
Creates a new chain code object that is 8-connected and represents the same shape.
auto Empty() const -> bool
A chain code whose start value hasn’t been set is considered empty.
auto Length(dip::String const& boundaryPixels = S::EXCLUDE) const -> dip::dfloat
Returns the length of the chain code using the method by Vossepoel and Smeulders. more...
auto Feret(dip::dfloat angleStep = 5.0/180.0*pi) const -> dip::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 -> dip::dfloat
Computes the bending energy. more...
auto Area() const -> dip::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 -> dip::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 -> dip::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. more...
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 Coordinates() const -> dip::CoordinateArray
Returns the pixel coordinates for each of the pixels represented in the chain code. more...
auto Offset() const -> dip::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.

Variables

std::vector<Code> codes
The chain codes
dip::VertexInteger start = {-1,-1}
The coordinates of the start pixel, the default value is outside the image to indicate there’s no chain code here
dip::LabelType objectID = 0
The label of the object from which this chain code is taken
bool is8connected = true
Is false when connectivity = 1, true when connectivity = 2

Class documentation

struct CodeTable

Provides data that are helpful when processing chain codes.

The table is prepared using the dip::ChainCode::PrepareCodeTable method. The method takes a stride array, which is expected to have exactly two elements (as chain codes only work with 2D images). The returned table contains a value pos[code] that says how the coordinates change when moving in the direction of the code, and a value offset[code] that says how to modify the image data pointer to reach the new pixel.

pos[code] is identical to code.Delta8() or code.Delta4() (depending on connectivity).

No checking is done when indexing. If the CodeTable is derived from a 4-connected chain code, only the first four table elements can be used. Otherwise, eight table elements exist and are valid.

Variables
dip::VertexInteger const* pos Array with position offsets for each chain code.
std::array<dip::sint, 8> offset Array with pointer offsets for each chain code.

Function documentation

dip::dfloat Length(dip::String const& boundaryPixels = S::EXCLUDE) 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 by default. 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. To include those portions of the perimeter, set boundaryPixels to "include".

dip::dfloat 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 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.

dip::CoordinateArray Coordinates() const

Returns the pixel coordinates for each of the pixels represented in the chain code.

Very large coordinate values will be returned if the chain code runs outside the image on the left or top (i.e. if the pixels encoded by the chain code have negative coordinates) because the output object uses unsigned integers.