de.unihalle.informatik.MiToBo.core.datatypes
Class MTBRegion2D

java.lang.Object
  extended by de.unihalle.informatik.MiToBo.core.datatypes.MTBRegion2D
All Implemented Interfaces:
MTBRegionInterface

@ALDParametrizedClass
public class MTBRegion2D
extends Object
implements MTBRegionInterface

Class to implement a 2D region object. the region is stored in a vector of 2D double points with its x- and y-coordinate. The area, center of mass, moments, and other properties of the region can be calculated. For further details watch the implemented methods.

Author:
Danny Misiak

Constructor Summary
MTBRegion2D()
          Construct a new empty MTBRegion2D object.
MTBRegion2D(Vector<Point2D.Double> inPoints)
          Construct a new MTBRegion2D from the given points.
 
Method Summary
 void addPixel(int x, int y)
          Append a point to the region from the given coordinates.
 void addPixel(Point2D.Double p)
          Append a point to the region from the given point object.
 MTBRegion2D clone()
          Override java.lang.Object.clone() to create and return a copy of this object.
 boolean contains(Point2D.Double p)
          Test if a point is inside the region or not.
static MTBRegion2D createRandomRegion2D(int xSize, int ySize, int maxArea, Random rndGen)
          Create a random connected 2D region of size maxArea in a hypothetical image of a random size between 1 and maxArea.
 boolean equals(Object obj)
           
 int getArea()
          Return the area of the region in pixels.
 MTBBorder2D getBorder()
          Method to get the border object from the current 2D region, for example to visualize the regions.
 double[] getBoundingBox()
          Calculates the axes-parallel bounding box of the region.
 float getCenterOfMass_X()
          Return x-coordinate of the center of mass.
 float getCenterOfMass_Y()
          Return y-coordinate of the center of mass.
 double getCentralMoment(int p, int q)
          Calculate central moment of the region of order p,q.
 double getCircularity()
          Calculates circularity of given region (1 for perfect circle, else smaller).
 MTBContour2D getContour()
          Method to get the contour object from the current 2D region.
 double getCorrCircularity()
          Calculates corrected circularity of given region (1 for perfect circle, else smaller).
 double getEccentricity()
          Calculate eccentricity of the region in range [0,1]. 1 means a sustained region.
 int getID()
          Return the ID of the region.
 double getMajorAxisLength()
          calculation of the length of the major axis of the ellipse best fitting
using moments of the region
 double[] getMinMaxCoordinates()
          Extracts the extreme coordinates of the region in each dimension.
 double getMoment(int p, int q)
          Calculate moment of the region of order p,q.
 double getNormalCentralMoment(int p, int q)
          Calculate normalized central moment of the region of order p,q.
 double getOrientation()
          Calculate orientation of principal axis of the MTBRegion2D, using the atan2 function.
 Vector<Point2D.Double> getPoints()
          Return all points of the region.
 MTBRegion2D getRegion()
          Get a Region2D copy of this object.
protected  void hookPointsUpdated()
          Function to update object state after setting new point list.
 MTBRegion2D join(MTBRegion2D reg)
          Join a region with this region.
 void setID(int _id)
          Set the ID of the region.
 MTBImage toMTBImage(String file, MTBImage image)
          Method to save a region with in a given MTBImage image.
 MTBImageByte toMTBImageByte(String file, int width, int height)
          Method to save the region on a binary image with specific width and height.
 MTBImageByte toMTBImageByte(String file, int width, int height, int color)
          Method to save the region on a binary image with specific width, height and color.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MTBRegion2D

public MTBRegion2D()
Construct a new empty MTBRegion2D object.


MTBRegion2D

public MTBRegion2D(Vector<Point2D.Double> inPoints)
Construct a new MTBRegion2D from the given points.

Parameters:
inPoints - Vector of region points.
Method Detail

clone

public MTBRegion2D clone()
Override java.lang.Object.clone() to create and return a copy of this object.

Overrides:
clone in class Object

getRegion

public MTBRegion2D getRegion()
Get a Region2D copy of this object.

Returns:
Copy of this Region2D object.

getPoints

public Vector<Point2D.Double> getPoints()
Return all points of the region.

Returns:
Region points.

getArea

public int getArea()
Return the area of the region in pixels.

Returns:
Pixel area of the region.

getCenterOfMass_X

public float getCenterOfMass_X()
Return x-coordinate of the center of mass.

Returns:
Center of mass coordinate in x-dimension.

getCenterOfMass_Y

public float getCenterOfMass_Y()
Return y-coordinate of the center of mass.

Returns:
Center of mass coordinate in y-dimension.

getMinMaxCoordinates

public double[] getMinMaxCoordinates()
Extracts the extreme coordinates of the region in each dimension.

Returns:
Array with extreme values: [xmin, ymin, xmax, ymax]

getID

public int getID()
Return the ID of the region. Uniqueness is not guaranteed nor checked!

Returns:
Region ID.

addPixel

public void addPixel(int x,
                     int y)
Append a point to the region from the given coordinates. The point is added at the end of the point vector.

Parameters:
x - coordinate in x-dimension
y - coordinate in y-dimension

addPixel

public void addPixel(Point2D.Double p)
Append a point to the region from the given point object. The point is added at the end of the point vector.

Parameters:
p - point to add

