com.xinapse.multisliceimage.roi
Class ROI

java.lang.Object
  extended by com.xinapse.multisliceimage.roi.ROI
Direct Known Subclasses:
EllipticalROI, HollowROI, IrregularROI, LineROI, Marker, RectangularROI

public abstract class ROI
extends java.lang.Object

A Class representing a region of interest. A region of interest's shape is stored internally in real-space (mm) coordinates and it has space-related statistics, such as area (in square mm) and length (in mm). However, when a region is associated with an image, it may be drawn onto a slice of that image, and its intensity-related statistics may be computed. Methods that associate an ROI with an image will always supply the dimensions of the image pixel matrix, and the pixel sizes.

An ROI has three representations:

Whenever the ROI is moved, or the shape is changed, the caches are cleared.

The origin of the real-space (mm) coordinates is at the centre of the field of view.

An ROI has an audit-trail history, consisting of a creation history item, a list of modfication items, and if deleted, a deletion history item.


Field Summary
protected  Handle[] handles
          If an ROI is editable, it will be drawn with handles.
static java.lang.String PREFERENCES_NODE_NAME
          The node name for all Preferences to do with ROIs.
static java.lang.String XTOKEN
          The token written to ROI output files to represent an x-coordinate.
static java.lang.String YTOKEN
          The token written to ROI output files to represent a y-coordinate.
 
Method Summary
 java.util.List<ROI> add(java.util.List<ROI> rois)
          Morphologically adds a List of ROIs to this ROI to create a new java.util.List<ROI> of ROIs that is the result of adding (forming the union of) the shapes of the ROIs to this ROI.
 java.util.List<ROI> add(ROI roi)
          Morphologically adds an ROI to this ROI to create a new java.util.List<ROI> of ROIs that is the result of adding the shapes of the two ROIs.
static java.util.List<ROI> addMorphological(java.util.List<ROI> rois)
          Morphologically adds a List of ROIs to create a new java.util.List<ROI> of ROIs that is the result of morphologically adding (forming the union of) the shapes of the ROIs.
 void clearDeletionHistory()
          Removed the deletion HistoryItem for this ROI.
 void clearStats()
          Clears the cached statistics for this ROI, forcing them to be re-computed next time they are required.
 ROI clone()
          Returns a clone of this ROI.
abstract  boolean contains(ROI roi)
          Indicates whether this ROI entirely contains another ROI entirely within its borders.
 java.util.List<ROI> dilate(double radius)
          Dilates this ROI by the specified distance.
 boolean draw(java.awt.Graphics g, java.awt.Rectangle visibleRectangle, int imageDrawCols, int imageDrawRows, int xOffset, int yOffset, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean drawAnnotation)
          Draws this ROI if it needs to be be drawn on screen.
abstract  void drawInOrthoView(java.awt.Image orthoView, javax.vecmath.Point3f viewPosition, javax.media.j3d.Transform3D imageToViewTx, int nCols, int nRows, int nSlices, float pixelXSize, float pixelYSize, boolean filled)
          Draws this ROI on top of an orthogonal view of an image.
abstract  boolean equals(java.lang.Object o)
          Indicates whether some Object is equal to this ROI.
 java.util.List<ROI> exclusiveOr(ROI roi)
          Performs an exclusive OR operation on the shape of this ROI with another ROI.
abstract  void flipHorizontal(java.awt.geom.Point2D flipPoint)
          Flip this ROI horizontally about a given location.
abstract  void flipVertical(java.awt.geom.Point2D flipPoint)
          Flip this ROI vertically about a given location.
 java.lang.String getAnnotation()
          Gets the anotation string for this ROI.
 java.awt.geom.Rectangle2D getBoundingRectangle(int nCols, int nRows, float pixelXSize, float pixelYSize)
          Returns a high-precision rectangle (in image pixel coordinates) that just bounds this ROI.
static java.awt.geom.Rectangle2D getBoundingRectangle(java.util.List<ROI> ROIList, int nCols, int nRows, float pixelXSize, float pixelYSize)
          Returns a high-precision rectangle (in image pixel coordinates) that bounds all the ROIs in the ROIlist.
protected  ROIStats getCachedStatistics()
          Returns the cached ROI statistics, or null if there are none.
static java.lang.Class[] getClasses()
          Returns an array of all known sub-classes of ROI.
 java.awt.Color getColor()
          Returns the java.awt.Color in which this ROI should be drawn.
abstract  ROI getCopy()
          Returns a copy of this ROI.
abstract  java.lang.String getDescription()
          Return a description of this type of ROI.
 java.awt.geom.Rectangle2D getDisplayedBounds2D()
          Returns a high-precision rectangle (in screen coordinates) that just bounds this ROI.
static java.awt.geom.Rectangle2D getDisplayedBounds2D(java.util.List<ROI> ROIList)
          Returns a high-precision rectangle (in screen coordinates) that bounds all the ROIs in the ROIlist.
protected  java.awt.geom.Area getDisplayedRoiArea()
          Returns the java.awt.geom.Area of this ROI as it is displayed on-screen.
abstract  Feret getFeret()
          Returns the minimum and maximum Feret's diameter for this ROI, in mm.
