Package gov.nih.mipav.model.file
Class FileMincHDF
java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileMincHDF
HDF5 based reader/writer for MINC 2.0
Currently, for the image max and image min nodes: in the case of 3d images in which 1 image min and 1 image max is to
be written out per slice, the dimorder is hardcoded to zspace. Sometimes minc2 3D images come in with just 1 image
min and 1 image max per volume...in that case, we write out the same way and do not write out a dimorder
ToDo: We need to make this type of functionality work for 4D images. Currently the code writes out 1 image min nd 1
image max per slice and hardcode the dimorder to time,zspace. We need to write out the same way we read in....yet to
do.
- Author:
- linkb
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic Stringstatic Stringprivate String[]The ordering of the dimensions.private int[]private String[]private String[]private double[][]direction cosines matrixprivate final StringThe directory containing the minc file being written out or read in.private final ncsa.hdf.object.FileFormatwill always use the HDF5 fileformatprivate final FileInfoMincHDFprivate final StringThe name of the minc file to be read in or written out.private ncsa.hdf.object.h5.H5Filethe file to be read/writtenprivate DefaultMutableTreeNodethe image node of the HDF file tree that contains the image data, and min max per slice informationprivate booleanprivate boolean[]whether each axis is centeredstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate double[]static final Stringstatic final Stringstatic final Stringprivate double[]MINC resolution (can be negative)private double[]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 voidbuildDimensionNode(ModelImage image, FileWriteOptions options, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, DefaultTreeModel model) Creates the dimension node for files that are not Minc2.0private voidbuildImageNode(ModelImage image, FileWriteOptions options, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, DefaultTreeModel model) Builds the image node (done for all filetypes when writing to MINC2.0 HDF5private voidbuildInfoNode(ModelImage image, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, DefaultTreeModel model) builds the Info node for files that were not originally MINC 2.0 HDF5private static final DefaultMutableTreeNodefindNode(DefaultMutableTreeNode nodeToSearch, String nodeNameToFind) Recursively finds the node within a tree with a given name.Returns the FileInfoXML read from the file.private intgetMipavOrderFromDimNode(String dimNodeStr) Gets the proper MIPAV dimension ordering index for a given Minc dim node string using the image info.static final FileInfoBase.UnitgetUnitFromString(String val) Return the proper unit based on a given unit string (abbrevation or full word).private voidparseDims(DefaultMutableTreeNode dimensionNode) Determines the dimensions, dirCosines, isCentered, step, and alignmentprivate voidrecursively parses the HDF tree into the given file infoprivate ModelImageparseImage(DefaultMutableTreeNode iNode) Parses the image node and reads in the image data (and image min and max per slice)private voidparseImageDimOrder(DefaultMutableTreeNode rootNode) parses the dim orderprivate voidparseInfo(DefaultMutableTreeNode infoNode) Parses the info node (right now only grabs the modality)booleanreadHeader(DefaultMutableTreeNode rootNode) readImage(boolean one) Reads a MINC 2.0 HDF-5 filevoidwriteImage(ModelImage image, FileWriteOptions options) Writes a MINC format type image.Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, finalize, 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
-
NODE_DIMENSIONS
- See Also:
-
NODE_IMAGE
- See Also:
-
NODE_INFO
- See Also:
-
LEAF_IMAGE
- See Also:
-
LEAF_IMAGE_MAX
- See Also:
-
LEAF_IMAGE_MIN
- See Also:
-
LEAF_X_SPACE
- See Also:
-
LEAF_Y_SPACE
- See Also:
-
LEAF_Z_SPACE
- See Also:
-
LEAF_T_SPACE
- See Also:
-
LEAF_ACQUISITION
- See Also:
-
LEAF_PATIENT
- See Also:
-
LEAF_PROCESSING
- See Also:
-
LEAF_STUDY
- See Also:
-
ATTR_DIM_UNITS
- See Also:
-
ATTR_DIM_START
- See Also:
-
ATTR_DIM_LENGTH
- See Also:
-
ATTR_DIM_DIRECTION_COSINES
- See Also:
-
ATTR_DIM_SPACETYPE
- See Also:
-
ATTR_DIM_STEP
- See Also:
-
ATTR_DIM_ALIGNMENT
- See Also:
-
ATTR_IMAGE_DIM_ORDER
- See Also:
-
ATTR_IMAGE_VALID_RANGE
- See Also:
-
ATTR_INFO_STUDY_MODALITY
- See Also:
-
ATTR_INFO_SLICE_THICKNESS
- See Also:
-
DICOM_GROUP_PREFIX
-
DICOM_ELEMENT_PREFIX
-
imageNode
the image node of the HDF file tree that contains the image data, and min max per slice information -
dimStringsReordered
-
dimStrings
-
step
private double[] stepMINC resolution (can be negative) -
stepReordered
private double[] stepReordered -
dirCosines
private double[][] dirCosinesdirection cosines matrix -
isCentered
private boolean[] isCenteredwhether each axis is centered -
mincStartLoc
private double[] mincStartLoc -
fileDir
The directory containing the minc file being written out or read in. -
fileName
The name of the minc file to be read in or written out. -
dimOrder
The ordering of the dimensions. Should be found in the image node attributes. -
fileFormat
private final ncsa.hdf.object.FileFormat fileFormatwill always use the HDF5 fileformat -
h5File
private ncsa.hdf.object.h5.H5File h5Filethe file to be read/written -
fileInfo
-
dimReorderIndexes
private int[] dimReorderIndexes -
is4D
private boolean is4D
-
-
Constructor Details
-
FileMincHDF
MINC reader/writer constructor.- Parameters:
fName- File name.fDir- File directory.- Throws:
IOException- if there is an error constructing the files
-
-
Method Details
-
readHeader
- Throws:
Exception
-
getFileInfo
Returns the FileInfoXML read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
parseHDFHeader
recursively parses the HDF tree into the given file info- Parameters:
node-fileInfo-- Throws:
Exception
-
findNode
private static final DefaultMutableTreeNode findNode(DefaultMutableTreeNode nodeToSearch, String nodeNameToFind) Recursively finds the node within a tree with a given name.- Parameters:
nodeToSearch- the root node of the tree to searchnodeNameToFind- the name of the node to find- Returns:
- a node with the name given, or null if no node was found within the given tree
-
parseImageDimOrder
parses the dim order- Parameters:
rootNode-- Throws:
Exception
-
parseDims
Determines the dimensions, dirCosines, isCentered, step, and alignment- Parameters:
dimensionNode-fileInfo-- Throws:
Exception
-
parseInfo
Parses the info node (right now only grabs the modality)- Parameters:
infoNode-fileInfo-- Throws:
Exception
-
parseImage
Parses the image node and reads in the image data (and image min and max per slice)- Parameters:
iNode-fileInfo-- Returns:
- Throws:
Exception
-
readImage
Reads a MINC 2.0 HDF-5 file- Parameters:
one-- Returns:
- the image
- Throws:
Exception
-
buildDimensionNode
private void buildDimensionNode(ModelImage image, FileWriteOptions options, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, DefaultTreeModel model) throws Exception Creates the dimension node for files that are not Minc2.0- Parameters:
image-format-mincNode-model-- Throws:
Exception
-
buildInfoNode
private void buildInfoNode(ModelImage image, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, DefaultTreeModel model) throws Exception builds the Info node for files that were not originally MINC 2.0 HDF5- Parameters:
image-format-mincNode-model-- Throws:
Exception
-
buildImageNode
private void buildImageNode(ModelImage image, FileWriteOptions options, ncsa.hdf.object.FileFormat format, FileMincHDF.HDFNode mincNode, DefaultTreeModel model) throws Exception Builds the image node (done for all filetypes when writing to MINC2.0 HDF5- Parameters:
image- the image nodeformat- the HDF5 FileFormatmincNode- the minc root nodemodel- the tree model linked to the root node- Throws:
Exception
-
writeImage
Writes a MINC format type image. Calls the appropriate header method.- Parameters:
image- Image model where the data is stored.options- Information about how to write this file.- Throws:
IOException- if there is an error writing the fileException- See Also:
-
getMipavOrderFromDimNode
Gets the proper MIPAV dimension ordering index for a given Minc dim node string using the image info.- Parameters:
dimNodeStr- A minc dimension node string (i.e., xspace, yspace, zspace, time).- Returns:
- The proper MIPAV dimension ordering index.
-
getUnitFromString
Return the proper unit based on a given unit string (abbrevation or full word).- Parameters:
val- The unit name or abbreviation.- Returns:
- The proper unit for the given string, or Unit.UNKNOWN_MEASURE if not recognized.
-