Package gov.nih.mipav.model.algorithms
Class AlgorithmMorphology25D
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmMorphology25D
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmMorphology25D extends AlgorithmBase
2.5D mathmatical morphology class (2D morphology on 3D volumes). Kernels of 3x3 (4 or 8 connected) and 5x5 (12 connected) are available or user defined kernels can be supplied.Supported methods include:
- erode
- dilate
- open
- close
- Morphological gradient
Adapted from AlgoritmMorphology2D by Matthew J. McAuliffe, Ph.D.
- Version:
- 1.0 June 8, 2004
- Author:
- Evan McCreedy
-
-
Field Summary
Fields Modifier and Type Field Description private intalgorithmDOCUMENT ME!static intBG_DISTANCE_MAPDOCUMENT ME!static intBORDER_CLEARINGprivate floatcircleDiameterDOCUMENT ME!static intCLOSEDOCUMENT ME!static intCLOSING_BY_RECONSTRUCTIONstatic intCONNECTED12DOCUMENT ME!static intCONNECTED4DOCUMENT ME!static intCONNECTED8DOCUMENT ME!static intDELETE_OBJECTSDOCUMENT ME!static intDILATEDOCUMENT ME!static intDISTANCE_MAPDOCUMENT ME!private booleanentireImageDOCUMENT ME!static intERODEDOCUMENT ME!static intFILL_HOLESDOCUMENT ME!static intFIND_EDGESDOCUMENT ME!static intGEODESIC_DILATIONstatic intGEODESIC_EROSIONprivate intgeodesicSizeSize of geodesic erosions and dilationsstatic intID_OBJECTSDOCUMENT ME!private short[]imgBufferDOCUMENT ME!private short[]imgBuffer2private intimgLengthDOCUMENT ME!static intINNER_EDGINGDOCUMENT ME!private intiterationsDDOCUMENT ME!private intiterationsEDOCUMENT ME!private intkDimDOCUMENT ME!private java.util.BitSetkernelDOCUMENT ME!private intkernelTypeprivate short[]maskBufferprivate ModelImagemaskImageUsed in geodesic dilation, geodesic erosion, morphological reconstruction by dilation, and morphological reconstruction by erosion Not used in opening by reconstruction and closing by reconstructionstatic intMORPHOLOGICAL_GRADIENTstatic intMORPHOLOGICAL_RECONSTRUCTION_BY_DILATIONstatic intMORPHOLOGICAL_RECONSTRUCTION_BY_EROSIONprivate intnumPruningPixelsNumber pixels to prune.static intOPENDOCUMENT ME!static intOPENING_BY_RECONSTRUCTIONstatic intOUTER_EDGINGDOCUMENT ME!static intPARTICLE_ANALYSISDOCUMENT ME!static intPARTICLE_ANALYSIS_NEWDOCUMENT ME!private short[]processBufferDOCUMENT ME!static intSIZED_CIRCLEDOCUMENT ME!static intSKELETONIZEDOCUMENT ME!private intsliceLengthDOCUMENT ME!static intULTIMATE_ERODEDOCUMENT ME!-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmMorphology25D(ModelImage srcImg, int kernelType, float circleDiameter, int method, int iterD, int iterE, int pruningPix, int edType, boolean entireImage)Creates a new AlgorithmMorphology25D object.AlgorithmMorphology25D(ModelImage srcImg, ModelImage maskImage, int kernelType, float circleDiameter, int method, int geodesicSize, int iterD, int iterE, boolean entireImage)Creates a new AlgorithmMorphology25D object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidborderClearing(boolean returnFlag)Removes objects that touch (i.e., are connected to) the borderprivate voiddilate(boolean returnFlag, int iters)Dilates a boolean, unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.private voiddilate2D(int indexZ, int iters)Dilates a boolean, unsigned byte or unsigned short image slice using the indicated kernel and the indicated number of executions.private voiderode(boolean returnFlag, int iters)Erodes a boolean or unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.private voiderode2D(int indexZ, int iters)Erodes a boolean or unsigned byte or unsigned short image slice using the indicated kernel and the indicated number of executions.private voidfillHoles(boolean returnFlag)Fill the holes inside the cell region blocks.private voidfillHolesRegion(int stIndex, short floodValue, short objValue)2D flood fill that fill the holes insize the cell region block.voidfinalize()Prepares this class for destruction.private voidgeodesicDilation(boolean returnFlag, int geodesicSize)geodesic dilation of a boolean, unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.private voidgeodesicErosion(boolean returnFlag, int geodesicSize)geodesic erosion of a boolean, unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.private booleanisEndpoint(int pix, short[] tmpBuffer)This method returns whether or not pix is the index of an endpoint in tmpBuffer (it is assumed that location pix is not the intensity of the background in tmpBuffer).private voidmakeCircularKernel(float circDiameter)Generates a cicular kernel of a specific diameter.private voidmakeKernel(int kernelType)Generates a kernel of the indicated type.voidprune(int iter, boolean returnFlag)This method is to be applied on skeletonized images: it removes all branches which are iter or less pixels in length.voidrunAlgorithm()Starts the program.voidsetAlgorithm(int method)Sets the algorithm type (i.e. erode, dilate)voidsetImage(ModelImage img)Sets the algorithm to new image of boolean type.voidsetIterations(int itersD, int itersE)Sets number of iterations for closing or opening.voidsetKernel(java.util.BitSet kernel, int dim)Sets user defined square kernels.voidshowKernel()display kernel as 1 or 0 in the debug window.voidskeletonize(int pruningPixels, boolean returnFlag)Skeletonizes the image by using a lookup table to repeatedly remove pixels from the edges of objects in a binary image, reducing them to single pixel wide skeletons.private intthin(int pass, int slice, int[] table)This a thinning algorithm used to do half of one layer of thinning (which layer is dictated by whether pass is even or odd).-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
ERODE
public static final int ERODE
DOCUMENT ME!- See Also:
- Constant Field Values
-
DILATE
public static final int DILATE
DOCUMENT ME!- See Also:
- Constant Field Values
-
CLOSE
public static final int CLOSE
DOCUMENT ME!- See Also:
- Constant Field Values
-
OPEN
public static final int OPEN
DOCUMENT ME!- See Also:
- Constant Field Values
-
ID_OBJECTS
public static final int ID_OBJECTS
DOCUMENT ME!- See Also:
- Constant Field Values
-
DELETE_OBJECTS
public static final int DELETE_OBJECTS
DOCUMENT ME!- See Also:
- Constant Field Values
-
DISTANCE_MAP
public static final int DISTANCE_MAP
DOCUMENT ME!- See Also:
- Constant Field Values
-
BG_DISTANCE_MAP
public static final int BG_DISTANCE_MAP
DOCUMENT ME!- See Also:
- Constant Field Values
-
ULTIMATE_ERODE
public static final int ULTIMATE_ERODE
DOCUMENT ME!- See Also:
- Constant Field Values
-
PARTICLE_ANALYSIS
public static final int PARTICLE_ANALYSIS
DOCUMENT ME!- See Also:
- Constant Field Values
-
SKELETONIZE
public static final int SKELETONIZE
DOCUMENT ME!- See Also:
- Constant Field Values
-
FIND_EDGES
public static final int FIND_EDGES
DOCUMENT ME!- See Also:
- Constant Field Values
-
PARTICLE_ANALYSIS_NEW
public static final int PARTICLE_ANALYSIS_NEW
DOCUMENT ME!- See Also:
- Constant Field Values
-
FILL_HOLES
public static final int FILL_HOLES
DOCUMENT ME!- See Also:
- Constant Field Values
-
MORPHOLOGICAL_GRADIENT
public static final int MORPHOLOGICAL_GRADIENT
- See Also:
- Constant Field Values
-
BORDER_CLEARING
public static final int BORDER_CLEARING
- See Also:
- Constant Field Values
-
GEODESIC_DILATION
public static final int GEODESIC_DILATION
- See Also:
- Constant Field Values
-
GEODESIC_EROSION
public static final int GEODESIC_EROSION
- See Also:
- Constant Field Values
-
MORPHOLOGICAL_RECONSTRUCTION_BY_DILATION
public static final int MORPHOLOGICAL_RECONSTRUCTION_BY_DILATION
- See Also:
- Constant Field Values
-
MORPHOLOGICAL_RECONSTRUCTION_BY_EROSION
public static final int MORPHOLOGICAL_RECONSTRUCTION_BY_EROSION
- See Also:
- Constant Field Values
-
OPENING_BY_RECONSTRUCTION
public static final int OPENING_BY_RECONSTRUCTION
- See Also:
- Constant Field Values
-
CLOSING_BY_RECONSTRUCTION
public static final int CLOSING_BY_RECONSTRUCTION
- See Also:
- Constant Field Values
-
SIZED_CIRCLE
public static final int SIZED_CIRCLE
DOCUMENT ME!- See Also:
- Constant Field Values
-
CONNECTED4
public static final int CONNECTED4
DOCUMENT ME!- See Also:
- Constant Field Values
-
CONNECTED8
public static final int CONNECTED8
DOCUMENT ME!- See Also:
- Constant Field Values
-
CONNECTED12
public static final int CONNECTED12
DOCUMENT ME!- See Also:
- Constant Field Values
-
OUTER_EDGING
public static final int OUTER_EDGING
DOCUMENT ME!- See Also:
- Constant Field Values
-
INNER_EDGING
public static final int INNER_EDGING
DOCUMENT ME!- See Also:
- Constant Field Values
-
algorithm
private int algorithm
DOCUMENT ME!
-
circleDiameter
private float circleDiameter
DOCUMENT ME!
-
entireImage
private boolean entireImage
DOCUMENT ME!
-
imgBuffer
private short[] imgBuffer
DOCUMENT ME!
-
imgBuffer2
private short[] imgBuffer2
-
maskBuffer
private short[] maskBuffer
-
imgLength
private int imgLength
DOCUMENT ME!
-
iterationsD
private int iterationsD
DOCUMENT ME!
-
iterationsE
private int iterationsE
DOCUMENT ME!
-
kDim
private int kDim
DOCUMENT ME!
-
kernel
private java.util.BitSet kernel
DOCUMENT ME!
-
kernelType
private int kernelType
-
numPruningPixels
private int numPruningPixels
Number pixels to prune.
-
processBuffer
private short[] processBuffer
DOCUMENT ME!
-
sliceLength
private int sliceLength
DOCUMENT ME!
-
maskImage
private ModelImage maskImage
Used in geodesic dilation, geodesic erosion, morphological reconstruction by dilation, and morphological reconstruction by erosion Not used in opening by reconstruction and closing by reconstruction
-
geodesicSize
private int geodesicSize
Size of geodesic erosions and dilations
-
-
Constructor Detail
-
AlgorithmMorphology25D
public AlgorithmMorphology25D(ModelImage srcImg, int kernelType, float circleDiameter, int method, int iterD, int iterE, int pruningPix, int edType, boolean entireImage)
Creates a new AlgorithmMorphology25D object.- Parameters:
srcImg- source image modelkernelType- kernel size (i.e. connectedness)circleDiameter- only valid if kernelType == SIZED_CIRCLE and represents the width of a circle in the resolution of the imagemethod- setup the algorithm method (i.e. erode, dilate)iterD- number of times to dilateiterE- number of times to erodepruningPix- the number of pixels to pruneedType- the type of edging to perform (inner or outer)entireImage- if true, indicates that the VOIs should NOT be used and that entire image should be processed
-
AlgorithmMorphology25D
public AlgorithmMorphology25D(ModelImage srcImg, ModelImage maskImage, int kernelType, float circleDiameter, int method, int geodesicSize, int iterD, int iterE, boolean entireImage)
Creates a new AlgorithmMorphology25D object.- Parameters:
srcImg- source image modelkernelType- dilation kernel size (i.e. connectedness)circleDiameter- dilation only valid if kernelType == SIZED_CIRCLE and represents the width of a circle in the resolution of the imagemethod- setup the algorithm method (i.e. erode, dilate)geodesicSize-iterD- number of times to dilateiterE- number of times to erodeentireImage- if true, indicates that the VOIs should NOT be used and that entire image should be processed
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
prune
public void prune(int iter, boolean returnFlag)This method is to be applied on skeletonized images: it removes all branches which are iter or less pixels in length.- Parameters:
iter- the threshold number of pixels for the maximum length of a removed branch to bereturnFlag- if true then this operation is a step in the morph process (i.e. close)
-
runAlgorithm
public void runAlgorithm()
Starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-
setAlgorithm
public void setAlgorithm(int method)
Sets the algorithm type (i.e. erode, dilate)- Parameters:
method- algorithm type
-
setImage
public void setImage(ModelImage img)
Sets the algorithm to new image of boolean type.- Parameters:
img- image model of boolean type
-
setIterations
public void setIterations(int itersD, int itersE)Sets number of iterations for closing or opening.- Parameters:
itersD- number of dilationsitersE- number of erosions
-
setKernel
public void setKernel(java.util.BitSet kernel, int dim)Sets user defined square kernels.- Parameters:
kernel- user defined kerneldim- length of one dimension (kernel should be square)
-
showKernel
public void showKernel()
display kernel as 1 or 0 in the debug window.
-
skeletonize
public void skeletonize(int pruningPixels, boolean returnFlag)Skeletonizes the image by using a lookup table to repeatedly remove pixels from the edges of objects in a binary image, reducing them to single pixel wide skeletons. Based on a thinning algorithm by Zhang and Suen. There is an entry in the table for each of the 256 possible 3x3 neighborhood configurations. An entry of '1' signifies to delete the indicated pixel on the first pass, '2' means to delete the indicated pixel on the second pass, and '3' indicates to delete the pixel on either pass.- Parameters:
pruningPixels- the number of pixels to prune after skeletonizing. (should be 0 if no pruning is to be done)returnFlag- if true then this operation is a step in the morph process (i.e. close)
-
dilate
private void dilate(boolean returnFlag, int iters)Dilates a boolean, unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. close)iters- number of dilations
-
geodesicDilation
private void geodesicDilation(boolean returnFlag, int geodesicSize)geodesic dilation of a boolean, unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. close)geodesicSize-
-
dilate2D
private void dilate2D(int indexZ, int iters)Dilates a boolean, unsigned byte or unsigned short image slice using the indicated kernel and the indicated number of executions.- Parameters:
indexZ-iters- number of dilations
-
geodesicErosion
private void geodesicErosion(boolean returnFlag, int geodesicSize)geodesic erosion of a boolean, unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. close)geodesicSize-
-
erode2D
private void erode2D(int indexZ, int iters)Erodes a boolean or unsigned byte or unsigned short image slice using the indicated kernel and the indicated number of executions.- Parameters:
indexZ-iters- number of erosion iterations.
-
erode
private void erode(boolean returnFlag, int iters)Erodes a boolean or unsigned byte or unsigned short image using the indicated kernel and the indicated number of executions.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. open)iters- number of erosion iterations.
-
fillHoles
private void fillHoles(boolean returnFlag)
Fill the holes inside the cell region blocks.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. close)
-
fillHolesRegion
private void fillHolesRegion(int stIndex, short floodValue, short objValue)2D flood fill that fill the holes insize the cell region block.- Parameters:
stIndex- the starting index of the seed pointfloodValue- the value to flood the region withobjValue- object ID value that idenditifies the flood region.
-
borderClearing
private void borderClearing(boolean returnFlag)
Removes objects that touch (i.e., are connected to) the border- Parameters:
returnFlag-
-
isEndpoint
private boolean isEndpoint(int pix, short[] tmpBuffer)This method returns whether or not pix is the index of an endpoint in tmpBuffer (it is assumed that location pix is not the intensity of the background in tmpBuffer).- Parameters:
pix- the index of a non-zero pixel in tmpBuffertmpBuffer- the image- Returns:
- DOCUMENT ME!
-
makeCircularKernel
private void makeCircularKernel(float circDiameter)
Generates a cicular kernel of a specific diameter.- Parameters:
circDiameter- represents the width of a circle in the resolution of the image
-
makeKernel
private void makeKernel(int kernelType)
Generates a kernel of the indicated type.- Parameters:
kernelType- type of kernel to be generated.
-
thin
private int thin(int pass, int slice, int[] table)This a thinning algorithm used to do half of one layer of thinning (which layer is dictated by whether pass is even or odd).- Parameters:
pass- the number pass this execution is on the imageslice- the slice number being worked on (starting with 0);table- the table to lookup whether to delete the pixel or let it stay.- Returns:
- DOCUMENT ME!
-
-