static Feret getFeret(java.util.List<ROI> ROIs)
          Returns the minimum and maximum Feret's diameter for this List of ROI, in mm.
 Handle[] getHandles()
          Returns an array of Handles that this ROI has.
 Handle getHandleUnderPoint(java.awt.Point point)
          Returns the Handle of this ROI that is under the point supplied (in screen coordinates).
 java.lang.String getImageSource()
          Returns the image source of this ROI.
abstract  double getPerimeter()
          Returns the perimeter length of this ROI.
static double getPixelValue(java.lang.Object pix, PixelDataType dataType, ComplexMode complexMode, int col, int row, int nCols, int nRows, int offset)
          Returns the pixel value at a particular (column,row) of an array of pixels.
static java.util.List<ROI> getROIs(java.io.File f, java.lang.Float pixelXSize, java.lang.Float pixelYSize, java.lang.Integer nCols, java.lang.Integer nRows)
          Returns a List of ROIs read from an input File.
static java.util.List<ROI> getROIs(java.io.InputStream s)
          Returns a List of ROIs read from an InputStream.
static java.util.List<ROI> getROIs(java.io.InputStream s, java.lang.Float pixelXSize, java.lang.Float pixelYSize, java.lang.Integer nCols, java.lang.Integer nRows)
          Returns a List of ROIs read from an InputStream.
 int getSlice()
          Returns the slice number for this ROI.
 ROIState getState()
          Returns the state of this ROI.
static ROIStats getStats(java.util.List<? extends ROI> ROIs, java.lang.Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, CombineMode combineMode, MaskAction maskAction, MaskMode maskMode, double maskValue, ComplexMode complexMode)
          Find combined statistics about a list of ROIs.
 ROIStats getStats(java.lang.Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, ComplexMode complexMode)
          Returns statistics about this ROI.
 ROIStats getStats(java.lang.Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, MaskAction maskAction, MaskMode maskMode, double maskValue, java.io.PrintStream intensityOutputStream, boolean isUnitsMM, ComplexMode complexMode)
          Returns statistics about this ROI, and (optionally) performs a masking operation.
static java.awt.Color getTextColor()
          Returns the java.awt.Color with which ROI annotation text should be rendered.
static int getTextFontSize()
          Returns the font size at which ROI annotation text should be rendered.
 byte getUserColour()
          Returns the user-defined colour for this ROI.
 int hashCode()
          Returns a hash code value for the ROI.
 java.util.List<ROI> intersect(ROI roi)
          Performs an intersection operation on the shape of this ROI with another ROI.
abstract  boolean intersects(ROI roi)
          Tests whether this ROI intersects another ROI.
 boolean isDeleted()
          Returns true if this ROI has been deleted.
 boolean isEditable()
          Returns true if this ROI is currently editable.
 boolean isReloaded()
          Returns true if this ROI has been reloaded from disk.
 boolean isSelected()
          Returns true if this ROI is currently selected.
static java.util.List<ROI> join(java.util.List<ROI> ROIList)
          Joins a List of ROIs with a waisted join at the nearest point.
static void main(java.lang.String[] args)
          Run the test suite for ROIs.
 void markDeleted()
          Mark this ROI as deleted.
static double mmPosToPix(double posMM, float pixelSize, int nPixels)
          Convert from a position in mm to a pixel number coordinate.
abstract  void move(double dx, double dy)
          Move this ROI by specified distances (in mm) in the x and y directions.
static void moveROIs(java.util.List<ROI> ROIList, double dx, double dy)
          Move a List of ROIs by specified distances (in mm) in the x and y directions.
static double pixPosToMm(double pixel, int nPixels, float pixelSize)
          Convert from a pixel number to a position in mm.
 void printStats(java.io.PrintStream s, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode, boolean writeColour, boolean writeAnnotation, boolean writeSlice, boolean writeArea, boolean writeMean, boolean writeStddev, boolean writeMin, boolean writeMax, boolean writeMedian, boolean writeLength, boolean writePerimeter, boolean writeFeretMin, boolean writeFeretMax)
          Prints the statistics about this ROI in output format to a PrintStream.
 boolean selectDeselect(java.awt.Point point, boolean editMode, boolean showDeleted, int nAlreadySelected)
          Selects or deselects an ROI after a user click at the point.
abstract  void set(ROI roi)
          Sets the shape of this ROI to the shape of the supplied argument ROI.
 void setAnnotation(java.lang.String annotation)
          Sets the anotation string for this ROI.
protected  void setCreationHistory(HistoryItem history)
          Sets the creation history HistoryItem for this ROI.
 void setSlice(int s)
          Sets the slice number for this ROI.
 void setState(ROIState state)
          Sets the state of this ROI.
static void setTextColor(java.awt.Color c)
          Sets the colour with which ROI annotation text should be drawn.
static void setTextSize(int size)
          Sets the font size at which ROI annotation text should be drawn.
 void setUserColour(byte index)
          Sets the user-defined colour for this ROI.
 java.util.List<ROI> subtract(java.util.List<ROI> rois)
          Morphologically subtracts a List of ROIs from this ROI to create a new java.util.List<ROI> of ROIs that is the result of subtracting the shapes of the ROIs.
 java.util.List<ROI> subtract(ROI roi)
          Morphologically subtracts an ROI from this ROI to create a new java.util.List<ROI> of ROIs that is the result of subtracting the shapes of the two ROIs.
