Class FileMGH


  • public class FileMGH
    extends FileBase
    The class reads MGH files. The 4 by 4 matrix in MGH transforms x,y,z indexes to (right, anterior, superior) coordinates where +x = Right, +y = Anterior, +z = Superior. In MIPAV the 4 by 4 matrix does not imply the axis orientations.

    The MGH definition is: [right] = [xr yr zr] [ xsize * x] + [rorigin] [anterior] = [xa ya za] [ ysize * y] + [aorigin] [superior] = [xs ys zs] [ zsize * z] + [sorigin] Now in going to MIPAV a change must occur. MGH has L->R and P->A while MIPAV uses R->L in all axes and A->P in axes 0 and 1 and P->A in axis 2, so this would cause xr, yr, zr, rorigin, xa, ya, za, and aorigin to be multiplied by -1. cr, ca, and cs refer to the center point of the scanner coordinate system.

    A 284 byte header always precedes the data buffer In version 1 if the goodRASFlag <= 0, then only the first 30 bytes are read. If the goodRASFlag > 0, then the first 90 bytes are read

    Immediately after the data buffer other optional data structures may be found: They are: Recovery time in milliseconds float Flip angle in radians float Echo time in milliseconds float Inversion time in millseconds float Field of view in millimeters float Comment about fov field from Nick Schmansky: The FoV field should be ignored. In discussing this field with Bruce Fischl, and looking more closely at the code, it appears to be a field with a long and inconsistent usage history (in how it is set and where the data originates). We do not rely on it in our binaries. Lastly, tags including the Talairach transform file name and a list of commands used to create this data(provenance info) may be present.

    I am not reading the contents of the Talairach transform file for 3 reasons: 1.) This information is probably not very useful. 2.) Every sample file that I obtained from MGH gave the same name: talairach.xfm. If this name is always used, then it is impossible to tell which .mgh file it corresponds to. 3.) The Talairach transform file is a clear ascii file, so it can be easily read with any number of common programs.

    See Also:
    FileIO, FileInfoMGH, FileRaw
    • Field Detail

      • TAG_OLD_COLORTABLE

        private static final int TAG_OLD_COLORTABLE
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • TAG_OLD_USEREALRAS

        private static final int TAG_OLD_USEREALRAS
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • TAG_OLD_SURF_GEOM

        private static final int TAG_OLD_SURF_GEOM
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • TAG_OLD_MGH_XFORM

        private static final int TAG_OLD_MGH_XFORM
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • cmdlines

        java.lang.String[] cmdlines
        DOCUMENT ME!
      • ncmds

        int ncmds
        DOCUMENT ME!
      • axisOrientation

        private int[] axisOrientation
        DOCUMENT ME!
      • bytesPerValue

        private int bytesPerValue
        DOCUMENT ME!
      • ca

        private float ca
        DOCUMENT ME!
      • cr

        private float cr
        DOCUMENT ME!
      • cs

        private float cs
        DOCUMENT ME!
      • dataType

        private int dataType
        DOCUMENT ME!
      • depth

        private int depth
        DOCUMENT ME!
      • dof

        private int dof
        DOCUMENT ME!
      • extents

        private int[] extents
        DOCUMENT ME!
      • file

        private java.io.File file
        DOCUMENT ME!
      • fileDir

        private java.lang.String fileDir
        DOCUMENT ME!
      • fileLength

        private long fileLength
        DOCUMENT ME!
      • fileName

        private java.lang.String fileName
        DOCUMENT ME!
      • fis

        private java.io.FileInputStream fis
        DOCUMENT ME!
      • flipAngle

        private float flipAngle
        DOCUMENT ME!
      • fov

        private float fov
        DOCUMENT ME!
      • goodRASFlag

        private short goodRASFlag
        DOCUMENT ME!
      • gunzip

        private boolean gunzip
        DOCUMENT ME!
      • height

        private int height
        DOCUMENT ME!
      • mghType

        private int mghType
        DOCUMENT ME!
      • nFrames

        private int nFrames
        DOCUMENT ME!
      • optionalStructuresLocation

        private long optionalStructuresLocation
        DOCUMENT ME!
      • origin

        private float[] origin
        DOCUMENT ME!
      • resolutions

        private float[] resolutions
        DOCUMENT ME!
      • te

        private float te
        DOCUMENT ME!
      • ti

        private float ti
        DOCUMENT ME!
      • tr

        private float tr
        DOCUMENT ME!
      • version

        private int version
        Present version number is 1.
      • width

        private int width
        DOCUMENT ME!
      • xa

        private float xa
        DOCUMENT ME!
      • xr

        private float xr
        DOCUMENT ME!
      • xs

        private float xs
        DOCUMENT ME!
      • ya

        private float ya
        DOCUMENT ME!
      • yr

        private float yr
        DOCUMENT ME!
      • ys

        private float ys
        DOCUMENT ME!
      • za

        private float za
        DOCUMENT ME!
      • zr

        private float zr
        DOCUMENT ME!
      • zs

        private float zs
        DOCUMENT ME!
    • Constructor Detail

      • FileMGH

        public FileMGH​(java.lang.String fName,
                       java.lang.String fDir)
        Constructs new file object.
        Parameters:
        fName - File name.
        fDir - File directory.
    • Method Detail

      • finalize

        public void finalize()
        Prepares this class for cleanup. Calls the finalize method for existing elements, closes any open files and sets other elements to null.
        Overrides:
        finalize in class FileBase
      • getFileInfo

        public FileInfoMGH getFileInfo()
        Returns the FileInfoMGH read from the file.
        Returns:
        File info read from file, or null if it has not been read.
      • readHeader

        public boolean readHeader​(java.lang.String imageFileName,
                                  java.lang.String fileDir)
                           throws java.io.IOException
        Reads the MGH header and stores the information in fileInfo.
        Parameters:
        imageFileName - File name of image.
        fileDir - Directory.
        Returns:
        Flag to confirm a successful read.
        Throws:
        java.io.IOException - if there is an error reading the header
        See Also:
        FileInfoMGH
      • readImage

        public ModelImage readImage​(boolean one)
                             throws java.io.IOException,
                                    java.lang.OutOfMemoryError
        Reads a MGH image file by reading the header then making a FileRaw to read the image for all filenames in the file list. Only the one file directory (currently) supported.
        Parameters:
        one - flag indicating one image of a 3D dataset should be read in.
        Returns:
        The image.
        Throws:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError
        See Also:
        FileRaw
      • readImage

        public void readImage​(float[] buffer)
                       throws java.io.IOException,
                              java.lang.OutOfMemoryError
        Reads a MGH image file by reading the header then making a FileRaw to read the file. Image data is left in buffer. If the fileInfo cannot be found, the header will be located and read first. Image is not 'flipped', and neither units of measure nor orientation are set.
        Parameters:
        buffer - Image buffer to store image data into.
        Throws:
        java.io.IOException - if there is an error reading the file
        java.lang.OutOfMemoryError
        See Also:
        FileRaw
      • writeImage

        public void writeImage​(ModelImage image,
                               FileWriteOptions options)
                        throws java.io.IOException
        Writes a MGH or MGZ format type image.
        Parameters:
        image - Image model of data to write.
        options - options such as starting and ending slices and times
        Throws:
        java.io.IOException - if there is an error writing the file
      • attachFileInfo

        private void attachFileInfo​(FileInfoMGH fileInfo,
                                    ModelImage image)
        DOCUMENT ME!
        Parameters:
        fileInfo - -- a NIFTI file Info that has already been read
        image - -- a ModelImage that the fileInfo needs to be attached to
      • getAxisOrientation

        public static int[] getAxisOrientation​(TransMatrix mat)
        Return the 3 axis orientation codes that correspond to the closest standard anatomical orientation of the (i,j,k) axes.
        Parameters:
        mat - 4x4 matrix that transforms (i,j,k) indexes to x,y,z coordinates where +x =Left, +y = Posterior, +z = Superior Only the upper-left 3x3 corner of the matrix is used This routine finds the permutation of (x,y,z) which has the smallest angle to the (i,j,k) axes directions, which are columns of the input matrix Errors: The codes returned will be zero.
        Returns:
        DOCUMENT ME!
      • getOffset

        private int getOffset()
        Helper method to calculate the offset for getting only the middle NIFTI image slice from the 3D file.
        Returns:
        offset
      • updateorigins

        private void updateorigins​(FileInfoBase[] fileInfo)
        Updates the start locations. Each image has a fileinfo where the start locations are stored. Note that the start location for the Z (3rd) dimension change with the change is the slice. The origin is in the upper left corner and we are using the right hand rule. + x -> left to right; + y -> top to bottom and + z -> into screen.
        Parameters:
        fileInfo - DOCUMENT ME!