Class AlgorithmDWI2DTI

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

    public class AlgorithmDWI2DTI
    extends AlgorithmBase
    implements AlgorithmInterface
    Algorithm calculates a Diffusion Tensor Image from a series of Diffusion Weighted Images. See: Introduction to Diffusion Tensor Imaging, by Susumu Mori
    • Field Detail

      • m_kMaskImage

        private ModelImage m_kMaskImage
        Mask Image for masking brain regions during tensor calculation:
      • m_kDWIImage

        private ModelImage m_kDWIImage
        DWI Image 4D series of weighted diffusion images
      • m_kB0Image

        private ModelImage m_kB0Image
        B0 weighted image:
      • m_kB0Frame

        private ViewJFrameImage m_kB0Frame
        ViewJFrameImage for displaying the B0 weighted image:
      • m_bDisplayB0

        private boolean m_bDisplayB0
        Whether to just display the B0 weighted image and return, or to do a full calculation:
      • m_iSlices

        private final int m_iSlices
        Number of slices in the input images:
      • m_iDimX

        private final int m_iDimX
        X Dimension of the input images:
      • m_iDimY

        private final int m_iDimY
        Y Dimension of the input images:
      • m_iBOrig

        private final int m_iBOrig
        Number of different entries in the BMatrix:
      • m_iWeights

        private final int m_iWeights
        Number of images in the weighted series:
      • m_fMeanNoise

        private float m_fMeanNoise
        The mean noise value:
      • m_kBMatrix

        private WildMagic.LibFoundation.Mathematics.GMatrixd m_kBMatrix
        General matrix storing BMatrix values.
      • m_aakDWIList

        private java.lang.String[][] m_aakDWIList
        List of file names for the Diffusion Weighted Images, from the .path file.
      • m_aiMatrixEntries

        private int[] m_aiMatrixEntries
        keeps track of unique entries in the BMatrix
      • m_kRawImageFormat

        private java.lang.String m_kRawImageFormat
        Format of the raw data: (float, int, dicom, etc.)
      • m_kDTI

        private ModelImage m_kDTI
        Output DTI Image:
      • m_bUseDTIParameters

        private boolean m_bUseDTIParameters
        When true, use the ModelImage DTI parameters.
      • m_3dbufferMap_float

        private final java.util.HashMap<java.lang.String,​float[]> m_3dbufferMap_float
      • m_4dbufferMap_float

        private final java.util.HashMap<java.lang.String,​float[]> m_4dbufferMap_float
      • m_3dbufferMap_int

        private final java.util.HashMap<java.lang.String,​int[]> m_3dbufferMap_int
      • m_4dbufferMap_int

        private final java.util.HashMap<java.lang.String,​int[]> m_4dbufferMap_int
    • Constructor Detail

      • AlgorithmDWI2DTI

        public AlgorithmDWI2DTI​(ModelImage kMaskImage,
                                boolean bDisplayB0,
                                int iSlices,
                                int iDimX,
                                int iDimY,
                                int iBOrig,
                                int iWeights,
                                float fMeanNoise,
                                java.lang.String[][] aakDWIList,
                                int[] aiMatrixEntries,
                                WildMagic.LibFoundation.Mathematics.GMatrixd kBMatrix,
                                java.lang.String kRawFormat)
        Create a new AlgorithmDWI2DTI
        Parameters:
        kMaskImage - mask image masking non-brain regions, if null it is calculated.
        bDisplayB0 - when true open and display the B0 weighted image and return.
        iSlices - number of slices in the raw data.
        iDimX - x-dimensions of the raw data.
        iDimY - y-dimensions of the raw data.
        iBOrig - number of different entries in the BMatrix.
        iWeights - number of weighted series.
        fMeanNoise - mean noise value.
        aakDWIList - list of file names in the weighted series.
        repidx -
        kBMatrix - BMatrix values.
        kRawFormat - format string for the raw data.
    • Method Detail

      • algorithmPerformed

        public void algorithmPerformed​(AlgorithmBase algorithm)
        Description copied from interface: AlgorithmInterface
        Called after an algorithm this listener is registered to exits (maybe successfully, maybe not). If the algorithm is run in a separate thread, this call will be made within that thread. If not, this call will be made from that same, shared thread.
        Specified by:
        algorithmPerformed in interface AlgorithmInterface
        Parameters:
        algorithm - the algorithm which has just completed
      • calculateDTI

        public void calculateDTI​(int start,
                                 int end,
                                 float[] dtiData,
                                 float[][][] weightData,
                                 Jama.Matrix B,
                                 Jama.Matrix H)
      • calculateDTIVoxel

        public void calculateDTIVoxel​(float[] dtiData,
                                      float[][] dwiData,
                                      float[][][] weightData,
                                      int x,
                                      int y,
                                      int z,
                                      Jama.Matrix B)
      • calculateDTIVoxel2

        public void calculateDTIVoxel2​(float[] dtiData,
                                       float[][] dwiData,
                                       float[][][] weightData,
                                       int x,
                                       int y,
                                       int z,
                                       Jama.Matrix H,
                                       int volumeSize)
      • calculateMatrix

        public Jama.Matrix calculateMatrix​(Jama.Matrix m)
      • createDWIImage

        public float[] createDWIImage()
        Second step in processing the diffusion weighted images. This function is called once the brain extractor is complete. The brain image is transformed into a mask image, which is passed to this function. The mask image limits where the tensor calculations are performed. The tensor is calculated, then the eigen vectors and functional anisotropy images. The DialogDTIColorDisplay is then launched.
        Parameters:
        kMaskImage - mask image representing the brain.
      • deleteImages

        public void deleteImages()
      • disposeLocal

        public void disposeLocal()
      • getDTI

        public ModelImage getDTI()
        Return the DTI Image.
        Returns:
        the DTI Image.
      • runAlgorithm

        public void runAlgorithm()
        Calculate the DTI image. If the mask image is null, calculate the mask image first.
        Specified by:
        runAlgorithm in class AlgorithmBase
      • solve

        public float[] solve​(Jama.Matrix y,
                             Jama.Matrix m)
      • createDWI

        private void createDWI()
      • createMaskImage

        private void createMaskImage()
        Create the mask image. Create an image with the B0 weighted data, if one has not already been created. Next use the JDialogBrainSurfaceExtractor to extract only the brain regions.
      • createTensorWeights

        private float[][][] createTensorWeights()
        Creates the weighted data for the tensor calculation from the diffusion weighted images.
        Returns:
        float[][][] containing the weights used in the tensor calculation.
      • readDicomWeight

        private float[] readDicomWeight​(int iSlice,
                                        int iWeight)
        Get the slice data for the image with the given slice and weight.
        Parameters:
        iSlice - slice to read.
        iWeight - weight to read.
        Returns:
        float[] containing the data.
      • readFloat

        private float readFloat​(byte[] abData,
                                int iIndex)
        Translates the byte[] into float values at the given indes iIndex.
        Parameters:
        abData - byte[] containing float values.
        iIndex - index into the array to get the float from.
        Returns:
        float value representing 4 bytes starting at abData[iIndex*4].
      • readFloatWeight

        private float[] readFloatWeight​(int iSlice,
                                        int iWeight)
        Get the slice data for the image with the given slice and weight. For 3d and 4d non-multifile images, the whole buffer is read in and stored...then slice data is extracted from that buffer
        Parameters:
        iSlice - slice to read.
        iWeight - weight to read.
        Returns:
        float[] containing the data.
      • readInteger

        private int readInteger​(byte[] abData,
                                int iIndex)
        Translates the byte[] into integer values at the given indes iIndex.
        Parameters:
        abData - byte[] containing integer values.
        iIndex - index into the array to get the float from.
        Returns:
        integer value representing 4 bytes starting at abData[iIndex*4].
      • readIntegerWeight

        private float[] readIntegerWeight​(int iSlice,
                                          int iWeight)
        Get the slice data for the image with the given slice and weight. For 3d and 4d non-multifile images, the whole buffer is read in and stored...then slice data is extracted from that buffer
        Parameters:
        iSlice - slice to read.
        iWeight - weight to read.
        Returns:
        float[] containing the data.
      • readSliceWeight

        private float[] readSliceWeight​(int iSlice,
                                        int iWeight)
        Get the slice data for the image with the given slice and weight.
        Parameters:
        iSlice - slice to read.
        iWeight - weight to read.
        Returns:
        float[] containing the data.