abstract  java.lang.String toString()
          Returns a String describing this ROI.
static void write(java.util.List<? extends ROI> rois, java.io.Writer w, java.lang.String source, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode)
          Write a List of ROIs using the specified writer.
 void write(java.io.Writer w, java.lang.String source, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode)
          Writes this ROI in output format using the specified writer.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PREFERENCES_NODE_NAME

public static final java.lang.String PREFERENCES_NODE_NAME
The node name for all Preferences to do with ROIs.

See Also:
Constant Field Values

XTOKEN

public static final java.lang.String XTOKEN
The token written to ROI output files to represent an x-coordinate.

See Also:
Constant Field Values

YTOKEN

public static final java.lang.String YTOKEN
The token written to ROI output files to represent a y-coordinate.

See Also:
Constant Field Values

handles

protected Handle[] handles
If an ROI is editable, it will be drawn with handles.

Method Detail

getTextColor

public static java.awt.Color getTextColor()
Returns the java.awt.Color with which ROI annotation text should be rendered.

Returns:
the java.awt.Color with which ROI annotation text should be rendered.

getTextFontSize

public static int getTextFontSize()
Returns the font size at which ROI annotation text should be rendered.

Returns:
the font size at which ROI annotation text should be rendered.

setCreationHistory

protected void setCreationHistory(HistoryItem history)
Sets the creation history HistoryItem for this ROI.


clearDeletionHistory

public void clearDeletionHistory()
Removed the deletion HistoryItem for this ROI. Needed to "undelete" an ROI.


getDescription

public abstract java.lang.String getDescription()
Return a description of this type of ROI.

Returns:
a String describing the type of this ROI.

move

public abstract void move(double dx,
                          double dy)
Move this ROI by specified distances (in mm) in the x and y directions.

Parameters:
dx - the distance to move in the x-direction.
dy - the distance to move in the y-direction.

flipVertical

public abstract void flipVertical(java.awt.geom.Point2D flipPoint)
Flip this ROI vertically about a given location.

Parameters:
flipPoint - the point about which the ROI will be flipped.

flipHorizontal

public abstract void flipHorizontal(java.awt.geom.Point2D flipPoint)
Flip this ROI horizontally about a given location.

Parameters:
flipPoint - the point about which the ROI will be flipped.

add

public java.util.List<ROI> add(ROI roi)
                        throws ROIException
Morphologically adds an ROI to this ROI to create a new java.util.List<ROI> of ROIs that is the result of adding the shapes of the two ROIs.

Parameters:
roi - the ROI to add.
Returns:
a List of ROIs that results from the addition of the shapes.
Throws:
ROIException - if an error occurs while constructing the new ROIs.

addMorphological

public static java.util.List<ROI> addMorphological(java.util.List<ROI> rois)
                                            throws ROIException
Morphologically adds a List of ROIs to create a new java.util.List<ROI> of ROIs that is the result of morphologically adding (forming the union of) the shapes of the ROIs.

Parameters:
rois - the ROIs to add.
Returns:
a List of ROIs that results from the addition of the shapes.
Throws:
ROIException

add

public java.util.List<ROI> add(java.util.List<ROI> rois)
                        throws ROIException
Morphologically adds a List of ROIs to this ROI to create a new java.util.List<ROI> of ROIs that is the result of adding (forming the union of) the shapes of the ROIs to this ROI.

Parameters:
rois - the ROIs to add.
Returns:
a List of ROIs that results from the addition of the shapes.
Throws:
ROIException

subtract

public java.util.List<ROI> subtract(ROI roi)
                             throws ROIException
Morphologically subtracts an ROI from this ROI to create a new java.util.List<ROI> of ROIs that is the result of subtracting the shapes of the two ROIs.

Parameters:
roi - the ROI to add.
Returns:
a List of ROIs that results from the addition of the shapes.
Throws:
ROIException

subtract

public java.util.List<ROI> subtract(java.util.List<ROI> rois)
                             throws ROIException
Morphologically subtracts a List of ROIs from this ROI to create a new java.util.List<ROI> of ROIs that is the result of subtracting the shapes of the ROIs.

ROIs are subtracted in the same order as they appear in the list.

Parameters:
rois - the ROIs to subtract.
Returns:
a List of ROIs that results from the subtraction of the shapes.
Throws:
ROIException

intersect

public java.util.List<ROI> intersect(ROI roi)
                              throws ROIException
Performs an intersection operation on the shape of this ROI with another ROI.

Parameters:
roi - the ROI with which to perform the intersection operation.
Returns:
a List of ROIs that result from the operation.
Throws:
ROIException - if the operation cannot be performed.

intersects

public abstract boolean intersects(ROI roi)
Tests whether this ROI intersects another ROI.

Note that the area of intersection may be zero if one or other of the ROIs (or both) contains no area.

Parameters:
roi - the ROI to be tested for intersection.
Returns:
true in the two ROIs intersect; false otherwise.

