@ALDDerivedClass public class MTBSnake extends MTBPolygon2D implements MTBSegmentationInterface
The snake is implemented with its control points and a large variety of convenience methods for using the snakes, e.g., methods to plot the snake to an image. A snake can be open or closed. In the latter case it also has an orientation, i.e., the snake points are ordered clockwise or counter-clockwise.
The snake interior is always located left of the snake segments. In case of a closed snake in counter-clockwise ordering the area enclosed by the snake polygon is defined as its interior. In case of counter-clockwise ordering the enclosed region is the exterior part of the domain or the background, respectively.
The snake datatype implements the MTBSegmentationInterface
, i.e.,
allows for querying if certain pixels belong to foreground/interior or
background/exterior. Note that the interior or foreground class is always
labeled with 1, the background or exterior region always with 0.
A pixel or position in the domain of the snake can be visible or not. The visibility is stored in an internal visibility map. Note that this map can be altered from external and does not need to have the same size as the snakes domain.
Modifier and Type | Class and Description |
---|---|
private class |
MTBSnake.SnakeCloner
Operator class to construct new snake object from a given one.
|
MTBSegmentationInterface.SegmentationDimension
Modifier and Type | Field and Description |
---|---|
protected int[][] |
classmap
2D map marking the region enclosed by the snake.
|
private int |
labelInside
Marker for label of enclosed area.
|
protected int |
mapHeight
Height of class map.
|
protected int |
mapMaxX
Maximal x coordinate of class map.
|
protected int |
mapMaxY
Maximal y coordinate of class map.
|
protected int |
mapMinX
Minimal x coordinate of class map.
|
protected int |
mapMinY
Minimal y coordinate of class map.
|
protected int |
mapWidth
Width of class map.
|
private double |
scaleFactor
Scale factor of the snake for normalization.
|
protected int |
visibilityMapHeight
Height of visibility map.
|
protected int |
visibilityMapWidth
Width of visibility map.
|
protected boolean[][] |
visiblemap
Visibility map for hiding individual pixels.
|
protected int |
visibleMapMaxX
Maximal x coordinate of visibility map.
|
protected int |
visibleMapMaxY
Maximal y coordinate of visibility map.
|
protected int |
visibleMapMinX
Minimal x coordinate of visibility map.
|
protected int |
visibleMapMinY
Minimal y coordinate of visibility map.
|
isClosed, points
Constructor and Description |
---|
MTBSnake()
Standard constructor to create a new and empty snake object.
|
MTBSnake(Vector<MTBSnakePoint2D> spoints,
boolean cycle)
Constructor to create a new Snake object.
|
MTBSnake(Vector<MTBSnakePoint2D> spoints,
boolean cycle,
double scale,
boolean isScaled)
Constructor to create a new Snake object.
|
Modifier and Type | Method and Description |
---|---|
void |
addPoint(double x,
double y)
Overwrites Polygon2D method.
|
private void |
calcSnakeDomain()
Calculates snake bounding box (in non-normalized coordinates!).
|
MTBSnake |
clone()
Override java.lang.Object.clone() to create and return a copy of this
object.
|
static MTBSnake |
convertContourToSnake(MTBContour2D contour)
Converts a contour into a snake.
|
static MTBPolygon2DSet |
convertRegionsToSnakes(MTBImage image)
Converts the regions of a label/binary image into a set of snakes.
|
static MTBSnake |
convertRegionToSnake(MTBRegion2D region)
Converts a region into a snake.
|
void |
denormalize()
Denormalizes the snake coordinates.
|
void |
drawPolygon(MTBImage img,
int color)
Draw snake into an image.
|
void |
drawPolygonPoints(MTBImage img,
int color,
int mode)
Draw snake points into an image (as crosses).
|
int[][] |
getBinaryMask(int w,
int h)
Generates binary mask for inside part of the snake.
|
private int[][] |
getBinaryMask(int w,
int h,
int xoff,
int yoff)
Generates binary mask for inside part of the snake.
|
int |
getClass(int x,
int y)
Returns the class label of position (x,y).
|
int |
getClass(int x,
int y,
int z)
Returns the class label of position (x,y,z).
|
double |
getCOMx()
Returns the center of mass of the snake in x-direction.
|
double |
getCOMy()
Returns the center of mass of the snake in y-direction.
|
MTBSegmentationInterface.SegmentationDimension |
getDimension()
Returns the dimension of the given membership.
|
int |
getDomainXMaxCoordinate()
Returns maximal x coordinate represented in class map.
|
int |
getDomainXMinCoordinate()
Returns minimal x coordinate represented in class map.
|
int |
getDomainYMaxCoordinate()
Returns maximal y coordinate represented in visibility map.
|
int |
getDomainYMinCoordinate()
Returns minimal y coordinate represented in class map.
|
MTBImage |
getMask(int class_)
Gets the mask of the specified class (0 Background, 255 Foreground)
|
int |
getMaxLabel()
Returns the maximal label used in the membership representation.
|
int |
getNumberOfClasses()
Returns the number of classes represented in the membership.
|
double |
getPartialDiffX(int position)
Get approximation of partial derivative in x-direction at point with given
index.
|
double |
getPartialDiffY(int position)
Get approximation of partial derivative in y-direction at point with given
index.
|
double |
getScaleFactor()
Get the scaling factor of the snake.
|
int |
getSizeX()
Returns the size of the segmentation domain in x direction.
|
int |
getSizeY()
Returns the size of the segmentation domain in y direction.
|
int |
getSizeZ()
Returns the size of the segmentation domain in z direction.
|
Vector<MTBSnakePoint2D> |
getSnakePoints()
Get snake points as vector of SnakePoint2D objects.
|
double |
getSndPartialDiffX(int position)
Get approximation of 2nd order partial derivative in x-direction.
|
double |
getSndPartialDiffY(int position)
Get approximation of 2nd order partial derivative in y-direction.
|
int |
getVisibilityMapHeight()
Returns height of the visibility map.
|
int |
getVisibilityMapWidth()
Returns width of the visibility map.
|
int |
getVisibilityMapXMaxCoordinate()
Returns maximal x coordinate represented in visibility map.
|
int |
getVisibilityMapXMinCoordinate()
Returns minimal x coordinate represented in visibility map.
|
int |
getVisibilityMapYMaxCoordinate()
Returns maximal y coordinate represented in visibility map.
|
int |
getVisibilityMapYMinCoordinate()
Returns minimal y coordinate represented in visibility map.
|
double |
getWeight(int x,
int y)
Returns the pixel weight of position (x,y).
|
double |
getWeight(int x,
int y,
int z)
Returns the pixel weight of position (x,y,z).
|
boolean |
isVisible(int x,
int y)
Get visibility of a certain pixel position.
|
boolean |
isVisible(int x,
int y,
int z)
True, if position (x,y,z) is visible.
|
void |
makeSimple()
Makes the polygon simple, i.e. removes self-overlaps.
|
void |
normalize(double scale)
Normalizes the snake coordinates.
|
void |
printPoints()
Prints points of snake to standard output stream.
|
void |
resample(double segLength)
Method to re-sample the line segments of the snake in a range of a given
segment length.
|
void |
reversePolypoints()
Overwrite reversePolypoints method of Polygon2D.
|
void |
setClass(int x,
int y,
int c)
Deprecated.
|
void |
setClass(int x,
int y,
int z,
int c)
Deprecated.
|
void |
setInvisible(int x,
int y)
Set position (x,y) invisible.
|
void |
setInvisible(int x,
int y,
int z)
Set position (x,y,z) invisible.
|
void |
setPoints(Vector<Point2D.Double> ps)
Overwrite Polygon2D method to set all points of the snake from the
specified point vector object.
|
void |
setSegmentationDomain(int xmin,
int xmax,
int ymin,
int ymax)
Specify the domain of the underlying segmentation.
|
void |
setSnakePoints(Vector<MTBSnakePoint2D> ps)
Set all points of the snake from the specified SnakePoint2D vector object.
|
void |
setVisibilityMask(boolean[][] mask,
int mMinX,
int mMinY,
int mMaxX,
int mMaxY)
Set the valid mask from external mask data.
|
void |
setVisible(int x,
int y)
Set position (x,y) visible.
|
void |
setVisible(int x,
int y,
int z)
Set position (x,y,z) visible.
|
void |
setWeight(int x,
int y,
double c)
Sets the pixel weight of position (x,y) to c.
|
void |
setWeight(int x,
int y,
int z,
double c)
Sets the pixel weight of position (x,y,z) to c.
|
void |
shift(double shift,
int imageSizeX,
int imageSizeY)
Method to shift the whole snake outward (positive value) ore inward
(negative value) to its normal vector from every line segment.
|
MTBImage |
toMTBImage(String file,
MTBImage img)
Method to draw and save the snake in a given MTBImage.
|
MTBImageByte |
toMTBImageByte(String file,
int w,
int h)
Method to draw and save the snake in a binary image.
|
de.unihalle.informatik.MiToBo_xml.MTBXMLSnakeType |
toXMLType(de.unihalle.informatik.MiToBo_xml.MTBXMLSnakeType xmlSnake)
Convert object to XML representation.
|
private void |
updateIDs(Vector<MTBSnakePoint2D> newPoints)
Update method for snake point ID's after make snake simple.
|
private void |
updateSnakeSegmentation()
Convenience function for updating the segmentation.
|
contains, containsPoint, convertToImageJRoi, drawPolygon, drawPolygonPoints, equals, getBinaryMask, getBoundingBox, getLength, getPointNum, getPoints, getPolygon, getSignedArea, isClosed, isConvex, isOrderedClockwise, isOrderedCounterClockwise, isSimple, setClosed, setOpen, simplify, standardization, toXMLType
private double scaleFactor
private int labelInside
protected int[][] classmap
Note that the enclosed region contains always values of 1, independent of the order of the snake. The getClass()-methods take care of returning correct class labels.
protected int mapMinX
protected int mapMaxX
protected int mapMinY
protected int mapMaxY
protected int mapWidth
protected int mapHeight
protected boolean[][] visiblemap
protected int visibleMapMinX
protected int visibleMapMaxX
protected int visibleMapMinY
protected int visibleMapMaxY
protected int visibilityMapWidth
protected int visibilityMapHeight
public MTBSnake()
public MTBSnake(Vector<MTBSnakePoint2D> spoints, boolean cycle)
spoints
- vector of 2D snake points as control points for the snakecycle
- true if snake forms a closed polygonpublic MTBSnake(Vector<MTBSnakePoint2D> spoints, boolean cycle, double scale, boolean isScaled)
spoints
- vector of 2D snake points as control points for the snakecycle
- true if snake forms a closed polygonscale
- scaling factorisScaled
- true if snake is already scaledpublic de.unihalle.informatik.MiToBo_xml.MTBXMLSnakeType toXMLType(de.unihalle.informatik.MiToBo_xml.MTBXMLSnakeType xmlSnake)
Copy the information of this object into the corresponding xml
element xmlSnake
. If xmlSnake
is null, a new
object is created, otherwise the passed object filled.
xmlSnake
- Object to be filled.public double getScaleFactor()
public MTBSnake clone()
clone
in class MTBPolygon2D
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
public void setPoints(Vector<Point2D.Double> ps)
setPoints
in class MTBPolygon2D
ps
- vector with new points of the polygonpublic void setSnakePoints(Vector<MTBSnakePoint2D> ps)
public void addPoint(double x, double y)
addPoint
in class MTBPolygon2D
x
- Point x coordinate.y
- Point y coordinate.public Vector<MTBSnakePoint2D> getSnakePoints()
public void normalize(double scale)
All snake points are scaled by the given scale factor, i.e. divided by the given scale. A factor larger than 1.0 shrinks the snake, a factor smaller than 1.0 expands it, and the default factor of 1.0 does not change anything. The factor is stored internally for later de-normalization of the snake.
Note that the scaling does not affect the snake's domain nor its visibility maps.
scale
- Scale factor, i.e. divisor, for normalization.public void denormalize()
The internally stored scale factor is used for the denormalization and subsequently set to 1.0.
public double getPartialDiffX(int position)
For calculating partial derivatives point differences are used, i.e. forward differences. Note, that the partial derivative for the last point of a non-closed snake is always zero!
position
- Index of snake point.public double getPartialDiffY(int position)
For calculating partial derivatives point differences are used, i.e. forward differences. Note, that the partial derivative for the last point of a non-closed snake is always zero!
position
- Index of snake point.public double getSndPartialDiffX(int position)
For calculating partial derivatives point differences are used, i.e. forward differences. Note, that the partial derivatives for the first and last point of a non-closed snake are always zero!
position
- Index of snake point.public double getSndPartialDiffY(int position)
For calculating partial derivatives point differences are used, i.e. forward differences. Note, that the partial derivatives for the first and last point of a non-closed snake are always zero!
position
- Index of snake point.public double getCOMx()
public double getCOMy()
public void drawPolygon(MTBImage img, int color)
drawPolygon
in class MTBPolygon2D
img
- Image where to draw the polygon into.color
- Color in which to draw the polygon.public void drawPolygonPoints(MTBImage img, int color, int mode)
drawPolygonPoints
in class MTBPolygon2D
img
- Image where to draw the polygon points into.color
- Color to be used.mode
- Shape of points to be applied.public int[][] getBinaryMask(int w, int h)
The area enclosed by the snake will be painted in white. Note that the coordinates of the mask start with (0,0).
getBinaryMask
in class MTBPolygon2D
w
- h
- de.unihalle.informatik.Alida.exceptions.ALDOperatorException
private int[][] getBinaryMask(int w, int h, int xoff, int yoff)
The area enclosed by the snake will be painted in white.
w
- Width of the mask.h
- Height of the mask.xoff
- Offset in x-direction.yoff
- Offset in y-direction.de.unihalle.informatik.Alida.exceptions.ALDOperatorException
public void makeSimple()
MTBPolygon2D
makeSimple
in class MTBPolygon2D
private void updateIDs(Vector<MTBSnakePoint2D> newPoints)
newPoints
- points after using jni_makePolySimple but without the former ID's
for all points.public void reversePolypoints()
If the snake points are ordered clockwise afterwards they are ordered counter-clockwise and vice versa. The old id of a snake point is kept.
reversePolypoints
in class MTBPolygon2D
public void resample(double segLength)
Method to re-sample the line segments of the snake in a range of a given segment length. The range is calculated from the given length of a segment by calculation: - minimum = segment length * 0.5 - maximum = segment length * 1.5 If a line segment (p,q) is too small, the point q is removed from the list. Then the new line segment (p,r) is observed, where r is the successor of q. If a line segment (p,q) is too large, new points will be added. The number of new points is calculated by the possible number of points (depending on the given segment length) that fit into the line segment between p and q. The old index of the snake point position in the previous snake is kept for all existing snake points. For new snake points the old position index is set to -1 by default.
resample
in class MTBPolygon2D
segLength
- Target length of segments in resampling.public void shift(double shift, int imageSizeX, int imageSizeY)
ATTENTION!!! After shifting a snake, it can happen that the snake is not simple !!!
shift
in class MTBPolygon2D
shift
- positive ore negative value to shift the snakeimageSizeX
- width of the image to test whether the coordinates of the shifted
snake are validimageSizeY
- height of the image to test whether the coordinates of the shifted
snake are validpublic MTBImageByte toMTBImageByte(String file, int w, int h) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException, de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
file
- file to save the image with the snake on the disk. File can be
null, then no file is stored on diskw
- image widthh
- image heightde.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
public MTBImage toMTBImage(String file, MTBImage img) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException, de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
file
- file to save the image with the snake on the disk. File can be
null, then no file is stored on diskimg
- image where the snake should be drawn inde.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
public void printPoints()
public static MTBSnake convertContourToSnake(MTBContour2D contour) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException, de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
contour
- Incoming contour.de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
public static MTBSnake convertRegionToSnake(MTBRegion2D region) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException, de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
region
- Incoming region.de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
public static MTBPolygon2DSet convertRegionsToSnakes(MTBImage image) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException, de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
image
- Incoming image.de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
public void setSegmentationDomain(int xmin, int xmax, int ymin, int ymax)
Class information is only available for pixels lying in the domain.
xmin
- Minimal coordinate in x-direction.xmax
- Maximal coordinate in x-direction.ymin
- Minimal coordinate in y-direction.ymax
- Maximal coordinate in y-direction.private void calcSnakeDomain()
private void updateSnakeSegmentation()
public MTBSegmentationInterface.SegmentationDimension getDimension()
getDimension
in interface MTBSegmentationInterface
public int getNumberOfClasses()
getNumberOfClasses
in interface MTBSegmentationInterface
public int getMaxLabel()
getMaxLabel
in interface MTBSegmentationInterface
public boolean isVisible(int x, int y, int z)
MTBSegmentationInterface
isVisible
in interface MTBSegmentationInterface
public boolean isVisible(int x, int y)
Note that pixels outside the domain of the visibility map are always assumed to be visible.
isVisible
in interface MTBSegmentationInterface
x
- x-coordinate of position under consideration.y
- y-coordinate of position under consideration.public int getClass(int x, int y, int z)
MTBSegmentationInterface
getClass
in interface MTBSegmentationInterface
public int getClass(int x, int y)
MTBSegmentationInterface
getClass
in interface MTBSegmentationInterface
@Deprecated public void setClass(int x, int y, int z, int c)
MTBSegmentationInterface
setClass
in interface MTBSegmentationInterface
@Deprecated public void setClass(int x, int y, int c)
MTBSegmentationInterface
setClass
in interface MTBSegmentationInterface
public void setVisible(int x, int y)
MTBSegmentationInterface
setVisible
in interface MTBSegmentationInterface
public void setVisible(int x, int y, int z)
MTBSegmentationInterface
setVisible
in interface MTBSegmentationInterface
public void setInvisible(int x, int y)
MTBSegmentationInterface
setInvisible
in interface MTBSegmentationInterface
public void setInvisible(int x, int y, int z)
MTBSegmentationInterface
setInvisible
in interface MTBSegmentationInterface
public void setVisibilityMask(boolean[][] mask, int mMinX, int mMinY, int mMaxX, int mMaxY)
Note that the parameter object is cloned for internal representation!
public int getSizeX()
MTBSegmentationInterface
getSizeX
in interface MTBSegmentationInterface
public int getSizeY()
MTBSegmentationInterface
getSizeY
in interface MTBSegmentationInterface
public int getSizeZ()
MTBSegmentationInterface
getSizeZ
in interface MTBSegmentationInterface
public int getDomainXMinCoordinate()
public int getDomainXMaxCoordinate()
public int getDomainYMinCoordinate()
public int getDomainYMaxCoordinate()
public int getVisibilityMapXMinCoordinate()
public int getVisibilityMapXMaxCoordinate()
public int getVisibilityMapYMinCoordinate()
public int getVisibilityMapYMaxCoordinate()
public int getVisibilityMapWidth()
public int getVisibilityMapHeight()
public double getWeight(int x, int y)
MTBSegmentationInterface
getWeight
in interface MTBSegmentationInterface
public double getWeight(int x, int y, int z)
MTBSegmentationInterface
getWeight
in interface MTBSegmentationInterface
public void setWeight(int x, int y, double c)
MTBSegmentationInterface
setWeight
in interface MTBSegmentationInterface
public void setWeight(int x, int y, int z, double c)
MTBSegmentationInterface
setWeight
in interface MTBSegmentationInterface
public MTBImage getMask(int class_)
MTBSegmentationInterface
getMask
in interface MTBSegmentationInterface
Copyright © 2010–2020 Martin Luther University Halle-Wittenberg, Institute of Computer Science, Pattern Recognition and Bioinformatics. All rights reserved.