Package com.xinapse.multisliceimage.roi
Class ROI
java.lang.Object
com.xinapse.multisliceimage.roi.ROI
- Direct Known Subclasses:
EllipticalROI,HollowROI,IrregularROI,LineROI,Marker,RadialDivider,RectangularROI,SplineROI
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:
- The shape is fundamentally represented in mm coordinate space.
- When associated with an image slice, there is a cached representation in image pixel coordinates.
- When an
ROIis visible on-screen, there is a cached representation in screen coordinates.
ROI is moved, or the shape is changed, the caches are cleared, and
the representations in pixel and screen coordinates are recalculated as needed.
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
FieldsModifier and TypeFieldDescriptionstatic final intThe standard (square) size for icons on ROI creation buttons.protected Handle[]If an ROI is editable, it will be drawn with handles.static final StringThe node name for all Preferences to do with ROIs.static final StringThe token written to ROI output files to represent an x-coordinate.static final StringThe token written to ROI output files to represent a y-coordinate. -
Method Summary
Modifier and TypeMethodDescriptionLogically AND NOTs (subtracts) an ROI from this ROI to create a newjava.util.List<ROI>of ROIs that is the result of subtracting the shape of the supplied ROI from this ROI.andNot(ROI roi, IndeterminateProgressMonitor progressMonitor) Logically AND NOTs (subtracts) an ROI from this ROI to create a newjava.util.List<ROI>of ROIs that is the result of subtracting the shape of the supplied ROI from this ROI.andNot(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) Logically AND NOTs (subtracts) a List of ROIs from this ROI to create a newjava.util.List<ROI>of ROIs that is the result of subtracting the shapes of the ROIs.voidRemoved the deletion HistoryItem for this ROI.clone()Returns a clone of thisROI.abstract booleandilate(double radius) Dilates this ROI by the specified distance.booleandraw(Graphics g, Rectangle visibleRectangle, int imageDrawCols, int imageDrawRows, int xOffset, int yOffset, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean drawAnnotation) Draws thisROIif it needs to be be drawn on screen.abstract voiddrawInOrthoView(Image orthoView, org.jogamp.vecmath.Point3f viewPosition, org.jogamp.java3d.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 booleanexclusiveOr(ROI roi, IndeterminateProgressMonitor progressMonitor) Performs an exclusive OR operation on the shape of this ROI with another ROI.exclusiveOr(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) Performs an exclusive OR (XOR) operation on the shape of this ROI with another ROI.abstract voidflipHorizontal(Point2D flipPoint) Flip thisROIhorizontally about a given location.abstract voidflipVertical(Point2D flipPoint) Flip thisROIvertically about a given location.Gets the anotation string for thisROI.getBoundingRectangle(int nCols, int nRows, float pixelXSize, float pixelYSize) Returns a high-precision rectangle (in image pixel coordinates) that just bounds thisROI.static Rectangle2DgetBoundingRectangle(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.abstract org.jogamp.vecmath.Point2dReturns the centroid (centre of area) of thisROI.static org.jogamp.vecmath.Point2dgetCentroid(ROI[] rois) Returns the centroid (centre of area) of an array of ROIs.Returns an array of all known sub-classes ofROI.getColor()abstract ROIgetCopy()Returns a copy of thisROI.abstract StringReturn a description of this type ofROI.static intReturns the font size at which ROI annotation text should be rendered.Returns a high-precision rectangle (in screen coordinates) that just bounds thisROI.static Rectangle2DgetDisplayedBounds2D(List<ROI> ROIList) Returns a high-precision rectangle (in screen coordinates) that bounds all the ROIs in the ROIlist.protected AreaReturns theAreaof this ROI as it is displayed on-screen.abstract FeretgetFeret()Returns the minimum and maximum Feret's diameter for thisROI, in mm.static Feretcom.xinapse.dicom.UidReturns the group UID for this ROI.static com.xinapse.dicom.UidgetGroupUid(List<ROI> roiList) Returns the Group UID of the ROIs supplied if they are all members of the same group (i.e., they all have the same Group UID).Handle[]getHandleUnderPoint(Point point) Returns the image source of thisROI.abstract doubleReturns the perimeter length of thisROI.static doublegetPixelValue(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.getROIs(File f, Float pixelXSize, Float pixelYSize, Integer nCols, Integer nRows, MonitorWorker worker) Returns aListof ROIs read from anInputStream.Returns aListof ROIs read from anInputStream.getROIs(InputStream s, Float pixelXSize, Float pixelYSize, Integer nCols, Integer nRows, MonitorWorker worker) Returns aListof ROIs read from anInputStream.intgetSlice()Returns the slice number for thisROI.getState()Returns the state of thisROI.getStats(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, ComplexMode complexMode) Returns statistics about this ROI.getStats(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, MaskAction maskAction, MaskMode maskMode, double maskValue, PrintStream intensityOutputStream, boolean isUnitsMM, ComplexMode complexMode) Returns statistics about thisROI, and (optionally) performs a masking operation.static ROIStatsgetStats(List<? extends ROI> ROIs, 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.static ColorReturns theColorwith which ROI annotation text should be rendered.byteReturns the user-defined colour for this ROI.static voidForm an ROI group from a List of ROIs.inthashCode()Returns a hash code value for theROI.intersect(ROI roi, IndeterminateProgressMonitor progressMonitor) Performs an intersection operation on the shape of this ROI with another ROI.intersect(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) Performs an intersection operation on the shape of this ROI with a List of other ROIs.booleanintersects(ROI roi) booleanReturnstrueif thisROIhas been deleted.booleanReturnstrueif thisROIis currently editable.static booleanTests whether all the ROIs supplied are members of the same group (i.e., they all have the same Group UID).booleanReturnstrueif thisROIhas been reloaded from disk.static booleanisSameAnnotation(List<ROI> roiList) Tests whether all the ROIs supplied have the same annotation.static booleanisSameColour(List<ROI> roiList) Tests whether all the ROIs supplied have the same colour.booleanReturnstrueif thisROIis currently selected.Joins aListof ROIs with a waisted join at the nearest point.logicalUnion(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) Logically adds a List of ROIs to create a newjava.util.List<ROI>of ROIs that is the result of logically adding (forming the union of) the shapes of the ROIs.static voidRun the self-test for the ROI class.voidMark thisROIas deleted.static doublemmPosToPix(double posMM, float pixelSize, int nPixels) Convert from a position in mm to a pixel number coordinate.abstract voidmove(double dx, double dy) Move thisROIby specified distances (in mm) in the x and y directions.static voidMove aListof ROIs by specified distances (in mm) in the x and y directions.static doublepixPosToMm(double pixel, int nPixels, float pixelSize) Convert from a pixel number to a position in mm.voidprintStats(PrintStream s, Object pixels, 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, String separator) Prints the statistics about thisROIin output format to a PrintStream.booleanselectDeselect(Point point, boolean editMode, boolean showDeleted, int nAlreadySelected) Selects or deselects anROIafter a user click at the point.abstract voidvoidsetAnnotation(String annotation) Sets the anotation string for thisROI.protected voidsetCreationHistory(HistoryItem history) Sets the creation history HistoryItem for this ROI.voidsetGroupUid(com.xinapse.dicom.Uid uid) Sets the group UID for this ROI.voidsetSlice(int s) Sets the slice number for thisROI.voidSets the state of thisROI.static voidSets the colour with which ROI annotation text should be drawn.static voidsetTextSize(int size) Sets the font size at which ROI annotation text should be drawn.voidsetUserColour(byte index) Sets the user-defined colour for this ROI.abstract StringtoString()static intUngroups all ROIs in the list.static voidUngroups the ROIs belonging to a particular ROI group.union(ROI roi, IndeterminateProgressMonitor progressMonitor) Logically add (forms the union) an ROI to this ROI to create a newjava.util.List<ROI>of ROIs that is the result of adding the shapes of the two ROIs.union(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) Logically forms the union of a List of ROIs and this ROI to create a newjava.util.List<ROI>of ROIs that is the result of adding (forming the union of) the shapes of the ROIs to this ROI.voidwrite(Writer w, String source, Object pix, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode) Writes thisROIin output format using the specified writer.static voidwrite(List<? extends ROI> rois, Writer w, String source, Object pix, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode) Write aListof ROIs using the specified writer.
-
Field Details
-
PREFERENCES_NODE_NAME
The node name for all Preferences to do with ROIs.- See Also:
-
BUTTON_ICON_SIZE
public static final int BUTTON_ICON_SIZEThe standard (square) size for icons on ROI creation buttons.- See Also:
-
XTOKEN
The token written to ROI output files to represent an x-coordinate.- See Also:
-
YTOKEN
The token written to ROI output files to represent a y-coordinate.- See Also:
-
handles
If an ROI is editable, it will be drawn with handles.
-
-
Method Details
-
getTextColor
Returns theColorwith which ROI annotation text should be rendered.- Returns:
- the
Colorwith which ROI annotation text should be rendered.
-
getDesignTextFontSize
public static int getDesignTextFontSize()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
Sets the creation history HistoryItem for this ROI.- Parameters:
history- the HistoryItem to set.
-
clearDeletionHistory
public void clearDeletionHistory()Removed the deletion HistoryItem for this ROI. Needed to "undelete" an ROI. -
getDescription
Return a description of this type ofROI.- Returns:
- a String describing the type of this
ROI.
-
move
public abstract void move(double dx, double dy) Move thisROIby 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
Flip thisROIvertically about a given location.- Parameters:
flipPoint- the point about which the ROI will be flipped.
-
flipHorizontal
Flip thisROIhorizontally about a given location.- Parameters:
flipPoint- the point about which the ROI will be flipped.
-
union
public List<ROI> union(ROI roi, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Logically add (forms the union) an ROI to this ROI to create a newjava.util.List<ROI>of ROIs that is the result of adding the shapes of the two ROIs.- Parameters:
roi- the ROI to add.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that results from the addition of the shape.
- Throws:
ROIException- if an error occurs while constructing the new ROIs.CancelledException- if the operation is cancelled by the user.
-
logicalUnion
public static List<ROI> logicalUnion(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Logically adds a List of ROIs to create a newjava.util.List<ROI>of ROIs that is the result of logically adding (forming the union of) the shapes of the ROIs.- Parameters:
rois- the ROIs to add.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that results from the addition of the shape.
- Throws:
ROIException- if creation of the new ROIs generates an error.CancelledException- if the operation is cancelled by the user.
-
union
public List<ROI> union(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Logically forms the union of a List of ROIs and this ROI to create a newjava.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.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that results from the addition of the shapes.
- Throws:
ROIException- if creation of the new ROIs generates an error.CancelledException- if the operation is cancelled by the user.
-
andNot
Logically AND NOTs (subtracts) an ROI from this ROI to create a newjava.util.List<ROI>of ROIs that is the result of subtracting the shape of the supplied ROI from this ROI.- Parameters:
roi- the ROI to subtract.- Returns:
- a List<ROI> of ROIs that results from the subtraction of the ROI.
- Throws:
ROIException- if creation of the new ROIs generates an error.
-
andNot
public List<ROI> andNot(ROI roi, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Logically AND NOTs (subtracts) an ROI from this ROI to create a newjava.util.List<ROI>of ROIs that is the result of subtracting the shape of the supplied ROI from this ROI.- Parameters:
roi- the ROI to subtract.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that results from the subtraction of the ROI.
- Throws:
ROIException- if creation of the new ROIs generates an error.CancelledException- if the operation is cancelled by the user.
-
andNot
public List<ROI> andNot(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Logically AND NOTs (subtracts) a List of ROIs from this ROI to create a newjava.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.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that results from the subtraction of the ROIs.
- Throws:
ROIException- if creation of the new ROIs generates an error.CancelledException- if the operation is cancelled by the user.
-
intersects
Tests whether thisROIintersects anotherROI.Note that the ROIs may intersect, but the area of intersection may be zero if one or other (or both) of the
ROIs contains no area.- Parameters:
roi- the ROI to be tested for intersection.- Returns:
truein the two ROIs intersect;falseotherwise.
-
intersect
- Parameters:
roi- theROIto intersect with thisROI.- Returns:
- the resulting List<ROI> of ROIs that result from the operation.
- Throws:
ROIException- if the operation cannot be performed.
-
intersect
public List<ROI> intersect(ROI roi, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Performs an intersection operation on the shape of this ROI with another ROI.- Parameters:
roi- the ROI with which to perform the intersection operation.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that result from the operation.
- Throws:
ROIException- if the operation cannot be performed.CancelledException- if the operation is cancelled by the user.
-
intersect
public List<ROI> intersect(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Performs an intersection operation on the shape of this ROI with a List of other ROIs.- Parameters:
rois- the List of ROIs with which to perform the intersection operation.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that result from the operation.
- Throws:
ROIException- if the operation cannot be performed.CancelledException- if the operation is cancelled by the user.
-
exclusiveOr
public List<ROI> exclusiveOr(ROI roi, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException 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.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that result from the operation.
- Throws:
ROIException- if the operation cannot be performed.CancelledException- if the operation is cancelled by the user.
-
exclusiveOr
public List<ROI> exclusiveOr(List<ROI> rois, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Performs an exclusive OR (XOR) operation on the shape of this ROI with another ROI.- Parameters:
rois- the ROI with which to perform the XOR operations.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that result from the operation.
- Throws:
ROIException- if the operation cannot be performed.CancelledException- if the operation is cancelled by the user.
-
dilate
Dilates this ROI by the specified distance.- Parameters:
radius- the radius of dilation. A positive radius will result in a dilation, while a negative radius will result in an erosion.- Returns:
- a
Listof ROIs that result from the operation. The List will be empty if the dilation results in an empty region.
-
markDeleted
public void markDeleted()Mark thisROIas deleted. -
group
Form an ROI group from a List of ROIs.- Parameters:
rois- the ROIs to group.
-
ungroup
Ungroups the ROIs belonging to a particular ROI group.- Parameters:
rois- a List of ROIs.uid- the UID for the group to be ungrouped.
-
ungroup
Ungroups all ROIs in the list.- Parameters:
rois- a List of ROIs.- Returns:
- the number of groups that were ungrouped.
-
getGroupUid
public com.xinapse.dicom.Uid getGroupUid()Returns the group UID for this ROI.- Returns:
- the group uid for this ROI, or null if it not part of a group.
-
setGroupUid
public void setGroupUid(com.xinapse.dicom.Uid uid) Sets the group UID for this ROI.- Parameters:
uid- the group uid for this ROI, or null if it not to be part of a group.
-
isGroup
Tests whether all the ROIs supplied are members of the same group (i.e., they all have the same Group UID).- Parameters:
roiList- the List of ROIs to test for group membership.- Returns:
trueif all the ROIs are members of one group;falseotherwise.
-
getGroupUid
Returns the Group UID of the ROIs supplied if they are all members of the same group (i.e., they all have the same Group UID).- Parameters:
roiList- the List of ROIs for which to return the group UID.- Returns:
- Returns the Group UID of the ROIs supplied, or
nullif they are not all members of the same group.
-
isSameAnnotation
Tests whether all the ROIs supplied have the same annotation.- Parameters:
roiList- the List of ROIs to see whether thy all have the same annotation.- Returns:
trueif all the ROIs have the same annotation;falseotherwise.
-
isSameColour
Tests whether all the ROIs supplied have the same colour.- Parameters:
roiList- the List of ROIs to see whether thy all have the same colour.- Returns:
trueif all the ROIs have the same colour;falseotherwise.
-
contains
-
equals
-
hashCode
public int hashCode() -
set
- Parameters:
roi- the ROI from which the shape is set.- Throws:
ClassCastException- if the sub-class of the argumentROIis not the same as thisROI.
-
getCopy
Returns a copy of thisROI. 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.
-
clone
-
toString
-
getHandleUnderPoint
-
getHandles
-
getState
Returns the state of thisROI.- Returns:
- the
ROIStateof thisROI. One of:ROIState.DELETED,ROIState.DELETED_SELECTED,ROIState.NORMAL,ROIState.SELECTED,ROIState.EDITABLE,ROIState.EDIT_OUTLINE.
-
setState
Sets the state of thisROI.- Parameters:
state- theROIStateof thisROIto be set. One of:ROIState.DELETED,ROIState.DELETED_SELECTED,ROIState.NORMAL,ROIState.SELECTED,ROIState.EDITABLE,ROIState.EDIT_OUTLINE.
-
isSelected
public boolean isSelected()Returnstrueif thisROIis currently selected.- Returns:
trueif thisROIis currently selected;falseotherwise.
-
isEditable
public boolean isEditable()Returnstrueif thisROIis currently editable.- Returns:
trueif thisROIis currently editable;falseotherwise.
-
isDeleted
public boolean isDeleted()Returnstrueif thisROIhas been deleted.- Returns:
trueif thisROIhas been deleted;falseotherwise.
-
getImageSource
Returns the image source of thisROI. Normally the path name of the image on which thisROIwas defined.- Returns:
- the image source of this
ROI.
-
isReloaded
public boolean isReloaded()Returnstrueif thisROIhas been reloaded from disk.- Returns:
trueif thisROIhas been reloaded from disk;falseotherwise.
-
getStats
public static ROIStats getStats(List<? extends ROI> ROIs, 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 theList, when they are combined using the specifiedCombineMode.- 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.NONEfor no masking;MaskAction.MASK_INSIDEto set pixel values to maskValue inside the shape; orMaskAction.MASK_OUTSIDEto set the pixel values to maskValue outside the shape.MaskAction.MASK_INSIDE_SOFTto perform soft masking inside the shape;MaskAction.MASK_OUTSIDE_SOFTto 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
nullwill be returned.
-
getStats
public ROIStats getStats(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- thePixelDataTypeof 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(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, MaskAction maskAction, MaskMode maskMode, double maskValue, PrintStream intensityOutputStream, boolean isUnitsMM, ComplexMode complexMode) Returns statistics about thisROI, 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 thisROIis 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.NONEfor no masking;MaskAction.MASK_INSIDEto set pixel values to maskValue inside the shape; orMaskAction.MASK_OUTSIDEto set the pixel values to maskValue outside the shape.MaskAction.MASK_INSIDE_SOFTto perform soft masking inside the shape;MaskAction.MASK_OUTSIDE_SOFTto 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 thisPrintStream.isUnitsMM-trueif the (x,y) coordinates of the pixel intensities are to be written in mm,falseif the coordinates are to be writtn in pixel units.complexMode- the calculation mode forPixelDataType.COMPLEXimages. The statistics returned will correspond to the mode: the real part, imaginary part, magnitude or phase.- Returns:
- statistics about the ROI.
-
getSlice
public int getSlice()Returns the slice number for thisROI. Slice numbers are indexed from zero.- Returns:
- the slice number for this
ROI.
-
setSlice
public void setSlice(int s) Sets the slice number for thisROI. Slice numbers are indexed from zero.- Parameters:
s- the new slice number for thisROI.
-
getFeret
Returns the minimum and maximum Feret's diameter for thisROI, in mm.- Returns:
- the minimum and maximum Feret's diameter (in mm) as a
Feretobject.
-
getFeret
-
getPerimeter
public abstract double getPerimeter()Returns the perimeter length of thisROI.- Returns:
- the perimeter length of this
ROI.
-
getCentroid
public abstract org.jogamp.vecmath.Point2d getCentroid()Returns the centroid (centre of area) of thisROI.- Returns:
- the centroid of this
ROI.
-
getCentroid
Returns the centroid (centre of area) of an array of ROIs.- Parameters:
rois- the set of ROIs for which to find the centroid.- Returns:
- the centroid of the array of
ROI.
-
write
public static void write(List<? extends ROI> rois, Writer w, String source, Object pix, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode) throws IOException Write aListof ROIs using the specified writer.- Parameters:
rois- ajava.util.List<ROI>of ROIs to write.w- theWriterusing which the ROIs will be written.source- a String describing the where the ROIs came from.pix- the image pixels used to calculate intensity-related statistics if non-null.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:
IOException- if the ROIs cannot be written.
-
write
public void write(Writer w, String source, Object pix, int nCols, int nRows, float pixelXSize, float pixelYSize, PixelDataType dataType, ComplexMode complexMode) throws IOException Writes thisROIin output format using the specified writer.- Parameters:
w- theWriterwith which thisROIwill be written.source- aStringdescribing where thisROIcame from.pix- the image pixels used to calculate intensity-related statistics if non-null.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 thisROIwas created. This is needed in case the image is Complex, so that the intensity can be correctly annotated.complexMode- forPixelDataType.COMPLEXimages, this affects the way the intensity is annotated but has no effect for other types of image.- Throws:
IOException- if an I/O error occurs.
-
printStats
public void printStats(PrintStream s, Object pixels, 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, String separator) Prints the statistics about thisROIin output format to a PrintStream.- Parameters:
s- thePrintStreamto which thisROIwill be printed.pixels- the image pixel values for the whole image, from which intensity statistics will be calculated.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 isPixelDataType.COMPLEX, so that the intensity can be correctly annotated.complexMode- forPixelDataType.COMPLEXimages, 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.writeStddev- a flag to indicate that intensity standard deviation 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 toLineROIandCurvedLineROIROIs.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.separator- the separator to be used to separate the individual statistics.
-
getROIs
public static List<ROI> getROIs(File f, Float pixelXSize, Float pixelYSize, Integer nCols, Integer nRows) throws IOException Returns aListof ROIs read from an inputFile. 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 inputFile.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).- Returns:
- a
Listof ROIs read from theFile. - Throws:
IOException- if there is an error reading the ROIs from theFile.
-
getROIs
public static List<ROI> getROIs(File f, Float pixelXSize, Float pixelYSize, Integer nCols, Integer nRows, MonitorWorker worker) throws IOException, CancelledException Returns aListof ROIs read from an inputFile. 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 inputFile.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).worker- if non-null theMonitorWorkerthat can be used to cancel the operation.- Returns:
- a
Listof ROIs read from theFile. - Throws:
IOException- if there is an error reading the ROIs from theFile.CancelledException- if the operation is cancelled by the user.
-
getROIs
Returns aListof ROIs read from anInputStream.- Parameters:
s- theInputStream.- Returns:
- a java.util.List<ROI> of ROIs read from the
InputStream. - Throws:
IOException- if there is an error reading the ROIs from theInputStream.
-
getROIs
public static List<ROI> getROIs(InputStream s, Float pixelXSize, Float pixelYSize, Integer nCols, Integer nRows) throws IOException Returns aListof ROIs read from anInputStream. 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- theInputStream.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).- Returns:
- a
Listof ROIs read from theInputStream. - Throws:
IOException- if there is an error reading the ROIs from theInputStream.
-
getROIs
public static List<ROI> getROIs(InputStream s, Float pixelXSize, Float pixelYSize, Integer nCols, Integer nRows, MonitorWorker worker) throws IOException, CancelledException Returns aListof ROIs read from anInputStream. 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- theInputStream.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).worker- if non-null theMonitorWorkerthat can be used to cancel the operation.- Returns:
- a java.util.List<ROI> of ROIs read from the
InputStream. - Throws:
IOException- if there is an error reading the ROIs from theInputStream.CancelledException- if the operation is cancelled by the user.
-
moveROIs
Move aListof ROIs by specified distances (in mm) in the x and y directions.- Parameters:
ROIList- ajava.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
Joins aListof ROIs with a waisted join at the nearest point. OnlyIrregularROIs will be joined; all other types ofROIwill be unchanged.- Parameters:
ROIList- ajava.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
Gets the anotation string for thisROI.- Returns:
- the annotation string for this
ROI.
-
setAnnotation
Sets the anotation string for thisROI.- Parameters:
annotation- the new annotation string for thisROI, ornullto unset the annotation.
-
getClasses
Returns an array of all known sub-classes ofROI.- 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.- Returns:
- real-space (mm) position, in pixels.
-
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.- Returns:
- the position of the pixel, in mm.
-
getPixelValue
public static double getPixelValue(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 thePixelDataTypeisPixelDataType.RGB_BY_PLANE,PixelDataType.RGB_INTERLACEDorPixelDataType.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 forPixelDataType.COMPLEXimages. 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
Returns a high-precision rectangle (in screen coordinates) that bounds all the ROIs in the ROIlist.- Parameters:
ROIList- ajava.util.List<ROI>of ROIs.- Returns:
- a
Rectangle2Dthat just bounds theListof ROIs.
-
getDisplayedRoiArea
Returns theAreaof this ROI as it is displayed on-screen.- Returns:
- the
Areaof this ROI as it is displayed on-screen.
-
getDisplayedBounds2D
Returns a high-precision rectangle (in screen coordinates) that just bounds thisROI.- Returns:
- a
Rectangle2Dthat just bounds thisROIin screen coordinates.
-
getBoundingRectangle
public static Rectangle2D getBoundingRectangle(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- ajava.util.List<ROI>of ROIs.nCols- the number of columns in the image on which thisROIis defined.nRows- the number of rows in the image on which thisROIis defined.pixelXSize- pixel width for the image on which thisROIis defined.pixelYSize- pixel height for the image on which thisROIis defined.- Returns:
- a
Rectangle2Dthat just bounds thejava.util.List<ROI>of ROIs, in pixel coordinates.
-
getBoundingRectangle
Returns a high-precision rectangle (in image pixel coordinates) that just bounds thisROI.- Parameters:
nCols- the number of columns in the image on which thisROIis defined.nRows- the number of rows in the image on which thisROIis defined.pixelXSize- pixel width for the image on which thisROIis defined.pixelYSize- pixel height for the image on which thisROIis defined.- Returns:
- a
Rectangle2Dthat just bounds thisROI.
-
selectDeselect
public boolean selectDeselect(Point point, boolean editMode, boolean showDeleted, int nAlreadySelected) Selects or deselects anROIafter a user click at the point.- Parameters:
point- thePointat which the user has clicked.editMode-trueif the tool working with ROIs is in edit mode;falseif it is in view mode.showDeleted-trueif the tool working with ROIs is set to show deleted ROIs;falseif it is not.nAlreadySelected- the number of ROIs already selected. This determines the exact selection/deselection behaviour.- Returns:
trueif the selection was changed.
-
draw
public boolean draw(Graphics g, Rectangle visibleRectangle, int imageDrawCols, int imageDrawRows, int xOffset, int yOffset, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean drawAnnotation) Draws thisROIif 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 thisROIis defined.nRows- the number of rows in the image on which thisROIis defined.pixelXSize- pixel width for the image on which thisROIis defined.pixelYSize- pixel height for the image on which thisROIis defined.drawAnnotation- a flag to indicate whether annotation should be drawn.- Returns:
trueif theROIis visible and been drawn on screen;falseotherwise.
-
drawInOrthoView
public abstract void drawInOrthoView(Image orthoView, org.jogamp.vecmath.Point3f viewPosition, org.jogamp.java3d.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- theImageinto which the ROI is to be drawn.viewPosition- the coordinates (col, row, slice position) of the orthogonal view in the original image.imageToViewTx- theTransform3Dthat 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
-
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
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
Run the self-test for the ROI class.- Parameters:
args- ignored.
-