exclusiveOr

public java.util.List<ROI> exclusiveOr(ROI roi)
                                throws ROIException
Performs an exclusive OR operation on the shape of this ROI with another ROI.

Parameters:
roi - the ROI with which to perform the XOR operation.
Returns:
a List of ROIs that result from the operation.
Throws:
ROIException - if the operation cannot be performed.

dilate

public java.util.List<ROI> dilate(double radius)
                           throws CancelledException
Dilates this ROI by the specified distance.

Parameters:
radius - the radius of dilation.
Returns:
a List of ROIs that result from the operation.
Throws:
CancelledException

markDeleted

public void markDeleted()
Mark this ROI as deleted.


contains

public abstract boolean contains(ROI roi)
Indicates whether this ROI entirely contains another ROI entirely within its borders. If the supplied ROI just touches the border, then it is not contained within this ROI.

Parameters:
roi - the ROI to be tested for containment within this ROI.
Returns:
true if the supplied ROI is contained within this ROI; false otherwise.

equals

public abstract boolean equals(java.lang.Object o)
Indicates whether some Object is equal to this ROI. To be equal, the Object must be an ROI of the same type, and of the same shape and location as this ROI.

Overrides:
equals in class java.lang.Object
Parameters:
o - the Object to be tested for equality to this ROI.
Returns:
true if the supplied Object is an ROI of the same type, shape and location as this ROI; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the ROI. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this ROI.

set

public abstract void set(ROI roi)
Sets the shape of this ROI to the shape of the supplied argument ROI.

Throws:
java.lang.ClassCastException - of the sub class of the argument ROI is not the same as this ROI.

getCopy

public abstract ROI getCopy()
Returns a copy of this ROI. The copy will be identical in shape and annotation as the original ROI, but with a history of that of a newly-created ROI.

Returns:
a copy of this ROI, cast to an Object.

clone

public ROI clone()
Returns a clone of this ROI. The copy will be identical in shape and annotation as the original ROI, and with a history identical to the cloned ROI.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this ROI, cast to an Object.

toString

public abstract java.lang.String toString()
Returns a String describing this ROI.

Overrides:
toString in class java.lang.Object
Returns:
a java.lang.String describing this ROI.

getHandleUnderPoint

public Handle getHandleUnderPoint(java.awt.Point point)
Returns the Handle of this ROI that is under the point supplied (in screen coordinates).

Parameters:
point - the point to test whether there is a handle there.
Returns:
the Handle under the point, or null if there is no Handle under the point.

getHandles

public Handle[] getHandles()
Returns an array of Handles that this ROI has.

Returns:
the Handles for this ROI, or null if it has none.

getState

public ROIState getState()
Returns the state of this ROI.

Returns:
the ROIState of this ROI. One of: ROIState.DELETED, ROIState.DELETED_SELECTED, ROIState.NORMAL, ROIState.SELECTED, ROIState.EDITABLE, ROIState.EDIT_OUTLINE.

setState

public void setState(ROIState state)
Sets the state of this ROI.

Parameters:
state - the ROIState of this ROI to be set. One of: ROIState.DELETED, ROIState.DELETED_SELECTED, ROIState.NORMAL, ROIState.SELECTED, ROIState.EDITABLE, ROIState.EDIT_OUTLINE.

isSelected

public boolean isSelected()
Returns true if this ROI is currently selected.

Returns:
true if this ROI is currently selected; false otherwise.

isEditable

public boolean isEditable()
Returns true if this ROI is currently editable.

Returns:
true if this ROI is currently editable; false otherwise.

isDeleted

public boolean isDeleted()
Returns true if this ROI has been deleted.

Returns:
true if this ROI has been deleted; false otherwise.

getImageSource

public java.lang.String getImageSource()
Returns the image source of this ROI. Normally the path name of the image on which this ROI was defined.

Returns:
the image source of this ROI.

isReloaded

public boolean isReloaded()
Returns true if this ROI has been reloaded from disk.

Returns:
true if this ROI has been reloaded from disk; false otherwise.

getStats

public static ROIStats getStats(java.util.List<? extends ROI> ROIs,
                                java.lang.Object pix,
                                PixelDataType dataType,
                                int nCols,
                                int nRows,
                                int offset,
                                float pixelXSize,
                                float pixelYSize,
                                CombineMode combineMode,
                                MaskAction maskAction,
                                MaskMode maskMode,
                                double maskValue,
                                ComplexMode complexMode)
Find combined statistics about a list of ROIs. The ROI statistics are returned for the shape that is combination of all the individual ROIs in the List, when they are combined using the specified CombineMode.

