public class PixelSet extends Object implements Cloneable, ReadWriteable, Iterable<Pixel>
Modifier and Type | Field and Description |
---|---|
Set<Pixel> |
pixels
The set of pixels within this connected component
|
Constructor and Description |
---|
PixelSet()
Default constructor; makes an empty PixelSet
|
PixelSet(FImage mask,
float thresh)
Constructs a PixelSet from a mask image.
|
PixelSet(int[][] img)
Constructs a PixelSet from a mask image.
|
PixelSet(int x,
int y,
int w,
int h)
Construct a rectangular
PixelSet . |
PixelSet(Set<Pixel> pixels)
Construct a PixelSet from the given set of
Pixel s. |
Modifier and Type | Method and Description |
---|---|
void |
addPixel(int x,
int y)
Add a pixel into this connected component.
|
void |
addPixel(Pixel p)
Add a pixel into this connected component.
|
String |
asciiHeader()
Header for ascii input.
|
byte[] |
binaryHeader()
Header for binary input.
|
Pixel |
bottomRightMostPixel()
Gets the bottom-right most pixel in the connected component.
|
int |
calculateArea()
Calculate the area of this connected component in pixels.
|
double[] |
calculateAverageHeightWidth()
Calculate the height and width of a box surrounding the component by
averaging the distances of pixels above and below the centroid.
|
double[] |
calculateAverageHeightWidth(double[] centroid)
Calculate the height and width of a box surrounding the component by
averaging the distances of pixels above and below the centroid.
|
FImage |
calculateBinaryMask(Image<?,?> input)
Returns an image where the connected component is masked in the image.
|
double[] |
calculateCentroid()
Calculate the centroid of the connected component.
|
Pixel |
calculateCentroidPixel()
Calculates the centroid pixel of the connected component.
|
double |
calculateDirection()
Calculates the principle direction of the connected component.
|
double |
calculateMoment(int p,
int q)
Calculate the pq central moment, μpq for this region.
|
double |
calculateMoment(int p,
int q,
double xc,
double yc)
Calculate the pq moment, μpq around the given centroid.
|
double |
calculateMomentNormalised(int p,
int q)
Calculate the normalized, unscaled, central moments ηpq.
|
Rectangle |
calculateRegularBoundingBox()
Calculate the regular bounding box of the region by calculating the
maximum and minimum x and y coordinates of the pixels contained within
the region.
|
double |
calculateRegularBoundingBoxAspectRatio()
Compute the aspect ratio of the regular bounding box.
|
MBFImage |
crop(MBFImage input,
boolean blackout)
Returns an image containing just the connected component cropped from the
original image.
|
FImage |
extractPixels1d(FImage input)
Extract a 1 x area image with all the pixels from the region in it.
|
MBFImage |
extractPixels1d(MBFImage input)
Extract a 1xarea image with all the pixels from the region in it.
|
MBFImage |
extractPixels2d(MBFImage input,
boolean blackout)
This is a convenience method that simply calls
crop(MBFImage, boolean) |
boolean |
find(int x,
int y)
Returns whether the given coordinates are within this connected
component.
|
boolean |
find(Pixel p)
Returns whether the given pixel is within this connected component.
|
protected void |
fromShape(Shape shape) |
Set<Pixel> |
getPixels()
Returns the set of
Pixel s that are within this component. |
Iterator<Pixel> |
iterator() |
void |
merge(ConnectedComponent c)
Shallow copies the pixels from the given
ConnectedComponent into
this object. |
Jama.Matrix |
normMatrix()
Returns a normalisation matrix for this component.
|
void |
readASCII(Scanner in)
Read internal state from in.
|
void |
readBinary(DataInput in)
Read internal state from in.
|
void |
reposition()
Repositions the connected component so that its bounding box has its
origin at (0,0).
|
FImage |
toFImage()
Returns a mask image for this connected component that will be the size
of this component's bounding box.
|
FImage |
toFImage(int padding)
Returns a mask image for this connected component that will be the size
of this component's bounding box plus a border of the given amount of
padding.
|
Pixel |
topLeftMostPixel()
Gets the top-left most pixel within the connected component.
|
String |
toString() |
String |
toStringImage()
Returns an ASCII representation of the connected component as a mask;
where the output is "1" for a pixel within the mask and "0" for a pixel
outside of the mask.
|
void |
transform(Jama.Matrix transform)
Affine transform the shape with the given transform matrix.
|
void |
translate(int x,
int y)
Translates the region's pixels by x and y.
|
void |
writeASCII(PrintWriter out)
Write the content of this as ascii to out.
|
void |
writeBinary(DataOutput out)
Write the content of this as binary to out.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public PixelSet()
public PixelSet(int x, int y, int w, int h)
PixelSet
. 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 PixelSet(int[][] img)
img
- The mask image to construct a connected component from.public PixelSet(FImage mask, float thresh)
mask
- The mask image to construct a connected component from.thresh
- the threshold value.public void addPixel(int x, int y)
x
- The x-coordinate of the pixel to addy
- The y-coordinate of the pixel to addpublic void addPixel(Pixel p)
p
- The pixel to addpublic Set<Pixel> getPixels()
Pixel
s that are within this component.Pixel
s that are within this component.public void merge(ConnectedComponent c)
ConnectedComponent
into
this object. If the pixels that are added are not adjacent to other
pixels within the component some methods may return unexpected results.
Side-affects this object.c
- The ConnectedComponent
to copy pixels from.public boolean find(Pixel p)
getPixels
().contains(p)
.p
- The pixel to find.public boolean find(int x, int y)
find
( new Pixel(x,y) )
.x
- The x-coordinate of the pixel to findy
- The y-coordinate of the pixel to findpublic int calculateArea()
getPixels
.size()
public double calculateMoment(int p, int q, double xc, double yc)
p
- The P moment to calculateq
- The Q moment to calculatexc
- x-coordinate of centroidyc
- y-coordinate of centroidpublic double calculateMoment(int p, int q)
p
- The P moment to calculateq
- The Q moment to calculatepublic double calculateMomentNormalised(int p, int q)
p
- The P moment to calculateq
- The Q moment to calculatepublic double calculateDirection()
0.5 * atan( (M20-M02) / 2 * M11 )
so results in an angle between -PI and +PI.public double[] calculateCentroid()
public Pixel calculateCentroidPixel()
Pixel
at the centroid.public double[] calculateAverageHeightWidth(double[] centroid)
centroid
- The centroid of the component.public double[] calculateAverageHeightWidth()
public double calculateRegularBoundingBoxAspectRatio()
public Rectangle calculateRegularBoundingBox()
Rectangle
describing the boundspublic void translate(int x, int y)
x
- The offset in the horizontal directiony
- The offset in the vertical direction.public Pixel topLeftMostPixel()
public Pixel bottomRightMostPixel()
public String toString()
toString
in class Object
Object.toString()
public MBFImage extractPixels1d(MBFImage input)
input
- input image to extract samples frompublic FImage extractPixels1d(FImage input)
input
- image to extract pixel values frompublic MBFImage crop(MBFImage input, boolean blackout)
input
- The input image from which to take the pixelsblackout
- Whether to blackout pixels that are not part of the region or
whether to mark them as transparentpublic MBFImage extractPixels2d(MBFImage input, boolean blackout)
crop(MBFImage, boolean)
input
- The input image from which to take the pixelsblackout
- Whether to blackout pixels that are not part of the region or
whether to mark them as transparentpublic FImage calculateBinaryMask(Image<?,?> input)
input
- The input image from which to take the size.FImage
containing a binary mask; pixels within the
connected component will have value 1, outside with have value 0public String toStringImage()
public void reposition()
public FImage toFImage()
FImage
mask imagepublic FImage toFImage(int padding)
padding
- The number of pixels padding to add around the outside of the
mask.FImage
mask imagepublic void transform(Jama.Matrix transform)
transform
- The matrix containing the transform.public Jama.Matrix normMatrix()
public void readASCII(Scanner in) throws IOException
ReadableASCII
readASCII
in interface ReadableASCII
in
- source to read from.IOException
- an error reading inputpublic void readBinary(DataInput in) throws IOException
ReadableBinary
readBinary
in interface ReadableBinary
in
- source to read from.IOException
- an error reading inputpublic String asciiHeader()
ReadableASCII
asciiHeader
in interface ReadableASCII
asciiHeader
in interface WriteableASCII
public byte[] binaryHeader()
ReadableBinary
binaryHeader
in interface ReadableBinary
binaryHeader
in interface WriteableBinary
public void writeASCII(PrintWriter out) throws IOException
WriteableASCII
writeASCII
in interface WriteableASCII
out
- sink to write toIOException
- an error writing to outpublic void writeBinary(DataOutput out) throws IOException
WriteableBinary
writeBinary
in interface WriteableBinary
out
- sink to write toIOException
- an error writing to out