Class FileAnalyze
In SPM the signed byte datatype was added with DT_BYTE = 130. MIPAV ANALYZE uses UNSIGNED_SHORT = 6 while SPM uses DT_UNSIGNED_SHORT = 132. The SPM standard also provides for an unsigned int = 136, but MIPAV does not used the unsigned int data type. Note that in SPM while DATA = datatype * 256 for swapped bytes, only datatype and not DATA is written to the file. The most obvious way to test for whether a file is Mayo or SPM would be to see if location 112 is a funused1 = 0 or a nonzero scale factor, but this is complicated by the MIPAV hacking at 112 to store the x-origin location as a float. Asking the users what variant there analyze file is would probably cause massive confusion, so it is probably best just to default to the hacked 7.5 code here unless a pressing need arises.
- Version:
- 0.1 Oct 14, 1997
- Author:
- Matthew J. McAuliffe, Ph.D.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]Storage buffer for the header.static final String[]The extensions of ANALYZE file.private static final intThe extent size of the ANALYZE file.private StringFile directory of the image.private FileReference to the header file (*.hdr).private FileInfoAnalyzeReference to the file info. for an Analyze headerprivate StringFile name of the image.static final intThe size of the header, always 348 for Analyze images.private intHeader size for an Analyze image is 348.private ModelImageThe image read in from the file.private floatVoxel offset tag used to read in the image.private booleanIf true, zero funused fieldsFields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE -
Constructor Summary
ConstructorsConstructorDescriptionFileAnalyze(String[] fileNames) Creates a new FileAnalyze object.FileAnalyze(String fName, String fDir) Constructs new file object. -
Method Summary
Modifier and TypeMethodDescriptionvoidabsoluteValue(ModelImage image) Take the absolute value of image.voidfinalize()Prepares this class for cleanup.voidflipTopBottom(float[] buffer, FileInfoAnalyze fileInfo) Flips image.static final voidflipTopBottom(ModelImage image) Flips image.static String[]getCompleteFileNameList(String absolutePath) Returns the complete list of file names according to given file name.Returns the FileInfoAnalyze read from the file.Returns the header file.static StringgetHeaderFile(String[] fileNames) Returns the header file (ends in .hdr) as a string.String[]Returns the image file list.static String[]getImageFiles(String[] fileNames) Returns the image file list.private intgetOffset(FileInfoAnalyze fileInfo) Helper method to calculate the offset for getting only the middle analyze image slice from the 3D file.static intisAnalyzeOrSPM(String absolutePath) Determines whether this file is ANALYZE file or not based on three fields of the header file: sizeof_hdr, extent and regular.static booleanisHeaderFile(String absolutePath) Return true if the file specified by absolutePath is header file of ANALYZE.static booleanisImageFile(String absolutePath) Return true if the file specified by absolutePath is image file of ANALYZE.booleanreadHeader(String imageFileName, String fileDir) Reads the analyze header and stores the information in fileInfo.readImage(boolean one) Reads an analyze 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 an analyze image file by reading the header then making a FileRaw to read the file.voidreOrgInfo(ModelImage image, FileInfoAnalyze fileInfo) Takes the image and sets it to analyze defaults, using the specified info.voidsetZerofunused(boolean zerofunused) private voidupdateStartLocations(FileInfoBase[] fileInfo) Updates the start locations.private voidupdateUnitsOfMeasure(FileInfoAnalyze fileInfo, ModelImage image) Updates the units of Measure in the file info based on the voxUnits from an Analyze Header.private booleanwriteHeader(ModelImage image, int nImagesSaved, int nTimeSaved, String fileName, String fileDir) Writes an Analyze header to a separate file.private voidwriteHeader3DTo2D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) This method is used when saving a 3D image in an array of 2D files.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 an analyze 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
-
EXTENSIONS
The extensions of ANALYZE file. -
HEADER_SIZE
public static final int HEADER_SIZEThe size of the header, always 348 for Analyze images.- See Also:
-
EXTENTS
private static final int EXTENTSThe extent size of the ANALYZE file.- See Also:
-
bufferImageHeader
private byte[] bufferImageHeaderStorage buffer for the header. -
fileDir
File directory of the image. -
fileHeader
Reference to the header file (*.hdr). -
fileInfo
Reference to the file info. for an Analyze header -
fileName
File name of the image. -
headerSize
private int headerSizeHeader size for an Analyze image is 348. -
image
The image read in from the file. -
vox_offset
private float vox_offsetVoxel offset tag used to read in the image. -
zerofunused
private boolean zerofunusedIf true, zero funused fields
-
-
Constructor Details
-
FileAnalyze
Creates a new FileAnalyze object.- Parameters:
fileNames- DOCUMENT ME!
-
FileAnalyze
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. -
setZerofunused
public void setZerofunused(boolean zerofunused) - Parameters:
zerofunused-
-
flipTopBottom
Flips image. Analyze stores its data "upside down".- Parameters:
image- Image to flip.- Throws:
IOException- DOCUMENT ME!
-
getCompleteFileNameList
Returns the complete list of file names according to given file name.- Parameters:
absolutePath- one file name of ANALYZE.- Returns:
- the complete list of file names.
-
getHeaderFile
Returns the header file (ends in .hdr) as a string.- Parameters:
fileNames- DOCUMENT ME!- Returns:
- The header file (ends in .hdr)
-
getImageFiles
Returns the image file list.- Parameters:
fileNames- DOCUMENT ME!- Returns:
- the image file list.
-
isAnalyzeOrSPM
Determines whether this file is ANALYZE file or not based on three fields of the header file: sizeof_hdr, extent and regular. Note that all Mayo Analyze 7.5 and all SPM99 variants will pass this test. SPM2 variants with a regular header size of 348 will also pass. Only SPM2 files with an extended header > 348 in size will fail.- Parameters:
absolutePath- the file name.- Returns:
- FileUtility.ANALYZE, FileUtility.SPM, or FileUtility.UNDEFINED
- Throws:
FileNotFoundException- thrown when the file can't be found.IOException- thrown when the I/O error happens.
-
isHeaderFile
Return true if the file specified by absolutePath is header file of ANALYZE.- Parameters:
absolutePath- the file name including path information.- Returns:
- true if the specified file is header file.
-
isImageFile
Return true if the file specified by absolutePath is image file of ANALYZE.- Parameters:
absolutePath- the file name including path information.- Returns:
- true if the specified file is image file.
-
absoluteValue
Take the absolute value of image.- Parameters:
image- Image to take absolute value of.- Throws:
IOException- DOCUMENT ME!
-
flipTopBottom
Flips image. Analyze stores its data "upside down".- Parameters:
buffer- Buffer holding image to flip.fileInfo- File info structure for image to flip.- Throws:
IOException- DOCUMENT ME!
-
getFileInfo
Returns the FileInfoAnalyze read from the file.- Returns:
- File info read from file, or null if it has not been read.
-
getHeaderFile
Returns the header file.- Returns:
- DOCUMENT ME!
-
getImageFiles
Returns the image file list.- Returns:
- the image file list.
-
readHeader
Reads the analyze 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 an analyze 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 an analyze 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:
-
reOrgInfo
Takes the image and sets it to analyze defaults, using the specified info.- Parameters:
image- Image to set to analyze defaults.fileInfo- File info structure to change.
-
writeImage
Writes an analyze format type image.- Parameters:
image- Image model of data to write.- Throws:
IOException- if there is an error writing the file- See Also:
-
getOffset
Helper method to calculate the offset for getting only the middle analyze image slice from the 3D file.- Parameters:
fileInfo- File info.- Returns:
- offset
-
updateStartLocations
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!
-
updateUnitsOfMeasure
Updates the units of Measure in the file info based on the voxUnits from an Analyze Header.- Parameters:
fileInfo- -- an Analyze file Info that has already been readimage- -- a ModelImage that the fileInfo needs to be attached to
-
writeHeader
private boolean writeHeader(ModelImage image, int nImagesSaved, int nTimeSaved, String fileName, String fileDir) throws IOException Writes an Analyze header to a separate file.- Parameters:
image- Image model of data to write.fileName- File name.fileDir- File directory.- Returns:
- Flag to confirm a successful read.
- Throws:
IOException- if there is an error- See Also:
-
writeHeader3DTo2D
private void writeHeader3DTo2D(ModelImage image, String fileName, String fileDir, FileWriteOptions options) throws IOException This method is used when saving a 3D image in an array of 2D 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!
-
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!
-