Class FileMGH
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 invalid input: '<'= 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]DOCUMENT ME!private intDOCUMENT ME!private floatDOCUMENT ME!(package private) String[]DOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private int[]DOCUMENT ME!private FileDOCUMENT ME!private StringDOCUMENT ME!private FileInfoMGHDOCUMENT ME!private longDOCUMENT ME!private StringDOCUMENT ME!private FileInputStreamDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private shortDOCUMENT ME!private booleanDOCUMENT ME!private intDOCUMENT ME!private ModelImageDOCUMENT ME!private TransMatrixDOCUMENT ME!private static final intDOCUMENT ME!private intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!(package private) intDOCUMENT ME!private intDOCUMENT ME!private longDOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private static final intDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private intPresent version number is 1.private intDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!private floatDOCUMENT ME!Fields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidattachFileInfo(FileInfoMGH fileInfo, ModelImage image) DOCUMENT ME!voidfinalize()Prepares this class for cleanup.static int[]Return the 3 axis orientation codes that correspond to the closest standard anatomical orientation of the (i,j,k) axes.Returns the FileInfoMGH read from the file.private intHelper method to calculate the offset for getting only the middle NIFTI image slice from the 3D file.booleanreadHeader(String imageFileName, String fileDir) Reads the MGH header and stores the information in fileInfo.readImage(boolean one) Reads a MGH image file by reading the header then making a FileRaw to read the image for all filenames in the file list.voidreadImage(float[] buffer) Reads a MGH image file by reading the header then making a FileRaw to read the file.private voidupdateorigins(FileInfoBase[] fileInfo) Updates the start locations.voidwriteImage(ModelImage image, FileWriteOptions options) Writes a MGH or MGZ format type image.Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, floatToBytes, getBufferDouble, getBufferFloat, getBufferInt, getBufferLong, getBufferShort, getBufferUShort, getDataType, getDouble, getFloat, getInt, getLong, getProgressChangeListeners, getRaFile, getSignedShort, getString, getUInt, getUnsignedByte, getUnsignedShort, intToBytes, isBigEndian, isProgressBarVisible, linkProgress, longToBytes, readDouble, readFloat, readInt, readLong, readShort, readString, readUnsignedShort, removeProgressChangeListener, setBigEndian, setBufferFloat, setBufferInt, setBufferLong, setBufferShort, setBufferString, setDataType, setEndianess, shortToBytes, writeBytes, writeDouble, writeFloat, writeInt, writeLong, writeShort
-
Field Details
-
MRI_UCHAR
private static final int MRI_UCHARDOCUMENT ME!- See Also:
-
MRI_INT
private static final int MRI_INTDOCUMENT ME!- See Also:
-
MRI_LONG
private static final int MRI_LONGDOCUMENT ME!- See Also:
-
MRI_FLOAT
private static final int MRI_FLOATDOCUMENT ME!- See Also:
-
MRI_SHORT
private static final int MRI_SHORTDOCUMENT ME!- See Also:
-
MRI_BITMAP
private static final int MRI_BITMAPDOCUMENT ME!- See Also:
-
MRI_TENSOR
private static final int MRI_TENSORDOCUMENT ME!- See Also:
-
TAG_OLD_COLORTABLE
private static final int TAG_OLD_COLORTABLEDOCUMENT ME!- See Also:
-
TAG_OLD_USEREALRAS
private static final int TAG_OLD_USEREALRASDOCUMENT ME!- See Also:
-
TAG_CMDLINE
private static final int TAG_CMDLINEDOCUMENT ME!- See Also:
-
TAG_OLD_SURF_GEOM
private static final int TAG_OLD_SURF_GEOMDOCUMENT ME!- See Also:
-
TAG_OLD_MGH_XFORM
private static final int TAG_OLD_MGH_XFORMDOCUMENT ME!- See Also:
-
TAG_MGH_XFORM
private static final int TAG_MGH_XFORMDOCUMENT ME!- See Also:
-
MAX_CMDS
private static final int MAX_CMDSDOCUMENT ME!- See Also:
-
cmdlines
String[] cmdlinesDOCUMENT ME! -
ncmds
int ncmdsDOCUMENT ME! -
axisOrientation
private int[] axisOrientationDOCUMENT ME! -
bytesPerValue
private int bytesPerValueDOCUMENT ME! -
ca
private float caDOCUMENT ME! -
cr
private float crDOCUMENT ME! -
cs
private float csDOCUMENT ME! -
dataType
private int dataTypeDOCUMENT ME! -
depth
private int depthDOCUMENT ME! -
dof
private int dofDOCUMENT ME! -
extents
private int[] extentsDOCUMENT ME! -
file
DOCUMENT ME! -
fileDir
DOCUMENT ME! -
fileInfo
DOCUMENT ME! -
fileLength
private long fileLengthDOCUMENT ME! -
fileName
DOCUMENT ME! -
fis
DOCUMENT ME! -
flipAngle
private float flipAngleDOCUMENT ME! -
fov
private float fovDOCUMENT ME! -
goodRASFlag
private short goodRASFlagDOCUMENT ME! -
gunzip
private boolean gunzipDOCUMENT ME! -
height
private int heightDOCUMENT ME! -
image
DOCUMENT ME! -
matrix
DOCUMENT ME! -
mghType
private int mghTypeDOCUMENT ME! -
nFrames
private int nFramesDOCUMENT ME! -
optionalStructuresLocation
private long optionalStructuresLocationDOCUMENT ME! -
origin
private float[] originDOCUMENT ME! -
resolutions
private float[] resolutionsDOCUMENT ME! -
te
private float teDOCUMENT ME! -
ti
private float tiDOCUMENT ME! -
tr
private float trDOCUMENT ME! -
version
private int versionPresent version number is 1. -
width
private int widthDOCUMENT ME! -
xa
private float xaDOCUMENT ME! -
xr
private float xrDOCUMENT ME! -
xs
private float xsDOCUMENT ME! -
ya
private float yaDOCUMENT ME! -
yr
private float yrDOCUMENT ME! -
ys
private float ysDOCUMENT ME! -
za
private float zaDOCUMENT ME! -
zr
private float zrDOCUMENT ME! -
zs
private float zsDOCUMENT ME!
-
-
Constructor Details
-
FileMGH
Constructs new file object.- Parameters:
fName- File name.fDir- File directory.
-
-
Method Details
-
finalize
public void finalize()Prepares this class for cleanup. Calls thefinalizemethod for existing elements, closes any open files and sets other elements tonull. -
getFileInfo
Returns the FileInfoMGH read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
readHeader
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:
IOException- if there is an error reading the header- See Also:
-
readImage
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:
IOException- if there is an error reading the fileOutOfMemoryError- See Also:
-
readImage
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:
IOException- if there is an error reading the fileOutOfMemoryError- See Also:
-
writeImage
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:
IOException- if there is an error writing the file
-
attachFileInfo
DOCUMENT ME!- Parameters:
fileInfo- -- a NIFTI file Info that has already been readimage- -- a ModelImage that the fileInfo needs to be attached to
-
getAxisOrientation
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
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!
-