Package gov.nih.mipav.model.algorithms
Class AlgorithmBrainSurfaceExtractor
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmBrainSurfaceExtractor
-
- All Implemented Interfaces:
AlgorithmInterface
,java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmBrainSurfaceExtractor extends AlgorithmBase implements AlgorithmInterface
This class provides an implementation of a second method for segmentation of the brain from a 3D MRI, as opposed to the BET algorithm implemented in AlgorithmBrainExtractor. The algorithm is partially based on the paper describing the Brain Surface Extraction (BSE) algorithm:Magnetic Resonance Image Tissue Classification Using a Partial Volume Model
David W. Shattuck et al.
NeuroImage 13, 856-876 (2001)
available at http://www.idealibrary.com
- Version:
- 1.0 June 3, 2004
- Author:
- Evan McCreedy
- See Also:
JDialogBrainSurfaceExtractor
,AlgorithmBrainExtractor
-
-
Field Summary
Fields Modifier and Type Field Description private float
brainRegionSize
The size of the region we have identified as the brain.private static float
brainRegionThresholdRatio
The proportion of the total number of pixels in the volume that a region should be before we decide that it's probably the brain.private int
closeIterations
The number of closings to perform.private int
closeKernel
Use the sized circle kernel for the closing.private float
closeKernelSize
The size of the kernel to use in closings.private boolean
doSeparable
Whether to use the edge detection algorithm with a separable convolver.private float
edgeKernel
The size of the edge detection kernel.private boolean
erosion25D
Whether to erode / dilate image slices independently.private int
erosionIterations
The number of erosions/dilations to perform.private boolean
extractPaint
This flag is set when the algorithm is being used only to extract paint from the brain.private boolean
fillHolesFlag
Whether to make an effort to fill in any interior holes in the final brain mask.private int
filterIterations
The number of filter passes to make.private float
filterKernel
The size of the filter kernel to use.private ModelImage
image
The source image.private int
imgSize
The size, in voxels, of the volume.private java.util.BitSet
paintMask
The actual paint bitmap.private IntVector
regionPointStack
The stack of voxels in the image that we should try to grow to.private static float
regionPointStackRatio
Used to initialize the stack size when finding the largest segmented region (i.e. the brain).private ModelImage
resultImage
The result image.private boolean
showIntermediateImages
Whether to show the intermediate images generated during the BSE algorithm.private int
sliceSize
The size, in voxels, of a slice of the volume.private int
xDim
The image size in the x dimension.private float
xRes
The image resolution in the x dimension.private int
yDim
The image size in the y dimension.private float
yRes
The image resolution in the y dimension.private int
zDim
The image size in the z dimension.private float
zRes
The image resolution in the z dimension.-
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 AlgorithmBrainSurfaceExtractor(ModelImage srcImg, int fIter, float fKernel, float eKernel, boolean ero25D, int eroIter, float cKernel, int cIter, boolean showIntermediate, boolean noHoles, boolean doSep, boolean extractPaint)
Create an extractor for segmenting the brain from a 3D magnetic resonance image.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static ModelImage
addPadding(ModelImage img)
Pad an image by copying the first and last slices 2 more times so that the laplacian algorithm behaves well in edge conditions.void
algorithmPerformed(AlgorithmBase algorithm)
This method is required if the AlgorithmPerformed interface is implemented.private float[]
calculateProgressRatios(int filterIterations, boolean doSeparable, boolean fillHolesFlag)
Calculates the progress ratios for different algorithms.private int[]
calculateProgressValueBoundary(int index, float[] ratios, int min, int max)
Calculates the boundary of progress value which is assigned to theindex
th algorithm.void
extractBrain()
Isolate the brain from the rest of the MR image.void
finalize()
Prepares this class for destruction.ModelImage
findLargestRegion(ModelImage maskImage)
Find the largest region within a mask image.float
getBrainVolume()
Returns the volume of the brain in units (typically millimeters).java.util.BitSet
getComputedPaintMask()
Method is used when the "extract paint" option is set.ModelImage
getResultImage()
Get the final result image.int
markRegion(int[] imgData, int initIndex, int regionId)
Start at a point in an image and grow to all connected points, marking them and counting as we go.private static ModelImage
removePadding(ModelImage paddedImg)
Remove the padding slices from the beginning and end of an image.void
runAlgorithm()
Starts the algorithm.-
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
-
brainRegionThresholdRatio
private static final float brainRegionThresholdRatio
The proportion of the total number of pixels in the volume that a region should be before we decide that it's probably the brain.- See Also:
- Constant Field Values
-
regionPointStackRatio
private static final float regionPointStackRatio
Used to initialize the stack size when finding the largest segmented region (i.e. the brain).- See Also:
- Constant Field Values
-
brainRegionSize
private float brainRegionSize
The size of the region we have identified as the brain.
-
closeIterations
private int closeIterations
The number of closings to perform.
-
closeKernel
private final int closeKernel
Use the sized circle kernel for the closing.- See Also:
- Constant Field Values
-
closeKernelSize
private float closeKernelSize
The size of the kernel to use in closings.
-
doSeparable
private boolean doSeparable
Whether to use the edge detection algorithm with a separable convolver.
-
edgeKernel
private float edgeKernel
The size of the edge detection kernel.
-
erosion25D
private boolean erosion25D
Whether to erode / dilate image slices independently.
-
erosionIterations
private int erosionIterations
The number of erosions/dilations to perform.
-
extractPaint
private boolean extractPaint
This flag is set when the algorithm is being used only to extract paint from the brain.
-
fillHolesFlag
private boolean fillHolesFlag
Whether to make an effort to fill in any interior holes in the final brain mask.
-
filterIterations
private int filterIterations
The number of filter passes to make.
-
filterKernel
private float filterKernel
The size of the filter kernel to use.
-
image
private ModelImage image
The source image.
-
imgSize
private int imgSize
The size, in voxels, of the volume.
-
paintMask
private java.util.BitSet paintMask
The actual paint bitmap.
-
regionPointStack
private IntVector regionPointStack
The stack of voxels in the image that we should try to grow to. Made a class member to increase speed.
-
resultImage
private ModelImage resultImage
The result image.
-
showIntermediateImages
private boolean showIntermediateImages
Whether to show the intermediate images generated during the BSE algorithm.
-
sliceSize
private int sliceSize
The size, in voxels, of a slice of the volume.
-
xDim
private int xDim
The image size in the x dimension.
-
xRes
private float xRes
The image resolution in the x dimension.
-
yDim
private int yDim
The image size in the y dimension.
-
yRes
private float yRes
The image resolution in the y dimension.
-
zDim
private int zDim
The image size in the z dimension.
-
zRes
private float zRes
The image resolution in the z dimension.
-
-
Constructor Detail
-
AlgorithmBrainSurfaceExtractor
public AlgorithmBrainSurfaceExtractor(ModelImage srcImg, int fIter, float fKernel, float eKernel, boolean ero25D, int eroIter, float cKernel, int cIter, boolean showIntermediate, boolean noHoles, boolean doSep, boolean extractPaint)
Create an extractor for segmenting the brain from a 3D magnetic resonance image.- Parameters:
srcImg
- the source image. Should be MR image of the brainfIter
- number of passes to make with the filterfKernel
- gaussian kernel size to use when running the filtereKernel
- kernel size to use with edge detection algoero25D
- whether to use 2.5D processing in erosion / dilationeroIter
- number of erosions / dialations to performcKernel
- kernel size in mm to be used in closingcIter
- number of closings to performshowIntermediate
- whether to save intermediate images for displaynoHoles
- whether to fill in all interior holes of the extracted braindoSep
- whether to use separable convolver for edge detectionextractPaint
- whether to extract paint from the brain
-
-
Method Detail
-
algorithmPerformed
public void algorithmPerformed(AlgorithmBase algorithm)
This method is required if the AlgorithmPerformed interface is implemented. It is called by the algorithms when it has completed or failed to to complete, so that the dialog can be display the result image and/or clean up.- Specified by:
algorithmPerformed
in interfaceAlgorithmInterface
- Parameters:
algorithm
- Algorithm that caused the event.
-
extractBrain
public void extractBrain()
Isolate the brain from the rest of the MR image.
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
findLargestRegion
public ModelImage findLargestRegion(ModelImage maskImage)
Find the largest region within a mask image.- Parameters:
maskImage
- the original mask image, with values of 0 or 1- Returns:
- ModelImage the image containing only the largest connected component from
maskImage
-
getBrainVolume
public final float getBrainVolume()
Returns the volume of the brain in units (typically millimeters).- Returns:
- The volume of the brain in voxel units (typically millimeters).
-
getComputedPaintMask
public java.util.BitSet getComputedPaintMask()
Method is used when the "extract paint" option is set.- Returns:
- the paint mask bitset representing the area not removed from the image during the brain extraction
-
getResultImage
public ModelImage getResultImage()
Get the final result image.- Returns:
- the final extracted brain image
-
markRegion
public int markRegion(int[] imgData, int initIndex, int regionId)
Start at a point in an image and grow to all connected points, marking them and counting as we go.- Parameters:
imgData
- the exported 3d image maskinitIndex
- the point to start growing the region fromregionId
- what to mark where the region is located- Returns:
- the number of voxels in the grown region
-
runAlgorithm
public void runAlgorithm()
Starts the algorithm.- Specified by:
runAlgorithm
in classAlgorithmBase
-
addPadding
private static ModelImage addPadding(ModelImage img)
Pad an image by copying the first and last slices 2 more times so that the laplacian algorithm behaves well in edge conditions.- Parameters:
img
- the image to pad- Returns:
- the padded image
-
removePadding
private static ModelImage removePadding(ModelImage paddedImg)
Remove the padding slices from the beginning and end of an image.- Parameters:
paddedImg
- the padded image- Returns:
- the image without padding
-
calculateProgressRatios
private float[] calculateProgressRatios(int filterIterations, boolean doSeparable, boolean fillHolesFlag)
Calculates the progress ratios for different algorithms.- Parameters:
filterIterations
- the iteration number for filter.doSeparable
- flag to indicate whether use separable algorithm or not.fillHolesFlag
- DOCUMENT ME!- Returns:
- the progress ratios for different algorithms
-
calculateProgressValueBoundary
private int[] calculateProgressValueBoundary(int index, float[] ratios, int min, int max)
Calculates the boundary of progress value which is assigned to theindex
th algorithm.- Parameters:
index
- the algorithm indexratios
- the ratio array assigned to the algorithms.min
- the minimum progress value available to be distributedmax
- the maximum progress value available to be distributed- Returns:
- the minimum and maximum progress value assigned to the
index
th algorithm.
-
-