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

java.lang.Object
  extended by de.unihalle.informatik.MiToBo.core.datatypes.MTBRegion2D

public class MTBRegion2D
extends java.lang.Object

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

Field Summary
(package private)  int area
          Size of region in pixels.
(package private)  float com_x
          Center of mass in x (just sum, not normalized by area!).
(package private)  float com_y
          Center of mass in y (just sum, not normalized by area!).
(package private)  int id
          Id of the region (uniqueness is not guaranteed nor checked!).
(package private)  java.util.Vector<java.awt.geom.Point2D.Double> points
          Pixels belonging to region.
 
Constructor Summary
MTBRegion2D()
          Construct a new empty MTBRegion2D object.
MTBRegion2D(de.unihalle.informatik.MiToBo_xml.MTBXMLRegion2DType xmlregion2D)
          Construct a new MTBRegion2D from a region object that was constructed from a xml-representation.
MTBRegion2D(java.util.Vector<java.awt.geom.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(java.awt.geom.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(java.awt.geom.Point2D.Double p)
          Test if a point is inside the region or not.
 int getArea()
          Return the area of the region in pixels.
 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.
 java.util.Vector<java.awt.geom.Point2D.Double> getPoints()
          Return all points of the region.
 MTBRegion2D getRegion()
          Get a Region2D copy of this object.
 MTBRegion2D join(MTBRegion2D reg)
          Join a region with this region.
 void setID(int id)
          Set the ID of the region.
 MTBImage toMTBImage(java.lang.String file, MTBImage image)
          Method to save a region with in a given MTBImage image.
 MTBImageByte toMTBImageByte(java.lang.String file, int width, int height)
          Method to save the region on a binary image with specific width and height.
 MTBImageByte toMTBImageByte(java.lang.String file, int width, int height, int color)
          Method to save the region on a binary image with specific width, height and color.
(package private)  de.unihalle.informatik.MiToBo_xml.MTBXMLRegion2DType toXMLType()
          Construct an object that represents this region by xml.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

area

int area
Size of region in pixels.


com_x

float com_x
Center of mass in x (just sum, not normalized by area!).


com_y

float com_y
Center of mass in y (just sum, not normalized by area!).


id

int id
Id of the region (uniqueness is not guaranteed nor checked!).


points

java.util.Vector<java.awt.geom.Point2D.Double> points
Pixels belonging to region.

Constructor Detail

MTBRegion2D

public MTBRegion2D()
Construct a new empty MTBRegion2D object.


MTBRegion2D

MTBRegion2D(de.unihalle.informatik.MiToBo_xml.MTBXMLRegion2DType xmlregion2D)
Construct a new MTBRegion2D from a region object that was constructed from a xml-representation. Only used for reading region sets ( MTBRegion2DSet) from file.

Parameters:
xmlregion2D - object that represents the region read from xml

MTBRegion2D

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

Parameters:
inPoints - vector of region points
Method Detail

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(java.awt.geom.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

clone

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

Overrides:
clone in class java.lang.Object

contains

public boolean contains(java.awt.geom.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.

getArea

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

Returns:
Pixel area of the region.

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.

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.

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.

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

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

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

getEccentricity

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

Returns:
Eccentricity as double value.

getID

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

Returns:
Region ID.

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

getMinMaxCoordinates

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

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

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.

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.

getPoints

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

Returns:
Region points.

getRegion

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

Returns:
Copy of this Region2D object.

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).

setID

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

Parameters:
id - Region ID

toMTBImage

public MTBImage toMTBImage(java.lang.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 inner- and outer-contours in a binary image of type MTBImageByte.
Throws:
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

toMTBImageByte

public MTBImageByte toMTBImageByte(java.lang.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(java.lang.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

toXMLType

de.unihalle.informatik.MiToBo_xml.MTBXMLRegion2DType toXMLType()
Construct an object that represents this region by xml. Only used for writing region sets (MTBRegion2DSet) to file.