Parameters:
ROIs - a List of ROIs.
pix - the whole image pixel value array. If pix is null, then the intensity-related stats will all be set to zero.
dataType - the type of pixels.
nCols - the number of columns in the slice.
nRows - the number of rows in the slice.
offset - an offset (in pixels) into the pixel value array for the starting pixel of the slice on which this ROI is defined.
pixelXSize - the size of image pixels in the horizontal direction.
pixelYSize - the size of image pixels in the vertical direction.
combineMode - one of CombineMode.UNION for creating statistics about the union of all ROIs. CombineMode.INTERSECTION for creating statistics about the intersection of all ROIs. CombineMode.XOR for creating statistics about the sequential exclusive OR of all all ROIs. Starting with the first pair of ROIs in the list, an exclusive OR operation is applied pair-wise to the ROIs, and the resulting ROIs is exclusive OR'd with the next ROI in the list until the list is exhausted.
maskAction - one of:
  • MaskAction.NONE for no masking;
  • MaskAction.MASK_INSIDE to set pixel values to maskValue inside the shape; or
  • MaskAction.MASK_OUTSIDE to set the pixel values to maskValue outside the shape.
  • MaskAction.MASK_INSIDE_SOFT to perform soft masking inside the shape;
  • MaskAction.MASK_OUTSIDE_SOFT to perform soft masking outside the shape.
maskMode - how much of a pixel must be inside ROIs for the pixel to be part of the mask.
maskValue - the pixel value to set outside/inside the shape when performing masking ops.
complexMode - the calculation mode for Complex images. The statistics returned will correspond to the mode: the real part, imaginary part, magnitude or phase.
Returns:
statistics about the combined shape. If list is empty, or the combined shape is an empty (null) area, then null will be returned.

getStats

public ROIStats getStats(java.lang.Object pix,
                         PixelDataType dataType,
                         int nCols,
                         int nRows,
                         int offset,
                         float pixelXSize,
                         float pixelYSize,
                         ComplexMode complexMode)
Returns statistics about this ROI.

Parameters:
pix - the whole image pixel value array. If pix is null, then the intensity-related stats will all be set to zero.
dataType - the PixelDataType of the image pixels.
nCols - the number of columns in the slice.
nRows - the number of rows in the slice.
offset - an offset (in pixels) into the pixel value array for the starting pixel of the slice on which this ROI is defined.
pixelXSize - the size of image pixels in the horizontal direction.
pixelYSize - the size of image pixels in the vertical direction.
complexMode - the calculation mode for Complex images. The statistics returned will correspond to the mode: the real part, imaginary part, magnitude or phase.
Returns:
statistics about the ROI.

getStats

public ROIStats getStats(java.lang.Object pix,
                         PixelDataType dataType,
                         int nCols,
                         int nRows,
                         int offset,
                         float pixelXSize,
                         float pixelYSize,
                         MaskAction maskAction,
                         MaskMode maskMode,
                         double maskValue,
                         java.io.PrintStream intensityOutputStream,
                         boolean isUnitsMM,
                         ComplexMode complexMode)
Returns statistics about this ROI, and (optionally) performs a masking operation.

Parameters:
pix - the whole image pixel value array. If pix is null, then the intensity-related stats will all be set to zero.
dataType - the type of pixels.
nCols - the number of columns in the slice.
nRows - the number of rows in the slice.
offset - an offset (in pixels) into the pixel value array for the starting pixel of the slice on which this ROI is defined.
pixelXSize - the size of image pixels in the horizontal direction.
pixelYSize - the size of image pixels in the vertical direction.
maskAction - one of:
  • MaskAction.NONE for no masking;
  • MaskAction.MASK_INSIDE to set pixel values to maskValue inside the shape; or
  • MaskAction.MASK_OUTSIDE to set the pixel values to maskValue outside the shape.
  • MaskAction.MASK_INSIDE_SOFT to perform soft masking inside the shape;
  • MaskAction.MASK_OUTSIDE_SOFT to perform soft masking outside the shape.
maskMode - how much of a pixel must be inside ROIs for the pixel to be part of the mask.
maskValue - the pixel value to set outside/inside the shape when performing masking ops.
intensityOutputStream - if non-null, pixel intensities within the ROI will be printed to this PrintStream.
isUnitsMM - true if the (x,y) coordinates of the pixel intensities are to be written in mm, false if the coordinates are to be writtn in pixel units.
complexMode - the calculation mode for PixelDataType.Complex images. The statistics returned will correspond to the mode: the real part, imaginary part, magnitude or phase.
Returns:
statistics about the ROI.

getCachedStatistics

protected ROIStats getCachedStatistics()
Returns the cached ROI statistics, or null if there are none.


clearStats

public void clearStats()
Clears the cached statistics for this ROI, forcing them to be re-computed next time they are required.


getSlice

public int getSlice()
Returns the slice number for this ROI. Slice numbers are indexed from zero.


setSlice

public void setSlice(int s)
Sets the slice number for this ROI. Slice numbers are indexed from zero.


getFeret

public abstract Feret getFeret()
Returns the minimum and maximum Feret's diameter for this ROI, in mm.

Returns:
the minimum and maximum Feret's diameter (in mm) as a Feret object.

getFeret

public static Feret getFeret(java.util.List<ROI> ROIs)
Returns the minimum and maximum Feret's diameter for this List of ROI, in mm.

Returns:
the minimum and maximum Feret's diameter (in mm) as a Feret object.

getPerimeter

public abstract double getPerimeter()
Returns the perimeter length of this ROI.

Returns:
the perimeter length of this ROI.

write