setID

public void setID(int _id)
Set the ID of the region. Uniqueness is not guaranteed nor checked!

Parameters:
_id - Region ID

join

public MTBRegion2D join(MTBRegion2D reg)
Join a region with this region. New point objects are created for the new region.

Parameters:
reg - region to join
Returns:
New region (union of the old region and the join region).

contains

public boolean contains(Point2D.Double p)
Test if a point is inside the region or not.

Parameters:
p - point that maybe lies in the region
Returns:
True if point p is inside, false if not.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toMTBImageByte

public MTBImageByte toMTBImageByte(String file,
                                   int width,
                                   int height)
                            throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                                   de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to save the region on a binary image with specific width and height. Color value of the region is set to 255.

Parameters:
file - path where the file should be saved, can be null if image should not be stored at disk
width - width of the binary image
height - height of the binary image
Returns:
2D region in a binary image of type MTBImageByte.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

toMTBImageByte

public MTBImageByte toMTBImageByte(String file,
                                   int width,
                                   int height,
                                   int color)
                            throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                                   de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to save the region on a binary image with specific width, height and color.

Parameters:
file - path where the file should be saved, can be null if image should not be stored at disk
width - width of the binary image
height - height of the binary image
color - region color
Returns:
2D region in a binary image of type MTBImageByte.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

toMTBImage

public MTBImage toMTBImage(String file,
                           MTBImage image)
                    throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                           de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to save a region with in a given MTBImage image. Color value of the region is set so image.getTypeMax().

Parameters:
file - path where the file should be saved, can be null if image should not be stored at disk
image - image where the region should be drawn in
Returns:
2D region in a image of type MTBImage.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

getContour

public MTBContour2D getContour()
                        throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                               de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to get the contour object from the current 2D region. Outer and inner contours will be returned from the current region object. The image size, including the region, is calculated by the minimum and maximum x- and y-coordinate of the bounding box of the region.

Returns:
Inner and outer contours of the given region.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

getBorder

public MTBBorder2D getBorder()
                      throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                             de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Method to get the border object from the current 2D region, for example to visualize the regions. Contrary to contours the borders extracted by this operator contain unordered sets of pixels, but it is faster than extracting the contours. Outer and inner borders will be returned from the current region object. The image size, including the region, is calculated by the minimum and maximum x- and y-coordinate of the bounding box of the region.

Returns:
Inner and outer borders of the given region.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
See Also:
BordersOnLabeledComponents

getMoment

public double getMoment(int p,
                        int q)
Calculate moment of the region of order p,q.

Parameters:
p - order of x-component
q - oder of y-component
Returns:
Moment as double value.

getCentralMoment

public double getCentralMoment(int p,
                               int q)
Calculate central moment of the region of order p,q.

Parameters:
p - order of x-component
q - oder of y-component
Returns:
Central moment as double value.

getNormalCentralMoment

public double getNormalCentralMoment(int p,
                                     int q)
Calculate normalized central moment of the region of order p,q.

Parameters:
p - order of x-component
q - oder of y-component
Returns:
Normalized central moment as double value.

getOrientation

public double getOrientation()
Calculate orientation of principal axis of the MTBRegion2D, using the atan2 function. The orientation (angle) is given in radian in a range [-pi, +pi]

Returns:
Orientation in radian.

getEccentricity

public double getEccentricity()
Calculate eccentricity of the region in range [0,1]. 1 means a sustained region.

Returns:
Eccentricity as double value.

getCircularity

public double getCircularity()
                      throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                             de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Calculates circularity of given region (1 for perfect circle, else smaller).

Parameters:
imageSizeX - width of image that includes the region
imageSizeY - height of image that includes the region
Returns:
Roundness of the region.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

getCorrCircularity

public double getCorrCircularity()
                          throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                                 de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Calculates corrected circularity of given region (1 for perfect circle, else smaller). Here the perimeter calculation is corrected.

Parameters:
imageSizeX - width of image that includes the region
imageSizeY - height of image that includes the region
Returns:
Roundness of the region.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

getBoundingBox

public double[] getBoundingBox()
Calculates the axes-parallel bounding box of the region.

The function extracts the coordinates of the upper left and lower right corner of the bounding box of the region. Note that the there is at least one point of the region lying on each side of the bounding box, i.e. the region not just touches the box, but lies on it.

The result array contains the corner coordinates in the following order: [xmin, ymin, xmax, ymax]

Returns:
Coordinates of upper left and lower right corners.

getMajorAxisLength

public double getMajorAxisLength()
calculation of the length of the major axis of the ellipse best fitting
using moments of the region

Returns:
length of major axis of best fitting ellipse

createRandomRegion2D

public static MTBRegion2D createRandomRegion2D(int xSize,
                                               int ySize,
                                               int maxArea,
                                               Random rndGen)
Create a random connected 2D region of size maxArea in a hypothetical image of a random size between 1 and maxArea.

Parameters:
xSize -
ySize -
maxArea -
Returns:

toString

public String toString()
Overrides:
toString in class Object

hookPointsUpdated

protected void hookPointsUpdated()
Function to update object state after setting new point list.

It is assumed that point list is up-to-date before calling the hook.



Copyright © 2010–2015 Martin Luther University Halle-Wittenberg. All rights reserved.