Package gov.nih.mipav.model.file
Class FileNRRD
java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileNRRD
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue for RAS and LAS, false for LPS.private booleanTrue if data file:[ ] encountered If true, autosequence using integer format specification varied according to , , and . private double[]Maximum axis value.private double[]Minimum axis value.private int[]For each axis R2L, L2R, A2P, P2A, I2S, or S2Iprivate StringIn autosequencing number between a capital D and the last period used in generating filenames.private StringIn autosequencing number before percentage sign and period used in generating start of autosequenced filename.private booleanUsed if autosequencing.private static final intThe location of the sample is located in the interior of the grid element.private int[]May remain null or may be created as NONE, CELL, or NODE.private String[][]"modality:=DWMRI" : This key/value pair explicitly indicates that the image is a diffusion-weighted MRI scan, and it implies that all of the following key/value pairs are also set in the header: "DWMRI_b-value:=b " : This key/value pair gives the (scalar) diffusion-weighting value, in units of s/mm^2.private String[][]"DWMRI_NEX_NNNN:=M " means that the information provided for image NNNN (either gradient or B-matrix) is the same as for image NNNN+1, NNNN+2, up to and including NNNN+M-1.private booleanDOCUMENT ME!private StringDOCUMENT ME!private FileDOCUMENT ME!private StringDOCUMENT ME!private FileInfoNRRDDOCUMENT ME!private FileInfoNRRDDOCUMENT ME!private longDOCUMENT ME!private StringDOCUMENT ME!private booleanDOCUMENT ME!private String[]DOCUMENT ME!private intDOCUMENT ME!private int[]DOCUMENT ME!private int[]DOCUMENT ME!private booleanDOCUMENT ME!private booleanDOCUMENT ME!private booleanIf true, data has gzip compression.private ModelImageDOCUMENT ME!private int[]DOCUMENT ME!private String[]Kind of information represented by the samples along each axis.private static final intA patient-based right-handed coordinate frame, with ordered basis vectors pointing towards left, posterior, and superior, respectively.private static final intLike LPS, but with time along the fourth axis.private TransMatrixDOCUMENT ME!private double[][]The measurement frame is a basic (per-array) field specification (not per-axis), which identifies a spaceDim-by-spaceDim matrix, where spaceDim is the dimension of the word space (implied by space or given by space dimension).private intDOCUMENT ME!private intDOCUMENT ME!private String[]MIPAV axis names such as X, Y, or Zprivate int[]DOCUMENT ME!private static final intThe location of the sample is at the boundary between grid elements.private static final intCentering information for this axis is either meaningless or unknown.private intDoes not tell if color or black and white.private intMay not be the same as MIPAV dimensions because in nrrd color is a dimension.private String[]nrrd axis names such as X, Y, or Zprivate int[]The number of samples along each nrrd axisprivate String[]DOCUMENT ME!private String[]Units of measurement of nrrd axisprivate intDOCUMENT ME!private intNumber of nrrd dimensions for which the kinds string equals "SPACE".private intNumber of axes for which thicknesses values foundprivate longDOCUMENT ME!private booleanIf true, header and data both stored in .nrrd file.private booleanTrue for .nrrd file with header and data in the same file.private float[]DOCUMENT ME!private intIn autosequencing if the sequence number length is less than the padding number, zeroes are added to the front of the sequence number until the sequence number length equals the padding number.private int0 indicates pixels are RGB, RGB chunky 1 indicates pixels are RRR, GGG, BBB planar.private booleanThe orientation information in some NRRD files cannot be applied to MIPAV without dimension reordering.private float[]DOCUMENT ME!private booleanIf true, data is a specialized form of 4-color with red, green, blue, and alpha, in that order.private booleanTrue for RAS.private static final intA scanner-based right-handed coordinate frame, used in ACR/NEMA 2.0.private static final intLike SCANNER_XYZ, but with time along the fourth axis.private intDOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private intNumber of bytes to skipprivate intNumber of lines to skipprivate floatDOCUMENT ME!private intRAS, LAS, LPS, RAST, LAST, LPST, SCANNER_XYZ, SCANNER_XYZ_TIME, THREED_RIGHT_HANDED, THREED_LEFT_HANDED, THREED_RIGHT_HANDED_TIME, or THREED_LEFT_HANDED_TIMEprivate double[][]Second index of spaceDirections specifies row of matrix to set.private double[]Used to set origin values.private StringDOCUMENT ME!private double[]Resolutions values for nrrd axesprivate int[]DOCUMENT ME!private int[]DOCUMENT ME!private intDOCUMENT ME!private double[]Used to obtain MIPAV sliceThickness valueprivate static final intAny left-handed three-dimensional space.private static final intLike THREEE_LEFT_HANDED, but with time along the fourth axis.private static final intAny right-handed three-dimensional space.private static final intLike THREED_RIGHT_HANDED, but with time along the fourth axis.private static final intDOCUMENT ME!private floatVersion of the NRRD file format being used.private static final intversion number of NRRD for writingFields 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 TypeMethodDescriptionvoidfinalize()Prepares this class for cleanup.private int[]Return the 3 axis orientation codes that correspond to the closest standard anatomical orientation of the (i,j,k) axes.Returns the FileInfoNRRD read from the file.private intgetOffset(FileInfoNRRD fileInfo) Helper method to calculate the offset for getting only the middle NRRD image slice from the 3D file.booleanreadHeader(String imageFileName, String fileDir) Reads the NRRD header and stores the information in fileInfo.readImage(boolean one, boolean doHeader) Reads a NRRD image file by reading the header then making a FileRaw to read the image for all filenames in the file list.private StringreadLine()Reads lines of the file and strips comments indicated by the # symbol until a nonnull String results or the end of the file is reached or a blank line containing end of header with zero characters is reached.voidsetFileInfo(FileInfoNRRD fileInfo) private voidsetFileInfo(FileInfoNRRD fileInfo, ModelImage image) DOCUMENT ME!private voidupdateorigins(FileInfoBase[] fileInfo) Updates the start locations.private booleanwriteHeader(ModelImage image, String fhName, String fDir, int beginSlice, int endSlice, int beginTime, int endTime) write NRRD headerprivate voidwriteHeader3DTo2D(ModelImage img, String headerName, String headerDir, FileWriteOptions options) Method to save off the header from a 3D image into 2D header files sequentially named (similar to the method in FileRaw).private voidwriteHeader4DTo3D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) This method is used when saving a 4D image in an array of 3D files.voidwriteImage(ModelImage image, FileWriteOptions options) Writes a NRRD 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
-
UNKNOWN
private static final int UNKNOWNDOCUMENT ME!- See Also:
-
LPS
private static final int LPSA patient-based right-handed coordinate frame, with ordered basis vectors pointing towards left, posterior, and superior, respectively. Used in DICOM.- See Also:
-
LPST
private static final int LPSTLike LPS, but with time along the fourth axis.- See Also:
-
SCANNER_XYZ
private static final int SCANNER_XYZA scanner-based right-handed coordinate frame, used in ACR/NEMA 2.0. If a patient lies parallel to the ground, face-up on the table, with their feet-to-head direction same as the front-to-back direction of the imaging equipment, the axes of this scanner-based coordinate frame and the (patient-based) left-posterior-superior frame coincide.- See Also:
-
SCANNER_XYZ_TIME
private static final int SCANNER_XYZ_TIMELike SCANNER_XYZ, but with time along the fourth axis.- See Also:
-
THREED_RIGHT_HANDED
private static final int THREED_RIGHT_HANDEDAny right-handed three-dimensional space.- See Also:
-
THREED_LEFT_HANDED
private static final int THREED_LEFT_HANDEDAny left-handed three-dimensional space.- See Also:
-
THREED_RIGHT_HANDED_TIME
private static final int THREED_RIGHT_HANDED_TIMELike THREED_RIGHT_HANDED, but with time along the fourth axis.- See Also:
-
THREED_LEFT_HANDED_TIME
private static final int THREED_LEFT_HANDED_TIMELike THREEE_LEFT_HANDED, but with time along the fourth axis.- See Also:
-
NONE
private static final int NONECentering information for this axis is either meaningless or unknown. This applies to any non-spatial axis.- See Also:
-
CELL
private static final int CELLThe location of the sample is located in the interior of the grid element.- See Also:
-
NODE
private static final int NODEThe location of the sample is at the boundary between grid elements.- See Also:
-
apInvert
private boolean apInvertTrue for RAS and LAS, false for LPS. If true, change sign on origin[1] and row[1] of matrix. -
autoSequence
private boolean autoSequenceTrue if data file:[ ] encountered If true, autosequence using integer format specification varied according to , , and . -
axisMaxs
private double[] axisMaxsMaximum axis value. centers[i], axisMins[i], axisMaxs[i], and nrrdSizes[i] are used to calculate resols[i] and origin[i] if spacings[i] not available. -
axisMins
private double[] axisMinsMinimum axis value. centers[i], axisMins[i], axisMaxs[i], and nrrdSizes[i] are used to calculate resols[i] and origin[i] if spacings[i] not available. -
axisOrientation
private int[] axisOrientationFor each axis R2L, L2R, A2P, P2A, I2S, or S2I -
baseAfterNumber
In autosequencing number between a capital D and the last period used in generating filenames. The capital D must come after the percentage sign. -
baseBeforeNumber
In autosequencing number before percentage sign and period used in generating start of autosequenced filename. -
baseNumber
private boolean baseNumberUsed if autosequencing. If true, increment file base. If false, increment file extension. True if period follows a capital D. The capital D must follow a percentage sign. -
centers
private int[] centersMay remain null or may be created as NONE, CELL, or NODE. -
dwmriGradient
"modality:=DWMRI" : This key/value pair explicitly indicates that the image is a diffusion-weighted MRI scan, and it implies that all of the following key/value pairs are also set in the header: "DWMRI_b-value:=b " : This key/value pair gives the (scalar) diffusion-weighting value, in units of s/mm^2. Example: "DWMRI_b-value:=1000". The effective magnitude of diffusion-weighting for each DWI is determined with some simple calculations based on the individual per-DWI gradient directions or B-matrices. For every index position NNNN along the DWI axis (whichever is the non-spatial axis identified by the "list" or "vector" kind field), either "DWMRI_gradient_NNNN:=x y z " or "DWMRI_B-matrix_NNNN:=xx xy xz yy yz zz " must be given (except if "DWMRI_NEX_NNNN:= M " is used). -
dwmriNex
"DWMRI_NEX_NNNN:=M " means that the information provided for image NNNN (either gradient or B-matrix) is the same as for image NNNN+1, NNNN+2, up to and including NNNN+M-1. -
endianess
private boolean endianessDOCUMENT ME! -
ext
DOCUMENT ME! -
file
DOCUMENT ME! -
fileDir
DOCUMENT ME! -
fileInfo
DOCUMENT ME! -
fileInfoSub
DOCUMENT ME! -
fileLength
private long fileLengthDOCUMENT ME! -
fileName
DOCUMENT ME! -
fileNameSequence
private boolean fileNameSequenceDOCUMENT ME! -
fileNameSet
DOCUMENT ME! -
fileNumber
private int fileNumberDOCUMENT ME! -
finishBlank
private int[] finishBlankDOCUMENT ME! -
finishQuote
private int[] finishQuoteDOCUMENT ME! -
foundEOF
private boolean foundEOFDOCUMENT ME! -
foundEOHeader
private boolean foundEOHeaderDOCUMENT ME! -
gunzip
private boolean gunzipIf true, data has gzip compression. -
image
DOCUMENT ME! -
imgExtents
private int[] imgExtentsDOCUMENT ME! -
kindsString
Kind of information represented by the samples along each axis. -
matrix
DOCUMENT ME! -
measurementFrame
private double[][] measurementFrameThe measurement frame is a basic (per-array) field specification (not per-axis), which identifies a spaceDim-by-spaceDim matrix, where spaceDim is the dimension of the word space (implied by space or given by space dimension). The matrix transforms (a column vector of) coordinates in the measurement frame to corrdinates in world space. vector[i] gives column i of the measurement frame matrix. Just as the space directions field gives, one column at a time, the mapping from image space to world space coordinates, the measurement frame gives the mapping measurement frame to world space coordinates, also one column at a time. -
mipavDataType
private int mipavDataTypeDOCUMENT ME! -
mipavDimensions
private int mipavDimensionsDOCUMENT ME! -
mipavLabels
MIPAV axis names such as X, Y, or Z -
mipavUnits
private int[] mipavUnitsDOCUMENT ME! -
nrrdDataType
private int nrrdDataTypeDoes not tell if color or black and white. -
nrrdDimensions
private int nrrdDimensionsMay not be the same as MIPAV dimensions because in nrrd color is a dimension. -
nrrdLabels
nrrd axis names such as X, Y, or Z -
nrrdSizes
private int[] nrrdSizesThe number of samples along each nrrd axis -
nrrdSpaceUnits
DOCUMENT ME! -
nrrdUnits
Units of measurement of nrrd axis -
numColors
private int numColorsDOCUMENT ME! -
numSpaceKinds
private int numSpaceKindsNumber of nrrd dimensions for which the kinds string equals "SPACE". -
numThicknesses
private int numThicknessesNumber of axes for which thicknesses values found -
offset1
private long offset1DOCUMENT ME! -
oneFileStorage
private boolean oneFileStorageTrue for .nrrd file with header and data in the same file. False for .nhdr header files with the data in one or more other files. -
origin
private float[] originDOCUMENT ME! -
paddingNumber
private int paddingNumberIn autosequencing if the sequence number length is less than the padding number, zeroes are added to the front of the sequence number until the sequence number length equals the padding number. -
planarConfig
private int planarConfig0 indicates pixels are RGB, RGB chunky 1 indicates pixels are RRR, GGG, BBB planar. -
reorder
private boolean reorderThe orientation information in some NRRD files cannot be applied to MIPAV without dimension reordering. This applies to 2 of my 15 example NRRD files. In Dwi-D.nhdr 4 dimensions are specified with the dimensions from 0 to 3 having sizes of 13, 29, 30, and 31. Right-anterior-superior space is specified, but the first axis contains diffusion values and the last 3 axes are the x, y, and z coordinates, so the right-anterior-space applies to the last 3 dimensions, whereas MIPAV would expect the first 3 dimensions to be involved. In gk2-rcc-mask2.nhdr 4 dimensions are specified with the dimensions from 0 to 3 having sizes of 7, 148, 190, and 160. Left-posterior-space is specified, but the first axis contains diffusion values and the last 3 axes are x, y, and z coordinates, so again the space applies to the last 3 dimensions rather than MIPAV's first 3 dimensions. In these cases reorder the data so that the first axis becomes the last axis. -
resols
private float[] resolsDOCUMENT ME! -
RGBAOrder
private boolean RGBAOrderIf true, data is a specialized form of 4-color with red, green, blue, and alpha, in that order. -
rlInvert
private boolean rlInvertTrue for RAS. False for LAS and LPS. If true, change sign on origin[0] and first row of matrix. -
sequenceFinish
private int sequenceFinishDOCUMENT ME! -
sequenceStart
private int sequenceStartDOCUMENT ME! -
sequenceStep
private int sequenceStepDOCUMENT ME! -
skippedBytes
private int skippedBytesNumber of bytes to skip -
skippedLines
private int skippedLinesNumber of lines to skip -
sliceThickness
private float sliceThicknessDOCUMENT ME! -
space
private int spaceRAS, LAS, LPS, RAST, LAST, LPST, SCANNER_XYZ, SCANNER_XYZ_TIME, THREED_RIGHT_HANDED, THREED_LEFT_HANDED, THREED_RIGHT_HANDED_TIME, or THREED_LEFT_HANDED_TIME -
spaceDirections
private double[][] spaceDirectionsSecond index of spaceDirections specifies row of matrix to set. -
spaceOrigin
private double[] spaceOriginUsed to set origin values. -
spaceUnitsString
DOCUMENT ME! -
spacings
private double[] spacingsResolutions values for nrrd axes -
startBlank
private int[] startBlankDOCUMENT ME! -
startQuote
private int[] startQuoteDOCUMENT ME! -
subdim
private int subdimDOCUMENT ME! -
thicknesses
private double[] thicknessesUsed to obtain MIPAV sliceThickness value -
versionNumber
private float versionNumberVersion of the NRRD file format being used. -
oneFile
private boolean oneFileIf true, header and data both stored in .nrrd file. If false, header stored in filename.nhdr and data stored in filename.raw. -
writeVersionNumber
private static final int writeVersionNumberversion number of NRRD for writing- See Also:
-
-
Constructor Details
-
FileNRRD
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 FileInfoNRRD read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
readHeader
Reads the NRRD 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 NRRD 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.doHeader-- Returns:
- The image.
- Throws:
IOException- if there is an error reading the fileOutOfMemoryError- See Also:
-
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:
- codes
-
getOffset
Helper method to calculate the offset for getting only the middle NRRD image slice from the 3D file.- Parameters:
fileInfo- File info.- Returns:
- offset
-
readLine
Reads lines of the file and strips comments indicated by the # symbol until a nonnull String results or the end of the file is reached or a blank line containing end of header with zero characters is reached.- Returns:
- the line read in
- Throws:
IOException- if there is an error reading the file
-
setFileInfo
- Parameters:
fileInfo-
-
setFileInfo
DOCUMENT ME!- Parameters:
fileInfo- -- a NRRD file Info that has already been readimage- -- a ModelImage that the fileInfo needs to be attached to
-
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!
-
writeHeader
private boolean writeHeader(ModelImage image, String fhName, String fDir, int beginSlice, int endSlice, int beginTime, int endTime) throws IOException write NRRD header- Returns:
- Throws:
IOException
-
writeImage
Writes a NRRD format type image.- Parameters:
image- Image model of data to write.options- FileWriteOptions- Throws:
IOException- if there is an error writing the file
-
writeHeader3DTo2D
private void writeHeader3DTo2D(ModelImage img, String headerName, String headerDir, FileWriteOptions options) throws IOException Method to save off the header from a 3D image into 2D header files sequentially named (similar to the method in FileRaw).- Parameters:
img- Image to be savedheaderName- Name of fileheaderDir- Directory for fileoptions- File write options (contains # of digits and start #)- Throws:
IOException- DOCUMENT ME!
-
writeHeader4DTo3D
private void writeHeader4DTo3D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) throws IOException This method is used when saving a 4D image in an array of 3D files. The file name has numbers appended to correctly order the images.- Parameters:
image- the image dataset to be savedfileName- the file namefileDir- the file directoryoptions- file options indicate how to save the image- Throws:
IOException- DOCUMENT ME!
-