public static void write(java.util.List<? extends ROI> rois,
                         java.io.Writer w,
                         java.lang.String source,
                         int nCols,
                         int nRows,
                         float pixelXSize,
                         float pixelYSize,
                         PixelDataType dataType,
                         ComplexMode complexMode)
                  throws java.io.IOException
Write a List of ROIs using the specified writer.

Parameters:
rois - a java.util.List<ROI> of ROIs to write.
w - the Writer using which the ROIs will be written.
source - a String describing the where the ROIs came from.
nCols - the number of columns in the source image.
nRows - the number of rows in the source image.
pixelXSize - the size of image pixels in the horizontal direction.
pixelYSize - the size of image pixels in the vertical direction.
dataType - the type of pixels for the image on which this ROI was created. This is needed in case the image is Complex, so that the intensity can be correctly annotated.
complexMode - for Complex images, this affects the way the intensity is annotated, but has no effect for other types of image.
Throws:
java.io.IOException - if the ROIs cannot be written.

write

public void write(java.io.Writer w,
                  java.lang.String source,
                  int nCols,
                  int nRows,
                  float pixelXSize,
                  float pixelYSize,
                  PixelDataType dataType,
                  ComplexMode complexMode)
           throws java.io.IOException
Writes this ROI in output format using the specified writer.

Parameters:
w - the Writer with which this ROI will be written.
source - a java.lang.String describing where this ROI came from.
nCols - the number of columns in the source image.
nRows - the number of rows in the source image.
pixelXSize - the size of image pixels in the horizontal direction.
pixelYSize - the size of image pixels in the vertical direction.
dataType - the type of pixels for the image on which this ROI was created. This is needed in case the image is Complex, so that the intensity can be correctly annotated.
complexMode - for PixelDataType.Complex images, this affects the way the intensity is annotated but has no effect for other types of image.
Throws:
java.io.IOException

printStats

public void printStats(java.io.PrintStream s,
                       int nCols,
                       int nRows,
                       float pixelXSize,
                       float pixelYSize,
                       PixelDataType dataType,
                       ComplexMode complexMode,
                       boolean writeColour,
                       boolean writeAnnotation,
                       boolean writeSlice,
                       boolean writeArea,
                       boolean writeMean,
                       boolean writeStddev,
                       boolean writeMin,
                       boolean writeMax,
                       boolean writeMedian,
                       boolean writeLength,
                       boolean writePerimeter,
                       boolean writeFeretMin,
                       boolean writeFeretMax)
Prints the statistics about this ROI in output format to a PrintStream.

Parameters:
s - the PrintStream to which this ROI will be printed.
nCols - the number of image columns.
nRows - the number of image rows.
pixelXSize - the size of image pixels in the horizontal direction.
pixelYSize - the size of image pixels in the vertical direction.
dataType - the type of pixels for the image on which this ROI was created. This is needed in case the image is PixelDataType.Complex, so that the intensity can be correctly annotated.
complexMode - for PixelDataType.Complex images, this affects th e way the intensity is annotated, but has no effect for other types of image.
writeColour - a flag to indicate that the ROI colour should be written.
writeAnnotation - a flag to indicate that ROI annotation should be written.
writeSlice - a flag to indicate that slice number should be written.
writeArea - a flag to indicate that ROI area should be written.
writeMean - a flag to indicate that mean intensity should be written.
writeMax - a flag to indicate that maximum intensity should be written.
writeMin - a flag to indicate that minimum intensity should be written.
writeLength - a flag to indicate that length of the ROI should be written. Only applied to LineROI and CurvedLineROI ROIs.
writeMedian - a flag to indicate that median intensity of the ROI should be written.
writePerimeter - a flag to indicate that perimeter length of the ROI should be written.
writeFeretMin - a flag to indicate that minimum Feret diameter of the ROI should be written.
writeFeretMax - a flag to indicate that maximum Feret diameter of the ROI should be written.

getROIs

public static java.util.List<ROI> getROIs(java.io.File f,
                                          java.lang.Float pixelXSize,
                                          java.lang.Float pixelYSize,
                                          java.lang.Integer nCols,
                                          java.lang.Integer nRows)
                                   throws java.io.IOException
Returns a List of ROIs read from an input File. If non-null values for the horizontal and vertical fields of view are supplied, then reading of ROI files from dispim is possible. The fields of view must be known since the coordinate system origin for dispim ROIs is at the top left of the image, while for the roi package it is in the centre of the field of view and a coordinate translation must be performed when reading in the ROIs.

Parameters:
f - the input File.
pixelXSize - the pixel size in the horizontal direction (pixel width).
pixelYSize - the pixel size in the vertical direction (pixel height).
nCols - the number of image columns (number of samples in the horizontal direction).
nRows - the number of image rows (number of samples in the vertical direction).
Throws:
java.io.IOException - if there is an error reading the ROIs from the File.

getROIs

public static java.util.List<ROI> getROIs(java.io.InputStream s)
                                   throws java.io.IOException
Returns a List of ROIs read from an InputStream.

Parameters:
s - the InputStream.
Throws:
java.io.IOException - if there is an error reading the ROIs from the InputStream.

getROIs

public static java.util.List<ROI> getROIs(java.io.InputStream s,
                                          java.lang.Float pixelXSize,
                                          java.lang.Float pixelYSize,
                                          java.lang.Integer nCols,
                                          java.lang.Integer nRows)
                                   throws java.io.IOException
