Class 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 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 brain
        fIter - number of passes to make with the filter
        fKernel - gaussian kernel size to use when running the filter
        eKernel - kernel size to use with edge detection algo
        ero25D - whether to use 2.5D processing in erosion / dilation
        eroIter - number of erosions / dialations to perform
        cKernel - kernel size in mm to be used in closing
        cIter - number of closings to perform
        showIntermediate - whether to save intermediate images for display
        noHoles - whether to fill in all interior holes of the extracted brain
        doSep - whether to use separable convolver for edge detection
        extractPaint - 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 interface AlgorithmInterface
        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 class AlgorithmBase
      • 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 mask
        initIndex - the point to start growing the region from
        regionId - what to mark where the region is located
        Returns:
        the number of voxels in the grown region
      • 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 the indexth algorithm.
        Parameters:
        index - the algorithm index
        ratios - the ratio array assigned to the algorithms.
        min - the minimum progress value available to be distributed
        max - the maximum progress value available to be distributed
        Returns:
        the minimum and maximum progress value assigned to the indexth algorithm.