Class AlgorithmSkullRemoval

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class AlgorithmSkullRemoval
    extends AlgorithmBase
    Algorithm Implementation 1. Calculate the input image histogram. 2. Calculate the image values that represent 2% and 98% of the histogram values and clamp the input image data to that range. 3. Set the cerebrospinal fluid (CSF) threshold minimum value to 30 % of the clamped image range and the CSF threshold maximum value to 70% of the clamped image range. 4. Calculate the brain center of gravity (COG) as the weighted sum of all voxels between the CSF minimum and maximum range using the voxel position scaled by intensity value. 5. Estimate the white matter threshold by segmenting the image into 5x5x5 voxel cubes and finding the cube with the highest mean intensity and lowest variance. The mean intensity of the selected cube is used to set the white matter threshold value. 6. Generate a white-matter segmentation of the brain by using a flood-fill algorithm with the white matter threshold seed point as the starting point. The flood-fill algorithm is limited by the CSF threshold values as well as a radius centered around the initial seed point. 7. Take the convex-hull of the white matter segmentation and pass this mesh into a modified version of the AlgorithmBrainExtractor. 8. The output of the AlgorithmBrainExtractor is a segmented mesh representing the surface of the brain. To err on the side of not removing too much data, the convex-hull of the brain surface is generated. 9. The final mask representing the data outside the brain is generated using all voxels outside the convex-hull of the brain surface. 10. (Optional final step). If the user chooses to segment only the face region instead of the entire skull region the final step produces the face segmentation from the convex-hull of the brain surface.
    • Field Detail

      • faceOrientation

        private int faceOrientation
        Face Orientation is left:
      • min_2P

        private float min_2P
        Value representing 2% of the histogram count:
      • max_98P

        private float max_98P
        Value representing 98% of the histogram count:
      • csfThresholdMin

        private float csfThresholdMin
        Cerebrospinal Fluid (CSF) minimum threshold :
      • csfThresholdMax

        private float csfThresholdMax
        Cerebrospinal Fluid (CSF) maximum threshold :
      • wmThreshold

        private float wmThreshold
        White Matter threshold :
      • gmThresholdMin

        private float gmThresholdMin
        Gray Matter minimum threshold :
      • gmThresholdMax

        private float gmThresholdMax
        Gray Matter maximum threshold :
      • cog

        private WildMagic.LibFoundation.Mathematics.Vector3f cog
        Center of Gravity :
      • dimX

        private int dimX
      • dimY

        private int dimY
      • dimZ

        private int dimZ
      • blur

        private boolean blur
        when true, blur the output
      • remove

        private boolean remove
        when true, remove the output
      • face

        private boolean face
        when true, compute face segmentation instead of skull
      • showFaceSegmentation

        private boolean showFaceSegmentation
        when true, display the face segmentation
      • showSkullSegmentation

        private boolean showSkullSegmentation
        when true, display the skull segmentation
      • offSet

        private float offSet
        Optional offset (in mm) boundary around the segmented region
      • originalAxis

        private int[] originalAxis
        stores the original image orientation axis
      • targetAxis

        private int[] targetAxis
        the orientation the images are remapped to before processing:
      • originalAxisTargetAtlas

        private int[] originalAxisTargetAtlas
        stores the original image orientation axis (used for the target image when an atlas image is present)
      • reMappedSrc

        private boolean reMappedSrc
        When true the source image was remapped
      • reMappedTargetAtlas

        private boolean reMappedTargetAtlas
        When true the target image was remapped (used for the target image when an atlas image is present)
      • atlasBasedImage

        private ModelImage atlasBasedImage
        atlas image:
      • registeredSourceImage

        private ModelImage registeredSourceImage
        registered atlas image
      • originalSrc

        private ModelImage originalSrc
        original source image
    • Constructor Detail

      • AlgorithmSkullRemoval

        public AlgorithmSkullRemoval​(ModelImage srcImg)
        Automatic DeSkulling initialization.
        Parameters:
        srcImg - The image to segment.
      • AlgorithmSkullRemoval

        public AlgorithmSkullRemoval​(ModelImage srcImg,
                                     ModelImage atlasImage)
        Automatic DeSkulling initialization.
        Parameters:
        srcImg - The image to segment.
        atlasImage - The atlas image.
    • Method Detail

      • finalize

        public void finalize()
        Clean up memory used by the algorithm.
        Overrides:
        finalize in class AlgorithmBase
      • setOffSet

        public void setOffSet​(float offSet)
        Set the boundary offset parameter in mm.
        Parameters:
        offSet -
      • setOutputOption

        public void setOutputOption​(boolean blur,
                                    boolean remove,
                                    boolean face,
                                    boolean showFaceSegmentation,
                                    boolean showSkullSegmentation)
        Set the output options
        Parameters:
        blur - when true blur the segmented region
        remove - when true remove the segmented region
        face - when true segment the face
        showFaceSegmentation - when true show the face segmentation
        showSkullSegmentation - when true show the skull segmentation
      • addBlur

        private void addBlur​(ModelImage blurImage,
                             ModelImage destImage)
        Combines the randomized-voxel blurred image with the output image. Only the areas that are in the segmented region are modified by the blur.
        Parameters:
        blurImage -
        destImage -
      • computeSurfaceMask

        private java.util.BitSet computeSurfaceMask​(WildMagic.LibGraphics.SceneGraph.TriMesh mesh)
        Computes a volume mask of the triangle mesh surface. The BitSet mask volume has the same volume dimensions as the current image. The mask is used to show the surface-plane intersections in the slice views.
        Parameters:
        mesh - triangle mesh to convert to a volume mask representation.
        Returns:
        BitSet mask, which is set to true wherever the triangle mesh intersects the volume voxel.
      • convexHull

        private WildMagic.LibGraphics.SceneGraph.TriMesh convexHull​(WildMagic.LibGraphics.SceneGraph.TriMesh mesh)
        Compute the convex hull of the input mesh, return the convex hull.
        Parameters:
        mesh -
        Returns:
      • createMask

        private java.util.BitSet createMask​(WildMagic.LibFoundation.Mathematics.Plane3f clipPlane,
                                            WildMagic.LibFoundation.Mathematics.Vector3f cog)
      • createMask

        private java.util.BitSet createMask​(WildMagic.LibGraphics.SceneGraph.TriMesh mesh,
                                            boolean show,
                                            java.lang.String postScript)
      • createMesh

        private WildMagic.LibGraphics.SceneGraph.TriMesh createMesh​(java.util.BitSet mask)
      • createMesh

        private WildMagic.LibGraphics.SceneGraph.TriMesh createMesh​(ModelImage image)
      • distance

        private float distance​(WildMagic.LibFoundation.Mathematics.Vector3f cog,
                               int x,
                               int y,
                               int z)
      • estimateParameters

        private void estimateParameters()
        1. Calculate the input image histogram. 2. Calculate the image values that represent 2% and 98% of the histogram values and clamp the input image data to that range. 3. Set the cerebrospinal fluid (CSF) threshold minimum value to 30 % of the clamped image range and the CSF threshold maximum value to 70% of the clamped image range. 4. Calculate the brain center of gravity (COG) as the weighted sum of all voxels between the CSF minimum and maximum range using the voxel position scaled by intensity value. Steps 1-4: The preprocessed steps generate the center of gravity (COG) and cerebrospinal fluid (CSF) thresholds, which are used to find the initial white-matter seed point. Potential white-matter seed points are limited to a radius around the COG. The minimum variance is selected from potential seed points with a maximum mean-intensity greater than the CSF threshold. These steps prevent the algorithm from finding a seed point in the background, where the variance may be zero but where the intensity is lower than the CSF threshold.
      • estimateWhiteMatter

        private VOI estimateWhiteMatter​(ModelImage image)
        5. Estimate the white matter threshold by segmenting the image into 5x5x5 voxel cubes and finding the cube with the highest mean intensity and lowest variance. The mean intensity of the selected cube is used to set the white matter threshold value.
        Parameters:
        image - image remapped to the robust image range.
        Returns:
        initial white-matter seed point(s).
      • fill

        private void fill​(ModelImage image,
                          WildMagic.LibFoundation.Mathematics.Vector3f centerBound,
                          java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> seedList,
                          java.util.BitSet visited,
                          java.util.BitSet whiteMatter)
      • fill

        private void fill​(java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> seedList,
                          java.util.BitSet visited,
                          java.util.BitSet mask)
      • fillWhiteMatter

        private void fillWhiteMatter​(ModelImage image,
                                     VOI seedPoints)
        Once the white-matter seed point is found it is used to initialize a flood-fill algorithm that segments the white-matter of the brain. The seed point is typically found in one hemisphere of the brain. The first step in initializing the flood-fill algorithm is to generate a mirror-image seed-point located in the opposite hemisphere. This enables the flood-fill algorithm to work equally well on both hemispheres. The flood-fill algorithm is limited to an ellipsoid shape around the COG, where the long axis of the ellipsoid is anterior-to-posterior and the short axes of the ellipsoid are superior-to-inferior and left-to-right.
        Parameters:
        image -
        seedPoints -
      • floodFill

        private void floodFill​(java.util.BitSet mask,
                               WildMagic.LibFoundation.Mathematics.Vector3f cog)
      • generateConvexHullMask

        private void generateConvexHullMask​(ModelImage image)
        Algorithm Implementation Steps: 7. Take the convex-hull of the white matter segmentation and pass this mesh into a modified version of the AlgorithmBrainExtractor. 8. The output of the AlgorithmBrainExtractor is a segmented mesh representing the surface of the brain. To err on the side of not removing too much data, the convex-hull of the brain surface is generated. 9. The final mask representing the data outside the brain is generated using all voxels outside the convex-hull of the brain surface. 10. (Optional final step). If the user chooses to segment only the face region instead of the entire skull region the final step produces the face segmentation from the convex-hull of the brain surface. Once the white-matter has been segmented, a convex-hull of the segmentation is generated in step 7. This mesh is passed to a modified version of the AlgorithmBrainExtractor in MIPAV. The convex-hull of the white-matter often provides a good enough segmentation of the skull, but in a few cases the convex-hull of the white-matter does not include the entire surface of the brain and processing the mesh with the AlgorithmBrainExtractor corrects the mesh. Steps 8-9 were added to provide a buffer around the brain segmentation. This enables the algorithm to err on the side of removing too little data rather than removing small portions of the brain surface.
      • getBoundsDistance

        private void getBoundsDistance​(WildMagic.LibFoundation.Mathematics.Vector3f min,
                                       WildMagic.LibFoundation.Mathematics.Vector3f max,
                                       WildMagic.LibFoundation.Mathematics.Vector3f centerBound,
                                       float limitX,
                                       float limit)
      • getIntersectX

        private float getIntersectX​(WildMagic.LibFoundation.Mathematics.Vector3f kV0,
                                    WildMagic.LibFoundation.Mathematics.Vector3f kV1,
                                    WildMagic.LibFoundation.Mathematics.Vector3f kV2,
                                    float iY,
                                    float iZ)
        Compute the point of intersection between a line (0,iY,iZ)+t(1,0,0) and the triangle defined by the three input points. All calculations are in voxel coordinates and the x-value of the intersection point is truncated to an integer.
        Parameters:
        kV0 - a 3D vertex of the triangle
        kV1 - a 3D vertex of the triangle
        kV2 - a 3D vertex of the triangle
        iY - the y-value of the origin of the line
        iZ - the z-value of the origin of the line
        Returns:
        the x-value of the intersection
      • getIntersectY

        private float getIntersectY​(WildMagic.LibFoundation.Mathematics.Vector3f kV0,
                                    WildMagic.LibFoundation.Mathematics.Vector3f kV1,
                                    WildMagic.LibFoundation.Mathematics.Vector3f kV2,
                                    float iX,
                                    float iZ)
        Compute the point of intersection between a line (iX,0,iZ)+t(0,1,0) and the triangle defined by the three input points. All calculations are in voxel coordinates and the y-value of the intersection point is truncated to an integer.
        Parameters:
        kV0 - a 3D vertex of the triangle
        kV1 - a 3D vertex of the triangle
        kV2 - a 3D vertex of the triangle
        iX - the x-value of the origin of the line
        iZ - the z-value of the origin of the line
        Returns:
        the y-value of the intersection
      • getIntersectZ

        private float getIntersectZ​(WildMagic.LibFoundation.Mathematics.Vector3f kV0,
                                    WildMagic.LibFoundation.Mathematics.Vector3f kV1,
                                    WildMagic.LibFoundation.Mathematics.Vector3f kV2,
                                    float iX,
                                    float iY)
        Compute the point of intersection between a line (iX,iY,0)+t(0,0,1) and the triangle defined by the three input points. All calculations are in voxel coordinates and the z-value of the intersection point is truncated to an integer.
        Parameters:
        kV0 - a 3D vertex of the triangle
        kV1 - a 3D vertex of the triangle
        kV2 - a 3D vertex of the triangle
        iX - the x-value of the origin of the line
        iY - the y-value of the origin of the line
        Returns:
        the z-value of the intersection
      • getMedianIntensity

        private float getMedianIntensity​(ModelImage image,
                                         java.util.BitSet mask)
      • inBounds

        private boolean inBounds​(int x,
                                 int y,
                                 int z)
      • randomize

        private ModelImage randomize​(ModelImage image,
                                     int stepSize)
        Randomizes voxel cubes with similar average intensities.
        Parameters:
        image -
        stepSize -
        Returns:
      • registerImages

        private ModelImage registerImages​(ModelImage target,
                                          ModelImage src)
        Registers the atlas image to the input target image:
        Parameters:
        target -
        src -
        Returns:
      • removeUnusedVertices

        private WildMagic.LibGraphics.SceneGraph.TriMesh removeUnusedVertices​(WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      • scaleMesh

        private void scaleMesh​(WildMagic.LibGraphics.SceneGraph.TriMesh mesh)
        Scales the input mesh based on the offset parameter set in the constructor. This enables the user to set a buffer around the segmentation.
        Parameters:
        mesh -
      • skullRemoval

        private void skullRemoval()
        Main algorithm implementation, skull segmentation and removal.
      • subtractMask

        private void subtractMask​(ModelImage image)
        Removes portions of the image that are masked.
        Parameters:
        image -