Returns a List of ROIs read from an InputStream. If non-null values for the horizontal and vertical fields of view are supplied, then reading of ROI files from dispim is possible. The fields of view must be known since the coordinate system origin for dispim ROIs is at the top left of the image, while for the roi package it is in the centre of the field of view and a coordinate translation must be performed when reading in the ROIs.

Parameters:
s - the InputStream.
pixelXSize - the pixel size in the horizontal direction (pixel width).
pixelYSize - the pixel size in the vertical direction (pixel height).
nCols - the number of image columns (number of samples in the horizontal direction).
nRows - the number of image rows (number of samples in the vertical direction).
Throws:
java.io.IOException - if there is an error reading the ROIs from the InputStream.

moveROIs

public static void moveROIs(java.util.List<ROI> ROIList,
                            double dx,
                            double dy)
Move a List of ROIs by specified distances (in mm) in the x and y directions.

Parameters:
ROIList - a java.util.List<ROI< of ROIs to move.
dx - the distance to move in the x-direction.
dy - the distance to move in the y-direction.

join

public static java.util.List<ROI> join(java.util.List<ROI> ROIList)
                                throws ROIException
Joins a List of ROIs with a waisted join at the nearest point. Only IrregularROIs will be joined; all other types of ROI will be unchanged.

Parameters:
ROIList - a java.util.List<ROI> of ROIs to join.
Returns:
a java.util.List<ROI> of ROIs resulting from the join operation.
Throws:
ROIException - if an error occurs during the join operation.

getAnnotation

public java.lang.String getAnnotation()
Gets the anotation string for this ROI.

Returns:
the annotation string for this ROI.

setAnnotation

public void setAnnotation(java.lang.String annotation)
Sets the anotation string for this ROI.

Parameters:
annotation - the new annotation string for this ROI, or null to unset the annotation.

getClasses

public static java.lang.Class[] getClasses()
Returns an array of all known sub-classes of ROI.

Returns:
an array of all known sub-classes of ROI.

mmPosToPix

public static double mmPosToPix(double posMM,
                                float pixelSize,
                                int nPixels)
Convert from a position in mm to a pixel number coordinate. The centre of the field of view has a mm coordinate of zero. The pixel coordinate of zero is at the edge of the field of view (not the centre of the first sample).

Parameters:
posMM - the position in mm coordinates in this dimension of the image.
pixelSize - the pixel size in mm in this dimension of the image.
nPixels - the number of samples in this dimension of the image.

pixPosToMm

public static double pixPosToMm(double pixel,
                                int nPixels,
                                float pixelSize)
Convert from a pixel number to a position in mm. The centre of the field of view has a mm coordinate of zero. The pixel coordinate of zero is at the edge of the field of view (not the centre of the first sample).

Parameters:
pixel - the position in pixel coordinates in this dimension of the image.
nPixels - the number of samples in this dimension of the image.
pixelSize - the pixel size in mm in this dimension of the image.

getPixelValue

public static double getPixelValue(java.lang.Object pix,
                                   PixelDataType dataType,
                                   ComplexMode complexMode,
                                   int col,
                                   int row,
                                   int nCols,
                                   int nRows,
                                   int offset)
Returns the pixel value at a particular (column,row) of an array of pixels. If the PixelDataType is RGB_BY_PLANE, RGB_INTERLACED or COLOURPACKED, then the luminance value (= (0.299 * Red) + (0.587 * Green) + (0.114 * Blue)) is returned.

Parameters:
pix - the array of pixel values.
dataType - the type of pixels.
col - the column number of the pixel.
row - the row number of the pixel.
offset - an offset (in pixels) into the pixel value array for the starting pixel of the slice on which this ROI is defined.
nCols - the number of columns in the array.
nRows - the number of rows in the array.
complexMode - the calculation mode for PixelDataType.Complex images. The value returned will correspond to the mode: the real part, imaginary part, magnitude or phase.
Returns:
the pixel value at a particular (column,row) of an array of pixels as a double value.

getDisplayedBounds2D

public static java.awt.geom.Rectangle2D getDisplayedBounds2D(java.util.List<ROI> ROIList)
Returns a high-precision rectangle (in screen coordinates) that bounds all the ROIs in the ROIlist.

Parameters:
ROIList - a java.util.List<ROI> of ROIs.
Returns:
a Rectangle2D that just bounds the List of ROIs.

getDisplayedRoiArea

protected java.awt.geom.Area getDisplayedRoiArea()
Returns the java.awt.geom.Area of this ROI as it is displayed on-screen.

Returns:
the java.awt.geom.Area of this ROI as it is displayed on-screen.

getDisplayedBounds2D

public java.awt.geom.Rectangle2D getDisplayedBounds2D()
Returns a high-precision rectangle (in screen coordinates) that just bounds this ROI.

Returns:
a Rectangle2D that just bounds this ROI in screen coordinates.

getBoundingRectangle

public static java.awt.geom.Rectangle2D getBoundingRectangle(java.util.List<ROI> ROIList,
                                                             int nCols,
                                                             int nRows,
                                                             float pixelXSize,
                                                             float pixelYSize)
