Package gov.nih.mipav.model.algorithms
Class AlgorithmMorphology3D
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmMorphology3D
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
Three-Dimensional mathmatical morphology class. Methods include:
- Background Distance Map
- close
- Delete objects
- dilate
- Distance Map
- erode
- fill holes
- find edges
- Identify objects
- Morphological gradient
- open
- Particle Analysis
- Skeletonize with pruning option
- ultimate erode
- Border clearing
- Geodesic dilation
- Geodesic erosion
- Morphological reconstruction by dilation
- Morphological reconstruction by erosion
- Opening by reconstruction
- Closing by reconstruction
- Version:
- 1.0 Aug 1999
- Author:
- Matthew J. McAuliffe, Ph.D.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classSimple class to temporarily store the object's size, ID and seed index value.Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intalgorithm type (i.e. erode, dilate)static final intDOCUMENT ME!static final intstatic final intDOCUMENT ME!static final intstatic final intDOCUMENT ME!static final intstatic final intDOCUMENT ME!static final intDOCUMENT ME!static final intDOCUMENT ME!static final intDOCUMENT ME!static final intDOCUMENT ME!private float[]DOCUMENT ME!private intEdge type.private booleanif true, indicates that the VOIs should NOT be used and that entire image should be processed.static final intDOCUMENT ME!static final intDOCUMENT ME!static final intDOCUMENT ME!static final intstatic final intprivate intSize of geodesic erosions and dilationsstatic final intDOCUMENT ME!private short[]imgBuffer that hold voxel value for the 3D slices.private short[]static final intParameter used in Find_Edges.private final intDilation iteration times.private final intErosion iteration times.private intKernel dimension.private intDOCUMENT ME!private BitSetKernel for both erosion and dilation.private final intkernel size (i.e. connectedness)private short[]private ModelImageUsed in geodesic dilation, geodesic erosion, morphological reconstruction by dilation, and morphological reconstruction by erosion Not used in opening by reconstruction and closing by reconstructionprivate intmaximum, minimum size of objects.private intmaximum, minimum size of objects.static final intstatic final intstatic final intprivate intNumber pixels to prune.private Vector<AlgorithmMorphology3D.intObject> Vector that holding the current available objects in the 3D image.static final intDOCUMENT ME!static final intstatic final intParameter used in Find_Edges.static final intDOCUMENT ME!private floatDOCUMENT ME!private short[]intermediate processing buffer, same size with imgBuffer.private final booleanNot used now.static final intDOCUMENT ME!static final intDOCUMENT ME!private floatkernel diameter.private WildMagic.LibFoundation.Mathematics.Vector3f[]DOCUMENT ME!static final intDOCUMENT 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, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmMorphology3D(ModelImage srcImg, int kernelType, float sphereDiameter, int method, int iterD, int iterE, int pruningPix, int edType, boolean entireImage) Creates a new AlgorithmMorphology3D object.AlgorithmMorphology3D(ModelImage srcImg, ModelImage destImg, int kernelType, float sphereDiameter, int method, int iterD, int iterE, int pruningPix, int edType, boolean entireImage) Creates a new AlgorithmMorphology3D object.AlgorithmMorphology3D(ModelImage srcImg, ModelImage destImg, ModelImage maskImage, int kernelType, float sphereDiameter, int method, int geodesicSize, int iterD, int iterE, boolean entireImage) Creates a new AlgorithmMorphology3D object. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidbackgroundDistanceMap(boolean returnFlag) Generates a Euclidian distance map of the background.private voidborderClearing(boolean returnFlag) Removes objects that touch (i.e., are connected to) the borderprivate voiddeleteObjects(int min, int max, boolean returnFlag) Deletes objects larger than maximum size indicated and objects smaller than the indicated minimum size.private voiddilate(boolean returnFlag, int iters) Dilates a boolean, unsigned byte, or unsigned short image using the indicated kernel and the indicated number of iterations.private voiddistanceMap(boolean returnFlag) Generates a Euclidian distance map.private voiddistanceMapForShapeInterpolation(boolean returnFlag) private voiderode(boolean returnFlag, int iters) Erodes a boolean, unsigned byte, or unsigned short image using the indicated kernel and the indicated number of iterations.private voidfillHoles(boolean returnFlag) Fill the holes inside the cell region blocks.private voidfillHolesRegion(int stIndex, short floodValue, short objValue) 3D flood fill that fill the holes insize the cell region block.voidfinalize()Prepares this class for destruction.voidfindEdges(int edgeType, boolean returnFlag) Finds the edges of objects.private intfloodFill(short[] idBuffer, int stIndex, short floodValue, short objValue) 3D flood fill that forms a short mask.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.voididentifyObjects(boolean returnFlag) Labels each object in an image with a different integer value.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 voidmakeKernel(int kernelType) Generates a kernel of the indicated type.private voidGenerates a spherical kernel of a specific diameter.private booleanonePixel(short[] buffer, int index, int sliceSize, int xDim) Used by ultimate erode to simplify code a little.private voidTake a mask like image and performs an analysis.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.voidStarts the program.voidsetAlgorithm(int method) Sets the algorithm type (i.e. erode, dilate)voidsetImage(ModelImage img) Sets new source image.voidSets user defined square kernels.voidsetMinMax(int _min, int _max) Sets the bounds of object size used to delete objects.voidsetPixDistance(float dist) Used in the ultimate erode function to remove all eroded points less than the distance specified in pixel units.voidDisplay 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).private voidultimateErode(boolean returnFlag) Erodes to a single point.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, windowOpenedMethods 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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
ERODE
public static final int ERODEDOCUMENT ME!- See Also:
-
DILATE
public static final int DILATEDOCUMENT ME!- See Also:
-
CLOSE
public static final int CLOSEDOCUMENT ME!- See Also:
-
OPEN
public static final int OPENDOCUMENT ME!- See Also:
-
ID_OBJECTS
public static final int ID_OBJECTSDOCUMENT ME!- See Also:
-
DELETE_OBJECTS
public static final int DELETE_OBJECTSDOCUMENT ME!- See Also:
-
DISTANCE_MAP
public static final int DISTANCE_MAPDOCUMENT ME!- See Also:
-
BG_DISTANCE_MAP
public static final int BG_DISTANCE_MAPDOCUMENT ME!- See Also:
-
ULTIMATE_ERODE
public static final int ULTIMATE_ERODEDOCUMENT ME!- See Also:
-
PARTICLE_ANALYSIS
public static final int PARTICLE_ANALYSISDOCUMENT ME!- See Also:
-
SKELETONIZE
public static final int SKELETONIZEDOCUMENT ME!- See Also:
-
FIND_EDGES
public static final int FIND_EDGESDOCUMENT ME!- See Also:
-
FILL_HOLES
public static final int FILL_HOLESDOCUMENT ME!- See Also:
-
DISTANCE_MAP_FOR_SHAPE_INTERPOLATION
public static final int DISTANCE_MAP_FOR_SHAPE_INTERPOLATIONDOCUMENT ME!- See Also:
-
MORPHOLOGICAL_GRADIENT
public static final int MORPHOLOGICAL_GRADIENT- See Also:
-
BORDER_CLEARING
public static final int BORDER_CLEARING- See Also:
-
GEODESIC_DILATION
public static final int GEODESIC_DILATION- See Also:
-
GEODESIC_EROSION
public static final int GEODESIC_EROSION- See Also:
-
MORPHOLOGICAL_RECONSTRUCTION_BY_DILATION
public static final int MORPHOLOGICAL_RECONSTRUCTION_BY_DILATION- See Also:
-
MORPHOLOGICAL_RECONSTRUCTION_BY_EROSION
public static final int MORPHOLOGICAL_RECONSTRUCTION_BY_EROSION- See Also:
-
OPENING_BY_RECONSTRUCTION
public static final int OPENING_BY_RECONSTRUCTION- See Also:
-
CLOSING_BY_RECONSTRUCTION
public static final int CLOSING_BY_RECONSTRUCTION- See Also:
-
SIZED_SPHERE
public static final int SIZED_SPHEREDOCUMENT ME!- See Also:
-
CONNECTED6
public static final int CONNECTED6DOCUMENT ME!- See Also:
-
CONNECTED24
public static final int CONNECTED24DOCUMENT ME!- See Also:
-
CONNECTED26
public static final int CONNECTED26- See Also:
-
OUTER_EDGING
public static final int OUTER_EDGINGParameter used in Find_Edges. Indicates that the edge extracted is formed from the voxels that are directly adjacient to the ojbect.- See Also:
-
INNER_EDGING
public static final int INNER_EDGINGParameter used in Find_Edges. Indicates that the edge extracted is formed from the voxels that overlay the edge voxels of the object.- See Also:
-
algorithm
private int algorithmalgorithm type (i.e. erode, dilate) -
distanceMap
private float[] distanceMapDOCUMENT ME! -
edgingType
private int edgingTypeEdge type. -
entireImage
private boolean entireImageif true, indicates that the VOIs should NOT be used and that entire image should be processed. -
imgBuffer
private short[] imgBufferimgBuffer that hold voxel value for the 3D slices. -
imgBuffer2
private short[] imgBuffer2 -
maskBuffer
private short[] maskBuffer -
iterationsD
private final int iterationsDDilation iteration times. -
iterationsE
private final int iterationsEErosion iteration times. -
kDimXY
private int kDimXYKernel dimension. -
kDimZ
private int kDimZDOCUMENT ME! -
kernel
Kernel for both erosion and dilation. -
kernelType
private final int kernelTypekernel size (i.e. connectedness) -
min
private int minmaximum, minimum size of objects. -
max
private int maxmaximum, minimum size of objects. -
numPruningPixels
private int numPruningPixelsNumber pixels to prune. -
objects
Vector that holding the current available objects in the 3D image. -
pixDist
private float pixDistDOCUMENT ME! -
processBuffer
private short[] processBufferintermediate processing buffer, same size with imgBuffer. -
showFrame
private final boolean showFrameNot used now. Flag to show frame during each algorithm method call.- See Also:
-
sphereDiameter
private float sphereDiameterkernel diameter. -
ultErodeObjects
private WildMagic.LibFoundation.Mathematics.Vector3f[] ultErodeObjectsDOCUMENT ME! -
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 geodesicSizeSize of geodesic erosions and dilations
-
-
Constructor Details
-
AlgorithmMorphology3D
public AlgorithmMorphology3D(ModelImage srcImg, int kernelType, float sphereDiameter, int method, int iterD, int iterE, int pruningPix, int edType, boolean entireImage) Creates a new AlgorithmMorphology3D object.- Parameters:
srcImg- source image modelkernelType- kernel size (i.e. connectedness)sphereDiameter- only valid if kernelType == SIZED_SPHERE and represents the width of a circle in the resolution of the imagemethod- setup the algorithm method (i.e. erode)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- flag that indicates if the VOIs should NOT be used and entire image should be processed
-
AlgorithmMorphology3D
public AlgorithmMorphology3D(ModelImage srcImg, ModelImage destImg, int kernelType, float sphereDiameter, int method, int iterD, int iterE, int pruningPix, int edType, boolean entireImage) Creates a new AlgorithmMorphology3D object.- Parameters:
srcImg- source image modeldestImg- destination image modelkernelType- kernel size (i.e. connectedness)sphereDiameter- only valid if kernelType == SIZED_SPHERE and represents the width of a circle in the resolution of the imagemethod- setup the algorithm method (i.e. erode)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- flag that indicates if the VOIs should NOT be used and entire image should be processed
-
AlgorithmMorphology3D
public AlgorithmMorphology3D(ModelImage srcImg, ModelImage destImg, ModelImage maskImage, int kernelType, float sphereDiameter, int method, int geodesicSize, int iterD, int iterE, boolean entireImage) Creates a new AlgorithmMorphology3D object.- Parameters:
srcImg- source image modelkernelType- dilation kernel size (i.e. connectedness)method- 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 processedcircleDiameter- dilation only valid if kernelType == SIZED_CIRCLE and represents the width of a circle in the resolution of the image
-
-
Method Details
-
finalize
public void finalize()Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
findEdges
public void findEdges(int edgeType, boolean returnFlag) Finds the edges of objects.- Parameters:
edgeType- Indicates that the edge extracted is formed from the voxels that are directly adjacient to the ojbect or from the voxels that overlay the edge voxels of the object.returnFlag- if true then this operation is a step in the morph process (i.e. close) see OUTER_EDGING see INNER_EDGE
-
identifyObjects
public void identifyObjects(boolean returnFlag) Labels each object in an image with a different integer value.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. close)
-
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
Sets new source image.- Parameters:
img- image model
-
setKernel
Sets user defined square kernels.- Parameters:
kernel- user defined kerneldimXY- length of x and y dimensionsdimZ- length of z dimension
-
setMinMax
public void setMinMax(int _min, int _max) Sets the bounds of object size used to delete objects.- Parameters:
_min- minimum size of objects_max- maximum size of objects
-
setPixDistance
public void setPixDistance(float dist) Used in the ultimate erode function to remove all eroded points less than the distance specified in pixel units.- Parameters:
dist- distance in pixels.
-
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)
-
distanceMapForShapeInterpolation
private void distanceMapForShapeInterpolation(boolean returnFlag) -
backgroundDistanceMap
private void backgroundDistanceMap(boolean returnFlag) Generates a Euclidian distance map of the background.- Parameters:
returnFlag- if true then this operation is a step in the morph process
-
deleteObjects
private void deleteObjects(int min, int max, boolean returnFlag) Deletes objects larger than maximum size indicated and objects smaller than the indicated minimum size.- Parameters:
min- delete all objects smaller than the minimum value (pixels)max- delete all objects greater than the maximum value (pixels)returnFlag- if true then this operation is a step in the morph process (i.e. close)
-
borderClearing
private void borderClearing(boolean returnFlag) Removes objects that touch (i.e., are connected to) the border- Parameters:
returnFlag-
-
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 iterations.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. close)iters- number of dilation iterations
-
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-
-
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-
-
distanceMap
private void distanceMap(boolean returnFlag) Generates a Euclidian distance map.- Parameters:
returnFlag- if true then this operation is a step in the morph process
-
erode
private void erode(boolean returnFlag, int iters) Erodes a boolean, unsigned byte, or unsigned short image using the indicated kernel and the indicated number of iterations.- 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) 3D 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.
-
floodFill
private int floodFill(short[] idBuffer, int stIndex, short floodValue, short objValue) 3D flood fill that forms a short mask.- Parameters:
idBuffer- buffer to store flooding resultsstIndex- starting index indicating the starting location of the flood fillfloodValue- the value to flood the area withobjValue- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
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!
-
makeKernel
private void makeKernel(int kernelType) Generates a kernel of the indicated type.- Parameters:
kernelType- type of kernel to be generated.
-
makeSphericalKernel
private void makeSphericalKernel()Generates a spherical kernel of a specific diameter. Most importantly it normalizes the kernel based on the resolution in the z-dimension. This in effect accounts for the anisotrophy in the z-dimension of typical 3D medical images. The resultant data is stored in the kernel class variable. -
onePixel
private boolean onePixel(short[] buffer, int index, int sliceSize, int xDim) Used by ultimate erode to simplify code a little. Checks to find a single pixels in the 27 neighborhood.- Parameters:
buffer- input data bufferindex- index of interestsliceSize- number of voxels in the image planexDim- dimension of the image in the x direction- Returns:
- true if single pixel, false if not single pixel.
-
particleAnalysis
private void particleAnalysis()Take a mask like image and performs an analysis.1. Deletes objects that are too small (noise) and objects that are too big 2. Ultimate erode and remove points that are too close 3. Watershed using ultimate eroded points as seed points and distance map. 4. Delete objects that are too small (noise) and objects that are too big
Ult erode invalid input: '&' (bg dist map AND orig image) => watershed(ultErodePts, ANDED Bg Dist) => IDobjects
-
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!
-
ultimateErode
private void ultimateErode(boolean returnFlag) Erodes to a single point.- Parameters:
returnFlag- if true then this operation is a step in the morph process (i.e. open)
-