ChainCode struct
The contour of an object as a chain code sequence.
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
- class Code
- Encodes a single chain code, as used by
dip::ChainCode. more... - struct CodeTable
- Provides data that are helpful when processing chain codes. more...
Functions
- 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 BendingEnergy() const -> dip::dfloat
- Computes the bending energy. more...
- auto BoundingBox() const -> dip::BoundingBoxInteger
- Finds the bounding box for the object described by the chain code.
- 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 ConvertTo8Connected() const -> dip::ChainCode
- Creates a new chain code object that is 8-connected and represents the same shape.
- auto ConvexHull() const -> dip::ConvexHull
- Returns the convex hull of the object, see
dip::ChainCode::Polygon. - auto Coordinates() const -> dip::CoordinateArray
- Returns the pixel coordinates for each of the pixels represented in the chain code. more...
- auto Empty() const -> bool
- A chain code whose
startvalue hasn’t been set is considered empty. - 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 usedip::ConvexHull::Feret. - 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 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 LongestRun() const -> dip::uint
- Returns the length of the longest run of identical chain codes.
- 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.
- auto Polygon(dip::String const& borderCodes = S::KEEP) const -> dip::Polygon
- Returns a polygon representation of the object. more...
- 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
- void Push(dip::ChainCode::Code const& code)
- Adds a code to the end of the chain.
Variables
- std::vector<Code> codes
- The chain codes
- bool is8connected = true
- Is false when connectivity = 1, true when connectivity = 2
- dip::LabelType objectID = 0
- The label of the object from which this chain code is taken
- 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
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. |
Alias documentation
using dip:: ChainCodeArray = std::vector<ChainCode>
A collection of object contours.
Function documentation
void Push( dip::ChainCode::Code const& code)
Adds a code to the end of the chain.
dip::ChainCode::CodeTable PrepareCodeTable( dip::IntegerArray const& strides) const
Returns a table that is useful when processing the chain code
static dip::ChainCode::CodeTable PrepareCodeTable( dip::uint connectivity, dip::IntegerArray const& strides)
Returns a table that is useful when processing the chain code
dip::ChainCode ConvertTo8Connected( ) const
Creates a new chain code object that is 8-connected and represents the same shape.
bool Empty( ) const
A chain code whose start value hasn’t been set is considered empty.
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::FeretValues Feret( dip::dfloat angleStep = 5.0/180.0*pi) const
Returns the Feret diameters, using an angular step size in radian of angleStep.
It is better to use dip::ConvexHull::Feret.
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::dfloat Area( ) const
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.
dip::VertexFloat Centroid( ) const
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.
dip::BoundingBoxInteger BoundingBox( ) const
Finds the bounding box for the object described by the chain code.
dip::uint LongestRun( ) const
Returns the length of the longest run of identical chain codes.
dip::Polygon Polygon( dip::String const& borderCodes = S::KEEP) 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.
If borderCodes is "keep" (the default), then the output polygon will have vertices for the
full chain code. If it is "lose", then the chain codes that go along the image border will
be ignored; the polygon will still follow that edge of the object, but there will be no vertices
along that edge.
dip::ConvexHull ConvexHull( ) const
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.
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.
dip::ChainCode Offset( ) const
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.
Variable documentation
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