Returns a high-precision rectangle (in image pixel coordinates) that bounds all the ROIs in the ROIlist.

Parameters:
ROIList - a java.util.List<ROI> of ROIs.
nCols - the number of columns in the image on which this ROI is defined.
nRows - the number of rows in the image on which this ROI is defined.
pixelXSize - pixel width for the image on which this ROI is defined.
pixelYSize - pixel height for the image on which this ROI is defined.
Returns:
a Rectangle2D that just bounds the java.util.List<ROI> of ROIs, in pixel coodinates.

getBoundingRectangle

public java.awt.geom.Rectangle2D getBoundingRectangle(int nCols,
                                                      int nRows,
                                                      float pixelXSize,
                                                      float pixelYSize)
Returns a high-precision rectangle (in image pixel coordinates) that just bounds this ROI.

Parameters:
nCols - the number of columns in the image on which this ROI is defined.
nRows - the number of rows in the image on which this ROI is defined.
pixelXSize - pixel width for the image on which this ROI is defined.
pixelYSize - pixel height for the image on which this ROI is defined.
Returns:
a Rectangle2D that just bounds this ROI.

selectDeselect

public boolean selectDeselect(java.awt.Point point,
                              boolean editMode,
                              boolean showDeleted,
                              int nAlreadySelected)
Selects or deselects an ROI after a user click at the point.

Parameters:
point - the Point at which the user has clicked.
editMode - true if the tool working with ROIs is in edit mode; false if it is in view mode.
showDeleted - true if the tool working with ROIs is set to show deleted ROIs; false if it is not.
nAlreadySelected - the number of ROIs already selected. This determines the exact selection/deselection behaviour.
Returns:
true if the selection was changed.

draw

public boolean draw(java.awt.Graphics g,
                    java.awt.Rectangle visibleRectangle,
                    int imageDrawCols,
                    int imageDrawRows,
                    int xOffset,
                    int yOffset,
                    int nCols,
                    int nRows,
                    float pixelXSize,
                    float pixelYSize,
                    boolean drawAnnotation)
Draws this ROI if it needs to be be drawn on screen.

Parameters:
g - the graphics context for the drawing operation.
visibleRectangle - the part of the image that can be seen on-screen.
imageDrawCols - width of the area in which this portion of the image is to be drawn.
imageDrawRows - height of the area in which this portion of the image is to be drawn.
xOffset - a horizontal offset for drawing operations.
yOffset - a vertical offset for drawing operations.
nCols - the number of columns in the image on which this ROI is defined.
nRows - the number of rows in the image on which this ROI is defined.
pixelXSize - pixel width for the image on which this ROI is defined.
pixelYSize - pixel height for the image on which this ROI is defined.
drawAnnotation - a flag to indicate whether annotation should be drawn.
Returns:
true if the ROI is visible and been drawn on screen; false otherwise.

drawInOrthoView

public abstract void drawInOrthoView(java.awt.Image orthoView,
                                     javax.vecmath.Point3f viewPosition,
                                     javax.media.j3d.Transform3D imageToViewTx,
                                     int nCols,
                                     int nRows,
                                     int nSlices,
                                     float pixelXSize,
                                     float pixelYSize,
                                     boolean filled)
Draws this ROI on top of an orthogonal view of an image.

Parameters:
orthoView - the java.awt.Image into which the ROI is to be drawn.
viewPosition - the coordinates (col, row, slice position) of the orthogonal view in the original image.
imageToViewTx - the Transform3D that maps original image pixel coordinates to pixel coordinates in the orthogonal view.
nCols - the number of columns in the original image.
nRows - the number of rows in the original image.
nSlices - the number of slices in the original image.
pixelXSize - the pixel width in the original image.
pixelYSize - the pixel height in the original image.
filled - whether the ROI should be drawn filled (effective only for ROIs that enclose an area).

getColor

public java.awt.Color getColor()
Returns the java.awt.Color in which this ROI should be drawn. The drawn colour of an ROI depends on its state.

Returns:
the java.awt.Color with which this ROI should be drawn.

getUserColour

public byte getUserColour()
Returns the user-defined colour for this ROI.

Returns:
a value which is an index to the user-defined colour. A return value of 0 indicates the a user-defined colour hasn't been set; values greater than zero are the index into the user-defined colour palette.

setUserColour

public void setUserColour(byte index)
Sets the user-defined colour for this ROI.

Parameters:
index - a value which is an index to the user-defined colour. A value of 0 indicates the a user-defined colour is to be unset; values greater than zero are the index into the user-defined colour palette of user-settable ROI colours.

setTextColor

public static void setTextColor(java.awt.Color c)
Sets the colour with which ROI annotation text should be drawn.

Parameters:
c - the colour with which ROI annotation text is to be drawn.

setTextSize

public static void setTextSize(int size)
Sets the font size at which ROI annotation text should be drawn.

Parameters:
size - the font size at which ROI annotation text is to be drawn.

main

public static void main(java.lang.String[] args)
Run the test suite for ROIs.



Copyright 2006-2011 Xinapse Systems Limited. All Rights Reserved.