Package gov.nih.mipav.model.file
Class FileUtility
java.lang.Object
gov.nih.mipav.model.file.FileUtility
Constants and static methods which relate to file input, output or processing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAFNI file type. extension: .head, .brikstatic final intAnalyze format (Mayo). extension: .img, .hdrstatic final intMultiple files of type analyze.static final intAVI file type.static final intExtension: .hdr for header, .bfloat for datastatic final intUsed by the Bio-Rad Pic format. extension: .pic invalid input: '&'invalid input: '&' fileID(54L)==12345static final intextension: .bmp.static final intBmp multifilestatic final intBruker file format.static final intCheshire file type (a kind of Analyze). extension: .imc Can also have .img extensionstatic final intCheshire overlay file type.static final intUsed by FreeSurfer software. extension: -.info or -.info~ for header file -.nnn for slice data file where nnn is the slice numberstatic final intextension: .cur.static final intZeiss ZISRAW (CZI) file format extension .czistatic final intextension: .dib.static final intDigital Imaging and COmmunications in Medicine file type.static final intGatan's Digital Micrograph version 3 file format. extension: .dm3static final intIll defined file type.private static final String[]static final intFITS file type. extension: .fitsstatic final intGE Genesis 5X and LX. extension: .sigstatic final intMultiple files of type GE_GENESISstatic final intGE Signa 4.x.static final intMultiple files of type GE_SIGNA4Xstatic final intextension: .gif.static final intextension: .ico.static final intImage Cytometry Standard. extension: .ics, .idsstatic final intInterfile file format used in Nuclear Medicine. extension: .hdrstatic final intMultiple files of type INTERFILEstatic final intJava Image Manangement Interface file type.static final intstatic final intextension: .jpeg, .jpg.static final intstatic final intstatic final intextension .jsonstatic final intDo not confuse with Leica image file format .lifstatic final intUsed by the Zeiss LSM 510 Dataserver. extension: .lsmstatic final intUsed by the Zeiss LSM 510 Dataserver.static final intSiemens MAGNETOM VISION. extension: .imastatic final intMultiple files of type MAGNETOM_VISIONstatic final intBenes Trus special file type. extension: .mapstatic final intextension .matstatic final intextension: .bin.static final intMetaimage files are either separate .mhd header and .raw image data files or combined .mha header and image data filestatic final intMGH/MGZ volume format.static final intMicro CT format for small animal imaging. extension: .log, .ctstatic final intMINC file type.static final intMINC 2.0 (HDF5)static final intMultiple files of type MINC.static final intNot presently implemented.static final intextension: .mrc.static final intNIFTI format. extension: .img, .hdr, .niistatic final intNIFTI multi-file format.static final intNearly raw raster data.static final intNearly raw raster data.static final intWashington University OSM dataset structure. extension: .wustatic final intextension: "par","parv2","rec","frec".static final intextension: "par","parv2","rec","frec".static final intextension: .pcx.static final intPortable Gray Map extension .pgmstatic final intextension: .pic.static final intextension: .pict.static final intextension: .png.static final intPortable Pixmap Utilities .ppmstatic final intextension: .psd.static final intQuicktime file type. extension: .mov, .qtstatic final intRAW image data, no header. extension: .rawstatic final intRAW MULTIFLE image data, no header.static final intExtension: .hdr for header, .img for datastatic final intSPAR file format for use with PARREC imagesstatic final intSPM file format.static final intMetaMorph Stack (STK) file type. extension: .stkstatic final intMIPAV Surface XML file format. extension: .xmlstatic final intMIPAV Surface XML file format. extension: .xmlstatic final intAperio TIFF based .svsstatic final intextension: .tga.static final intTIFF file; tagged header. extension: .tif, .tiffstatic final intMultiple files of TIFF images.static final intOptical coherence tomography. extension: .tmgstatic final intExtension: .trk, TrackVis track datastatic final intUndefined file type.static final intVista file extension .vstatic final intVOI file, used to read VOIs. extension: .voistatic final intextension: .xbm.static final intMIPAV XML file format. mipav xml image format. extension: .xmlstatic final intMIPAV XML file format.static final intextension: .xpm.static final intZeiss ZVI has extension .zvi -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final String[]getCORFileList(String fileDir, String fileName, boolean quiet) Only for FreeSurfer COR volume files Looks in the image directory and returns all images with the same root up to the hyphen, sorted in lexicographical order.static final StringOnly used for COR volume files with hyphen in name Breaks the filename into basename and suffix, then returns the suffix.static final StringgetExtension(String absolutePath) Returns the extension of the file name (including the dot), if file name does not have extension, then return empty string.static final StringgetFileDirectory(String fileName) Returns the path information from the file name with the path information.static final intgetFileIndex(String fName) Trims off the file extension and file name, but leaves the file index.static final String[]getFileList(String fileDir, String fileName, boolean quiet) Looks in the image directory and returns all images with the same suffix asfileName, sorted in lexicographical order.static final StringgetFileName(String absolutePath) Returns the file name without path information from file name with the path information.getFileNameList(FileInfoBase[] fileInfoList) Gets the file name list from which this ModelImage is opened.getFileNameList(ModelImage image) Gets the file name list from which this ModelImage is opened.static final intgetFileType(String fileName, String fileDir, boolean quiet) Sets the FileBase.static final intgetFileType(String fileName, String fileDir, boolean doWrite, boolean quiet, boolean[] zerofunused) Sets the FileBase.static intReturns the file type associated with a string.static StringgetFileTypeStr(int m) Return the string associated with a file type.static final intisAnalyzeOrSPM(String fileName, String fileDir, boolean quiet) Tests if the unknown file is of type Analyze.static final intTests if the unknown file is of type Dicom.static final intisDicom_ver2(String fileName, String fileDir, boolean quiet) tests if unknown file is of type 2.0 dicomstatic final intisGESigna4X(String fileName, String fileDir, boolean quiet) Tests if the unknown file is of type GE Signa 4X type.static final intisGESigna5X(String fileName, String fileDir, boolean quiet) Tests if the unknown file is of type GE Signa 5X type.static final intisInterfile(String fileName, String fileDir, boolean quiet) Tests if the unknown file is of type Interfile.static final intisMagnetomVision(String fileName, String fileDir, boolean quiet) Tests if the unknown file is of type Siemens Magnetom Vision.static final intTests if the unknown file is of type Minc.static final intDetermines whether the file on disk is of type MINC 2.0static final intTests if the unknown file is of type Nifti.static final intTests if the unknown file is of type SPM.static final StringstripExtension(String fileName) Helper method to strip the image name of the extension, so when we save we don't have double extensions (like genormcor.img.tif).static final StringTrims the numbers or file extension from COR file names.static final StringtrimNumbersAndSpecial(String fName) Trims the numbers and special character from the file name.
-
Field Details
-
ERROR
public static final int ERRORIll defined file type.- See Also:
-
UNDEFINED
public static final int UNDEFINEDUndefined file type.- See Also:
-
AFNI
public static final int AFNIAFNI file type. extension: .head, .brik- See Also:
-
ANALYZE
public static final int ANALYZEAnalyze format (Mayo). extension: .img, .hdr- See Also:
-
ANALYZE_MULTIFILE
public static final int ANALYZE_MULTIFILEMultiple files of type analyze.- See Also:
-
AVI
public static final int AVIAVI file type. Windows Media. extension: .avi- See Also:
-
BIORAD
public static final int BIORADUsed by the Bio-Rad Pic format. extension: .pic invalid input: '&'invalid input: '&' fileID(54L)==12345- See Also:
-
BMP
public static final int BMPextension: .bmp.- See Also:
-
BMP_MULTIFILE
public static final int BMP_MULTIFILEBmp multifile- See Also:
-
BRUKER
public static final int BRUKERBruker file format. Reads a BRUKER file by first reading in the d3proc header file, second the reco header file, third the acqp file int the same directory or up one or two two parent directories, and finally the 2dseq binary file.- See Also:
-
CHESHIRE
public static final int CHESHIRECheshire file type (a kind of Analyze). extension: .imc Can also have .img extension- See Also:
-
CHESHIRE_OVERLAY
public static final int CHESHIRE_OVERLAYCheshire overlay file type. Contains VOIs. extension: .oly- See Also:
-
COR
public static final int CORUsed by FreeSurfer software. extension: -.info or -.info~ for header file -.nnn for slice data file where nnn is the slice number- See Also:
-
CUR
public static final int CURextension: .cur.- See Also:
-
DIB
public static final int DIBextension: .dib.- See Also:
-
DICOM
public static final int DICOMDigital Imaging and COmmunications in Medicine file type. Fully implemented versions 2 invalid input: '&' 3. extension: .dcm- See Also:
-
DM3
public static final int DM3Gatan's Digital Micrograph version 3 file format. extension: .dm3- See Also:
-
FITS
public static final int FITSFITS file type. extension: .fits- See Also:
-
GE_GENESIS
public static final int GE_GENESISGE Genesis 5X and LX. extension: .sig- See Also:
-
GE_GENESIS_MULTIFILE
public static final int GE_GENESIS_MULTIFILEMultiple files of type GE_GENESIS- See Also:
-
GE_SIGNA4X
public static final int GE_SIGNA4XGE Signa 4.x.- See Also:
-
GE_SIGNA4X_MULTIFILE
public static final int GE_SIGNA4X_MULTIFILEMultiple files of type GE_SIGNA4X- See Also:
-
GIF
public static final int GIFextension: .gif.- See Also:
-
ICO
public static final int ICOextension: .ico.- See Also:
-
ICS
public static final int ICSImage Cytometry Standard. extension: .ics, .ids- See Also:
-
INTERFILE
public static final int INTERFILEInterfile file format used in Nuclear Medicine. extension: .hdr- See Also:
-
INTERFILE_MULTIFILE
public static final int INTERFILE_MULTIFILEMultiple files of type INTERFILE- See Also:
-
JIMI
public static final int JIMIJava Image Manangement Interface file type.- See Also:
-
JPEG
public static final int JPEGextension: .jpeg, .jpg.- See Also:
-
LSM
public static final int LSMUsed by the Zeiss LSM 510 Dataserver. extension: .lsm- See Also:
-
LSM_MULTIFILE
public static final int LSM_MULTIFILEUsed by the Zeiss LSM 510 Dataserver.- See Also:
-
MAGNETOM_VISION
public static final int MAGNETOM_VISIONSiemens MAGNETOM VISION. extension: .ima- See Also:
-
MAGNETOM_VISION_MULTIFILE
public static final int MAGNETOM_VISION_MULTIFILEMultiple files of type MAGNETOM_VISION- See Also:
-
MAP
public static final int MAPBenes Trus special file type. extension: .map- See Also:
-
MEDIVISION
public static final int MEDIVISIONextension: .bin.- See Also:
-
MGH
public static final int MGHMGH/MGZ volume format.- See Also:
-
MICRO_CAT
public static final int MICRO_CATMicro CT format for small animal imaging. extension: .log, .ct- See Also:
-
MINC
public static final int MINCMINC file type. MINC is a medical imaging oriented extension of the NetCDF file format. NetCDF stands for 'Network Common Data Form'. extension: .mnc- See Also:
-
MINC_MULTIFILE
public static final int MINC_MULTIFILEMultiple files of type MINC.- See Also:
-
MIPAV
public static final int MIPAVNot presently implemented.- See Also:
-
MRC
public static final int MRCextension: .mrc.- See Also:
-
NIFTI
public static final int NIFTINIFTI format. extension: .img, .hdr, .nii- See Also:
-
NIFTI_MULTIFILE
public static final int NIFTI_MULTIFILENIFTI multi-file format.- See Also:
-
NRRD
public static final int NRRDNearly raw raster data.- See Also:
-
NRRD_MULTIFILE
public static final int NRRD_MULTIFILENearly raw raster data.- See Also:
-
OSM
public static final int OSMWashington University OSM dataset structure. extension: .wu- See Also:
-
PCX
public static final int PCXextension: .pcx.- See Also:
-
PIC
public static final int PICextension: .pic.- See Also:
-
PICT
public static final int PICTextension: .pict.- See Also:
-
PNG
public static final int PNGextension: .png.- See Also:
-
PSD
public static final int PSDextension: .psd.- See Also:
-
QT
public static final int QTQuicktime file type. extension: .mov, .qt- See Also:
-
RAW
public static final int RAWRAW image data, no header. extension: .raw- See Also:
-
RAW_MULTIFILE
public static final int RAW_MULTIFILERAW MULTIFLE image data, no header.- See Also:
-
SPM
public static final int SPMSPM file format. SPM99 and SPM2 are slight variants of analyze with the same .img, .hdr file extensions. The user could also change the extension .img to .spm to indicate SPM. The header extension would remain .hdr- See Also:
-
STK
public static final int STKMetaMorph Stack (STK) file type. extension: .stk- See Also:
-
SURFACE_XML
public static final int SURFACE_XMLMIPAV Surface XML file format. extension: .xml- See Also:
-
TGA
public static final int TGAextension: .tga.- See Also:
-
TIFF
public static final int TIFFTIFF file; tagged header. extension: .tif, .tiff- See Also:
-
TIFF_MULTIFILE
public static final int TIFF_MULTIFILEMultiple files of TIFF images.- See Also:
-
TMG
public static final int TMGOptical coherence tomography. extension: .tmg- See Also:
-
VOI_FILE
public static final int VOI_FILEVOI file, used to read VOIs. extension: .voi- See Also:
-
XBM
public static final int XBMextension: .xbm.- See Also:
-
XML
public static final int XMLMIPAV XML file format. mipav xml image format. extension: .xml- See Also:
-
XML_MULTIFILE
public static final int XML_MULTIFILEMIPAV XML file format.- See Also:
-
XPM
public static final int XPMextension: .xpm.- See Also:
-
PARREC
public static final int PARRECextension: "par","parv2","rec","frec".- See Also:
-
PARREC_MULTIFILE
public static final int PARREC_MULTIFILEextension: "par","parv2","rec","frec".- See Also:
-
SPAR
public static final int SPARSPAR file format for use with PARREC images- See Also:
-
SURFACEREF_XML
public static final int SURFACEREF_XMLMIPAV Surface XML file format. extension: .xml- See Also:
-
MINC_HDF
public static final int MINC_HDFMINC 2.0 (HDF5)- See Also:
-
LIFF
public static final int LIFFDo not confuse with Leica image file format .lif- See Also:
-
BFLOAT
public static final int BFLOATExtension: .hdr for header, .bfloat for data- See Also:
-
SIEMENSTEXT
public static final int SIEMENSTEXTExtension: .hdr for header, .img for data- See Also:
-
ZVI
public static final int ZVIZeiss ZVI has extension .zvi- See Also:
-
JP2
public static final int JP2- See Also:
-
MATLAB
public static final int MATLABextension .mat- See Also:
-
VISTA
public static final int VISTAVista file extension .v- See Also:
-
METAIMAGE
public static final int METAIMAGEMetaimage files are either separate .mhd header and .raw image data files or combined .mha header and image data file- See Also:
-
TRACKVIS
public static final int TRACKVISExtension: .trk, TrackVis track data- See Also:
-
CZI
public static final int CZIZeiss ZISRAW (CZI) file format extension .czi- See Also:
-
PGM
public static final int PGMPortable Gray Map extension .pgm- See Also:
-
PPM
public static final int PPMPortable Pixmap Utilities .ppm- See Also:
-
SVS
public static final int SVSAperio TIFF based .svs- See Also:
-
JSON
public static final int JSONextension .json- See Also:
-
JPEG_LS
public static final int JPEG_LS- See Also:
-
JPEG_XL
public static final int JPEG_XL- See Also:
-
fileTypeStr
-
-
Constructor Details
-
FileUtility
public FileUtility()
-
-
Method Details
-
getFileTypeFromStr
Returns the file type associated with a string.- Parameters:
s- String to test- Returns:
- axis orientation
-
getFileTypeStr
Return the string associated with a file type.- Parameters:
m- int representing the file type (see the above static definitions)- Returns:
- String representing the string associated with the file type.
-
getCORFileList
public static final String[] getCORFileList(String fileDir, String fileName, boolean quiet) throws OutOfMemoryError Only for FreeSurfer COR volume files Looks in the image directory and returns all images with the same root up to the hyphen, sorted in lexicographical order. Will set the number of images (nImages) for the calling program.- Parameters:
fileDir- Directory to look for images.fileName- File name of the image.quiet- Whether to avoid displaying errors using the GUI.- Returns:
- An array of the image names to be read in or saved as.
- Throws:
OutOfMemoryError- If there is a problem allocating required memory.
-
getCORSuffixFrom
Only used for COR volume files with hyphen in name Breaks the filename into basename and suffix, then returns the suffix.- Parameters:
fn- The filename.- Returns:
- The suffix or file-extension. For example,
-info
. Note that suffix includes the separator '-'
-
getExtension
Returns the extension of the file name (including the dot), if file name does not have extension, then return empty string.- Parameters:
absolutePath- the file name.- Returns:
- The file's extension.
-
getFileDirectory
Returns the path information from the file name with the path information.- Parameters:
fileName- the file name wiht the path information.- Returns:
- The path information.
-
getFileIndex
Trims off the file extension and file name, but leaves the file index. An index might be 0001, or 140, for example.- Parameters:
fName- String file name to get index- Returns:
- String (index string)
-
getFileList
public static final String[] getFileList(String fileDir, String fileName, boolean quiet) throws OutOfMemoryError Looks in the image directory and returns all images with the same suffix asfileName, sorted in lexicographical order.- Parameters:
fileDir- Directory to look for images.fileName- File name of the image.quiet- Whether to avoid displaying errors using the GUI.- Returns:
- An array of the image names to be read in or saved as.
- Throws:
OutOfMemoryError- If there is a problem allocating required memory.
-
getFileName
Returns the file name without path information from file name with the path information.- Parameters:
absolutePath- the file name with the path information.- Returns:
- The file name without path information.
-
getFileType
Sets the FileBase.(filetype) based on the file extension of the given filename. Also sets file "suffix", if required.- Parameters:
fileName- Filename of the image to read in. Must include the file extension.fileDir- Directory where fileName exists.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
- Filetype from FileBase.
- See Also:
-
getFileType
public static final int getFileType(String fileName, String fileDir, boolean doWrite, boolean quiet, boolean[] zerofunused) Sets the FileBase.(filetype) based on the file extension of the given filename. Also sets file "suffix", if required.- Parameters:
fileName- Filename of the image to read in. Must include the file extension.fileDir- Directory where fileName exists.doWrite- If true about to write a filequiet- Whether to avoid any user interaction (ie, from error popups).zerofunused- If true, zero funused fields in an analyze write- Returns:
- Filetype from FileBase.
- See Also:
-
isAnalyzeOrSPM
public static final int isAnalyzeOrSPM(String fileName, String fileDir, boolean quiet) throws IOException Tests if the unknown file is of type Analyze.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.ANALYZEif the file is a ANALYZE type,FileUtility.SPMif the file is a SPM type, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isDicom
Tests if the unknown file is of type Dicom.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.DICOMif the file is a DICOM file, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isDicom_ver2
public static final int isDicom_ver2(String fileName, String fileDir, boolean quiet) throws IOException tests if unknown file is of type 2.0 dicom- Parameters:
fileName-fileDir-quiet-- Returns:
- Throws:
IOException
-
isGESigna4X
public static final int isGESigna4X(String fileName, String fileDir, boolean quiet) throws IOException Tests if the unknown file is of type GE Signa 4X type.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.GE_SIGNA4Xif the file is a GE MR Signa 4.x file, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isGESigna5X
public static final int isGESigna5X(String fileName, String fileDir, boolean quiet) throws IOException Tests if the unknown file is of type GE Signa 5X type.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.GE_GENESISif the file is a GE MR Signa 5.x file, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isInterfile
public static final int isInterfile(String fileName, String fileDir, boolean quiet) throws IOException Tests if the unknown file is of type Interfile.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.Interfileif the file is a Interfile type, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isMagnetomVision
public static final int isMagnetomVision(String fileName, String fileDir, boolean quiet) throws IOException Tests if the unknown file is of type Siemens Magnetom Vision.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.MAGNETOM_VISIONif the file is a Siemens Magnetom Vision type, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isMinc
Tests if the unknown file is of type Minc.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.MINCif the file is a MINC type, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isMincHDF
Determines whether the file on disk is of type MINC 2.0- Parameters:
fileName- name of the filefileDir- directoryquiet-- Returns:
- whether the file is HDF5 type
-
isNIFTI
Tests if the unknown file is of type Nifti.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.NIFTIif the file is a NIFTI type, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
isSPM
Tests if the unknown file is of type SPM.- Parameters:
fileName- Name of the image file to read.fileDir- Directory of the image file to read.quiet- Whether to avoid any user interaction (ie, from error popups).- Returns:
FileUtility.SPMif the file is a SPM type, andFileUtility.UNDEFINEDotherwise- Throws:
IOException- If there is a problem determining the type of the given file.
-
stripExtension
Helper method to strip the image name of the extension, so when we save we don't have double extensions (like genormcor.img.tif).- Parameters:
fileName- Original name.- Returns:
- Name without extension, or original name if there was no extension.
-
trimCOR
Trims the numbers or file extension from COR file names. Any numbers or.info
or.info~
will be removed from after a hyphen in the given fname.- Parameters:
fName- File name where the last characters are alpha-numerics indicating the image number or .info or .info~- Returns:
- File name without numbers on the end.
-
trimNumbersAndSpecial
Trims the numbers and special character from the file name. Numerics and some special characters[ - _ .are removed from the end of the file.- Parameters:
fName- File name where the last characters are alpha-numerics indicating the image number.- Returns:
- File name without numbers on the end.
-
getFileNameList
Gets the file name list from which this ModelImage is opened.- Parameters:
image- the ModelImage object.- Returns:
- the actual file name list.
-
getFileNameList
Gets the file name list from which this ModelImage is opened.- Parameters:
image- the ModelImage object.- Returns:
- the actual file name list.
-