public class ConnectedComponent extends PixelSet
Nothing stops an unconnected component being constructed, but it is important
to realise that some methods may return unexpected results (e.g. boundary
tracing). If you are only dealing with unconnected pixel sets, use the
PixelSet
superclass instead.
Modifier and Type | Class and Description |
---|---|
static class |
ConnectedComponent.ConnectMode
For boundary representations of
ConnectedComponent s, this enum
determines and specifies how the boundary is calculated; either using a
4-connected rule, or an 8-connected rule. |
Constructor and Description |
---|
ConnectedComponent()
Default constructor.
|
ConnectedComponent(FImage mask,
float thresh)
Constructs a connected component from a mask image.
|
ConnectedComponent(int[][] img)
Constructs a connected component from a mask image.
|
ConnectedComponent(int x,
int y,
int w,
int h)
Construct a rectangular
ConnectedComponent . |
ConnectedComponent(Polygon poly)
Construct a new connected component from the given polygon.
|
ConnectedComponent(Set<Pixel> pixels)
Construct a connected component from the given set of
Pixel s. |
ConnectedComponent(Shape shape)
Construct a new connected component from the given shape.
|
Modifier and Type | Method and Description |
---|---|
String |
asciiHeader()
Header for ascii input.
|
byte[] |
binaryHeader()
Header for binary input.
|
double |
calculateAreaRatio(ConnectedComponent ch)
Calculate the ratio of the area of the given connected component to the
area of the connected component.
|
double |
calculateAreaRatio(Polygon ch)
Calculate the ratio of the area of the given polygon to the area of this
connected component.
|
gnu.trove.list.array.TFloatArrayList |
calculateBoundaryDistanceFromCentre()
Calculates the distance from the centroid of every pixel on the
8-connected boundary of this component.
|
protected Polygon |
calculateConvexHull_AndrewsMontone()
Calculate the convex hull using Andrew's monotone chain 2D convex hull
algorithm.
|
protected Polygon |
calculateConvexHull_Melkman(List<Pixel> V)
Calculate convex hull using Melkman's algorithm.
|
Polygon |
calculateConvexHull()
Calculates the convex hull polygon for this connected component using
Andrew's montone algorithm.
|
RotatedRectangle |
calculateOrientatedBoundingBox()
Calculates the polygon that defines the minimum bounding box that best
fits the connected component, at whatever angle that may be.
|
double |
calculateOrientatedBoundingBoxAspectRatio()
Compute the aspect ratio of the oriented bounding box.
|
double |
calculatePercentageConvexHullFit()
Calculate the ratio of the area of this component's convex hull to the
actual area of this connected component.
|
ConnectedComponent |
clone()
Performs a deep copy on the connected component; that is, all pixels are
also cloned.
|
protected int |
code4(Pixel current,
Pixel next)
For the two pixels, determines the 4-connected chain code that will move
from the first pixel to the next.
|
protected int |
code8(Pixel current,
Pixel next)
For the two pixels, determines the 8-connected chain code that will move
from the first pixel to the next.
|
int |
estimateNumberOfVertices(int smoothWidth,
int windowWidth)
Estimates how many vertices are required to encode the boundary with the
given smoothness and window width.
|
static ConnectedComponent |
floodFill(FImage image,
Pixel start)
Performs a flood fill on the given image starting at the given pixel.
|
gnu.trove.list.array.TIntArrayList |
freemanChainCode(ConnectedComponent.ConnectMode mode)
Calculates the Freeman chaincode for this connected component.
|
List<Pixel> |
getInnerBoundary(ConnectedComponent.ConnectMode mode)
Returns an ordered list of pixels that are on the inner boundary of the
shape.
|
List<Pixel> |
getOuterBoundary()
Returns an ordered list of pixels that are on the outer boundary of the
shape.
|
protected int |
isLeft(Pixel P0,
Pixel P1,
Pixel P2) |
protected Pixel |
nextEdgePixelACW4(Pixel current,
int lastdir)
Returns the next edge pixel when tracing a boundary in a 4-connected
system.
|
protected Pixel |
nextEdgePixelACW4(Pixel current,
int lastdir,
List<Pixel> outer)
Returns the next edge pixel when tracing a boundary in a 4-connected
system.
|
protected Pixel |
nextEdgePixelACW8(Pixel current,
int lastdir)
Returns the next edge pixel when tracing a boundary in an 8-connected
system.
|
static void |
process(Collection<ConnectedComponent> components,
ConnectedComponentProcessor p)
Process the given set of connected components with the given
ConnectedComponentProcessor . |
ConnectedComponent |
process(ConnectedComponentProcessor p)
Process this connected component with the given
ConnectedComponentProcessor and returns a new component
containing the result. |
ConnectedComponent |
processInplace(ConnectedComponentProcessor p)
Process a connected component with the given
ConnectedComponentProcessor . |
Polygon |
toPolygon()
Converts this connected component into a
Polygon representation
by performing a 4-connected boundary trace and converting the resulting
pixels into vertices. |
addPixel, addPixel, bottomRightMostPixel, calculateArea, calculateAverageHeightWidth, calculateAverageHeightWidth, calculateBinaryMask, calculateCentroid, calculateCentroidPixel, calculateDirection, calculateMoment, calculateMoment, calculateMomentNormalised, calculateRegularBoundingBox, calculateRegularBoundingBoxAspectRatio, crop, extractPixels1d, extractPixels1d, extractPixels2d, find, find, fromShape, getPixels, iterator, merge, normMatrix, readASCII, readBinary, reposition, toFImage, toFImage, topLeftMostPixel, toString, toStringImage, transform, translate, writeASCII, writeBinary
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public ConnectedComponent()
public ConnectedComponent(Shape shape)
shape
- The shape from which to construct the connected component.public ConnectedComponent(Polygon poly)
poly
- The polygon from which to construct the connected component.public ConnectedComponent(int x, int y, int w, int h)
ConnectedComponent
. Pixels are created
for the area within the rectangle but these will not have any specific
value as they are not associated to any particular image.x
- The top-left x-coordinate of the rectangley
- The top-left y-coordinate of the rectanglew
- The width of the rectangleh
- The height of the rectanglepublic ConnectedComponent(int[][] img)
img
- The mask image to construct a connected component from.public ConnectedComponent(FImage mask, float thresh)
mask
- The mask image to construct a connected component from.thresh
- the threshold value.public ConnectedComponent(Set<Pixel> pixels)
Pixel
s. The
pixels are shallow copied into the connected component. If the pixels do
not form a connected component then some methods in this class may not
return expected results.public int estimateNumberOfVertices(int smoothWidth, int windowWidth)
smoothWidth
- The smoothness of the resulting boundarywindowWidth
- The number of edge points to considerpublic Polygon calculateConvexHull()
public double calculateAreaRatio(ConnectedComponent ch)
ch
- The connected component to test.public double calculateAreaRatio(Polygon ch)
ch
- The polygon to test again.public double calculatePercentageConvexHullFit()
protected Polygon calculateConvexHull_Melkman(List<Pixel> V)
Copyright 2001, softSurfer (www.softsurfer.com) This code may be freely used and modified for any purpose providing that this copyright notice is included with it. SoftSurfer makes no warranty for this code, and cannot be held liable for any real or imagined damage resulting from its use. Users of this code must verify correctness for their application.
V
- List of pixels containing within the regionprotected Polygon calculateConvexHull_AndrewsMontone()
protected Pixel nextEdgePixelACW4(Pixel current, int lastdir)
current
- The current pixellastdir
- The last direction traversedprotected Pixel nextEdgePixelACW4(Pixel current, int lastdir, List<Pixel> outer)
current
- The current pixellastdir
- The last direction traversedouter
- A list to fill with the outer boundaryprotected Pixel nextEdgePixelACW8(Pixel current, int lastdir)
current
- The current pixellastdir
- The last direction traversedprotected int code4(Pixel current, Pixel next)
current
- The current pixelnext
- The next pixelprotected int code8(Pixel current, Pixel next)
current
- The current pixelnext
- The next pixelpublic Polygon toPolygon()
Polygon
representation
by performing a 4-connected boundary trace and converting the resulting
pixels into vertices.Polygon
representing the inner boundary of the
component.public List<Pixel> getInnerBoundary(ConnectedComponent.ConnectMode mode)
PixelSet.topLeftMostPixel()
.mode
- The ConnectedComponent.ConnectMode
to use.public List<Pixel> getOuterBoundary()
public gnu.trove.list.array.TIntArrayList freemanChainCode(ConnectedComponent.ConnectMode mode)
The Freeman chaincode is a means for encoding the paths between nodes on the boundary of a shape, thereby reducing the encoding of a shape to a single start coordinate and a list of direction codes. The Freeman direction codes are 0-4 for 4-connected boundaries and 0-7 for 8-connected boundaries.
mode
- 4 or 8 connectivitypublic static void process(Collection<ConnectedComponent> components, ConnectedComponentProcessor p)
ConnectedComponentProcessor
.components
- The components to processp
- The process to process the components withpublic ConnectedComponent process(ConnectedComponentProcessor p)
ConnectedComponentProcessor
and returns a new component
containing the result.p
- The processor to process this component withpublic ConnectedComponent processInplace(ConnectedComponentProcessor p)
ConnectedComponentProcessor
. Side-affects this component.p
- The processor to process this component withpublic static ConnectedComponent floodFill(FImage image, Pixel start)
ConnectedComponent
.image
- The image on which to perform a flood fillstart
- The start pixel to begin the floodpublic ConnectedComponent clone()
public gnu.trove.list.array.TFloatArrayList calculateBoundaryDistanceFromCentre()
TFloatArrayList
that contains the list of distances (in order of the boundary).TFloatArrayList
) of distances of boundary points
to the centroid.public String asciiHeader()
ReadableASCII
asciiHeader
in interface ReadableASCII
asciiHeader
in interface WriteableASCII
asciiHeader
in class PixelSet
public byte[] binaryHeader()
ReadableBinary
binaryHeader
in interface ReadableBinary
binaryHeader
in interface WriteableBinary
binaryHeader
in class PixelSet
public double calculateOrientatedBoundingBoxAspectRatio()
public RotatedRectangle calculateOrientatedBoundingBox()
RotatedRectangle
that defines the minimum bounding box.