Class FileDicom
The Hashtable is based upon the default DICOM dictionary which contains all possible standard DICOM tags. It also contains many private tags that are commented out. If the user wishes a specific private tag to be recognized by this program, he or she should edit the dictionary file. The tag will then be displayed as any other standard tag would be displayed. Otherwise, all tags are read in, but if their value representation is unrecognized (only the case with tags not defined in dictionary file) their value is stored as a string. When FileInfoDicom displays the tag information, it shows the name of the tag as private and the value as the string. The string may contain valid data or it may contain junk. There is no way of knowing how to properly read in a private tag without a valid value representation (VR). So if the user wishes to know private tag information, he or she should specify the proper VR in the dictionary file and be sure that their file conforms to that VR.
- Version:
- 1.0 Aug 1, 1999
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate Byte[]private FileDicomSQHolds sequence of files described in DICOMDIR.private booleanstatic final StringThe tag marking the start of the double image data.private intLength of the value field of data element.private intSecond number (DICOM element in a group) in ordered pair of numbers that uniquely identifies a data element.private booleanWhen Dicom image data is 'encapsulated,' it may be in pieces, or 'fragments.' don't know quite why, or if pieces should be kept together.private booleanprivate booleanStores the endianess of the header, used for processing sequence tagsprivate intprivate intprivate FileDicomTagTable[]private int[]The currently known extents of the image, as indicated by the headerprivate StringDirectory of the image file.private FileFile object of the image.private FileInfoDicomMeta data structure in which to save all the DICOM tags.private StringName of the file to be read in.private final intLocation of first element.private booleanHeader loop keeps executing when truestatic final StringThe tag marking the start of the float image data.private intFirst number (DICOM group) in ordered pair of numbers that uniquely identifies a data element.private booleanTrue if the DICOM image header has been read.private booleanprivate booleanprivate final intLocation of 'DICM'.private ModelImageReference to the image read into the application.static final Stringstatic final Stringstatic final StringThe tag marking the start of the image data.private booleanWhether adequate processing of the file has occurred to allowed image to be extracted, this includes getting offset and pixel representation.private booleanprivate booleanprivate booleanprivate booleanprivate int[]private int[]Buffer used when reading in encapsulated JPEG images.private booleanJPEG compression may be lossy or lossless.private intNumber of bytes following this File Meta Element (end of the Value field) up to and including the last File Meta Element of the Group 2 File Meta Information.private StringName of the sequence tag.static final Stringstatic final Stringstatic final Stringstatic final Stringprivate PrivateFileDicomKeyPrivate tag for current publisher nameprivate booleanIf the file is quiet no user-interaction is performed.private FileRawDOCUMENT ME!private booleanprivate int[]static final StringThe tag marking the beginning of a dicom sequence.static final StringThe tag marking the end of a dicom sequence.static final StringThe tag marking the end of an undefined length dicom sequence.static final Stringstatic final Stringstatic final Stringprivate booleanWhether MIPAV should be written to this dicom file as the secondary stamp *private FileDicomTagTableThe tag table for the base FileInfoDicom.static final Stringprivate int[]private final intUndefined element length.private byte[]Value Representation - see FileDicomTagInfo.Fields inherited from class gov.nih.mipav.model.file.FileDicomBase
BIG_ENDIAN, BUFFER_SIZE, byteBuffer, byteBuffer2, byteBuffer4, byteBuffer8, fLength, imageElementLength, imageElementWord, imageGroupWord, imageTagLocation, isDicomRecv, LITTLE_ENDIAN, notDir, numEmbeddedImages, pBarVisible, progressBar, raFile, READ, READ_WRITE, SPECTROSCOPY, tagBuffer, TAMAR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidchangeDicomFileSize(RandomAccessFile raFile, long sizeChange, long pointerLoc, int oldTagElementLength) private intcheckMaxSlice(FileDicomTagTable tagTable, int numSlices, TreeSet<Integer> sliceInt) Helper method for enhanced dicom which finds the maximum slice number in the dataset.voidclose()Closes random access file associated with this object.private StringconvertGroupElement(int groupWord, int elementWord) Converts the integer values of the group word and element word into a string that is the hexadecimal representation of group word and element word, separated by a comma.voiddoEnhanced(boolean doEnhanced, int[] extents) voiddoStampSecondary(boolean stampSecondary) Sets whether MIPAV will edit the DICOM tags of this image with a secondary stamp.private int[]Starts with image tag. goes with OB/OW. image file must be open, file ptr: raFile.private int[]encapsulatedJP2ImageData(int imageType) private int[]private int[]extractLossyJPEGImage(byte[] imageFrag) Brute force removal of 1st fragment of JPEG encoded image.voidfinalize()Prepares this class for cleanup.private ObjectgetByte(int vm, int length, boolean endianess) Reads a length of the data and deposits it into a single Short or an array of Short as needed by the tag's VM.private booleangetColorPallete(FileDicomTagTable tagTable, FileDicomKey palleteKey) Reads a pallete (look-up table) out of the given DICOM key and interprets the data based on the data-size specification tag.private FileDicomSQItemgetDataSet(int itemLength, boolean endianess) Reads a set of DICOM tags from a DICOM sequence item, ending with the data-element end tagFFFE,E00D.final FileDicomSQAccessor that returns the DICOMDIR sequence file info.private ObjectgetDouble(int vm, int length, boolean endianess) Reads a length of the data and deposits it into a single Double or an array of Double as needed by the tag's VM.intintfinal FileInfoBaseAccessor that returns the file info.private ObjectgetFloat(int vm, int length, boolean endianess) Reads a length of the data and deposits it into a single Float or an array of Float as needed by the tag's VM.private ObjectgetInteger(int vm, int length, boolean endianess) Reads a length of the data and deposits it into a single Integer or an array of Integer as needed by the tag's VM.private intgetLength(boolean endianess, byte b1, byte b2, byte b3, byte b4) Reads in four integers, then tests for implicit Value Representation(VR) or explicit VR.private ObjectgetLong(int vm, int length, boolean endianess) Reads a length of the data and deposits it into a single Integer or an array of Integer as needed by the tag's VM.private voidgetNextElement(boolean bigEndian) Increments the location, then reads the elementWord, groupWord, and elementLength.private FileDicomKeygetNextTag(boolean endianess) private FileDicomSQgetSequence(boolean endianess, int seqLength) Gets the sequence in a sequence tag.private ObjectgetShort(int vm, int length, boolean endianess) Reads a length of the data and deposits it into a single Short or an array of Short as needed by the tag's VM.private int[]guessImageLength(int[] extents) Helper method for dicom files that do not specify a valid extentsbooleanisDICOM()Looks for the DICM _tag_ in the File header.booleanDicom version 2: Does not have a preamble in which to search for "DICM" So...the solution will be to search that it has at least a couple of beginning "08" tags However, we do not know if its Little Endian or Big Endian..so need to handle bothfinal booleanisDir()booleanbooleanfinal booleanisQuiet()gets the quiet option on the class.private booleanprocessImageData(int[] extents2, int imageNumber, int imageTagLoc) Processes image data from the defined image tag location.private booleanprocessNextTag(FileDicomTagTable tagTable, FileDicomKey key, boolean endianess, boolean inSequence) private voidprocessSequence(FileDicomTagTable tagTable, FileDicomKey key, String name, boolean endianess) private booleanprocessTransferSyntax(String strValue) private voidprocessUnknownVR(FileDicomTagTable tagTable, String name, FileDicomKey key, int tagVM, String strValue) private FileDicomTagInfoputPrivateTagInfo(FileDicomTagTable tagTable, FileDicomKey key, boolean implicit) booleanreadHeader(boolean loadTagBuffer) Reads in all the tags available in the file and stores them in the Hashtable in FileInfoDicom.voidreadImage(double[] buffer, int imageType, int imageNo) Reads a DICOM image file and stores the data into the given double buffer.voidreadImage(float[] buffer, int imageType, int imageNo) Reads a DICOM image file and stores the data into the given float buffer.voidreadImage(int[] buffer, int imageType, int imageNo) Reads a DICOM image file and stores the data into the given short buffer.voidreadImage(short[] buffer, int imageType, int imageNo) Reads a DICOM image file and stores the data into the given short buffer.voidreadShortToFloatImage(float[] floatBuffer, int imageType, int imageNo) Reads a DICOM image file and stores the data into the given short buffer.private ObjectGets private tags or other tags where the type is unknown; does not change the data, so it may be written out correctly.(package private) Stringprivate voidreplaceTag(RandomAccessFile raFile, FileDicomKey key, FileDicomTag newTag, int oldTagElementLength) newTag is written to raFile to replace old tag of tagElementLengthprivate int[]RLEImageData(int imageType) voidsetEnhanced4D(boolean isEnhanced4D) voidsetEnhancedNumSlices(int enhancedNumSlices) voidsetEnhancedTagTables(int numTables) voidfinal voidsetFileInfo(FileInfoDicom fiDicom) Sets the file info and sets the hasHeaderBeenRead to true.voidsetFileName(File f, FileInfoDicom refInfo) Accessor that sets the file name and allocates new FileInfo, File and RandomAccess file objects based on the new image file based on the new filename and the new directory.final voidsetFileName(String fName, FileInfoDicom refInfo) Accessor that sets the file name and allocates new FileInfo, File and RandomAccess file objects based on the new image file based on the new filename and the old directory.final voidsetFileName(String fName, String fDir, FileInfoDicom refInfo) Accessor that sets the file name and allocates new FileInfo, File and RandomAccess file objects based on the new image file based on the new filename and the new directory.final voidsetQuiet(boolean q) sets the quiet option on the class.private voidstampSecondaryCapture(FileInfoDicom fileInfo) Writing a file to disk likely indicates that it was changed in some way.private int[]voidwriteHeader(RandomAccessFile outputFile, FileInfoDicom fileInfo, boolean saveAsEncapJP2) Writes the tags of the DICOM header.voidwriteImage(ModelImage image, int start, int end, int index, boolean saveAsEncapJP2) Writes a dicom format type image.voidwriteMultiFrameImage(ModelImage image, int startSlice, int endSlice, int startTime, int endTime) Writes a dicom format type image.private voidwriteNextTag(FileDicomTag tag, RandomAccessFile outputFile, int[] lengthReduction) Writes a dicom tag to the provided output file.private voidwriteSequence(RandomAccessFile outputFile, FileInfoDicom.VRtype vr_type, FileDicomSQ sq, boolean endianess) Writes out a sequence tag and its data.voidwriteTags(RandomAccessFile outputFile, FileInfoDicom fileInfo, FileDicomKey[] editKeys, FileDicomTag[] editTags) Writes selected tag values (location specified by editKeys, value specified by editTags), to existing dicom file specified by outputFile.Methods inherited from class gov.nih.mipav.model.file.FileDicomBase
getByte, getDouble, getFileLength, getFilePointer, getFloat, getInt, getLong, getSignedByte, getSignedShort, getString, getStringFromFile, getUInt, getUnsignedShort, initializeFullRead, isHeaderOnlyRead, isProgressBarVisible, loadTagBuffer, locateImageTag, read, seek, setBufferFloat, setBufferInt, setBufferLong, setBufferShort, setBufferString, setHeaderOnlyRead, setProgressBarVisible, setTagBuffer, skipBytes, writeByte, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUnsignedShort
-
Field Details
-
IMAGE_TAG
The tag marking the start of the image data.- See Also:
-
FLOAT_IMAGE_TAG
The tag marking the start of the float image data.- See Also:
-
DOUBLE_IMAGE_TAG
The tag marking the start of the double image data.- See Also:
-
TAMAR_COMPRESSED_PIXEL_DATA
- See Also:
-
SPECTROSCOPY_DATA
- See Also:
-
SEQ_ITEM_BEGIN
The tag marking the beginning of a dicom sequence.- See Also:
-
SEQ_ITEM_END
The tag marking the end of a dicom sequence.- See Also:
-
SEQ_ITEM_UNDEF_END
The tag marking the end of an undefined length dicom sequence.- See Also:
-
PIXEL_MEASURES_SEQUENCE
- See Also:
-
SLICE_THICKNESS
- See Also:
-
PIXEL_SPACING
- See Also:
-
SPACING_BETWEEN_SLICES
- See Also:
-
PLANE_POSITION_SEQUENCE
- See Also:
-
IMAGE_POSITION
- See Also:
-
PLANE_ORIENTATION_SEQUENCE
- See Also:
-
IMAGE_ORIENTATION
- See Also:
-
transferSyntaxValue
-
transferSyntaxLocation
-
transferSyntaxInSequence
-
doGEBigEndianPixelData
private boolean doGEBigEndianPixelData -
isComplex
private boolean isComplex -
elementLength
private int elementLengthLength of the value field of data element. -
elementWord
private int elementWordSecond number (DICOM element in a group) in ordered pair of numbers that uniquely identifies a data element. -
encapsulated
private boolean encapsulatedWhen Dicom image data is 'encapsulated,' it may be in pieces, or 'fragments.' don't know quite why, or if pieces should be kept together. If in fragments, the image data may span several slices, called a 'frame.' -
encapsulatedJP2
private boolean encapsulatedJP2 -
RLE
private boolean RLE -
JPEG_LS
private boolean JPEG_LS -
fileDir
Directory of the image file. -
fileHeader
File object of the image. -
fileInfo
Meta data structure in which to save all the DICOM tags. -
fileName
Name of the file to be read in. -
FIRST_ELEMENT
private final int FIRST_ELEMENTLocation of first element.- See Also:
-
groupWord
private int groupWordFirst number (DICOM group) in ordered pair of numbers that uniquely identifies a data element. -
hasHeaderBeenRead
private boolean hasHeaderBeenReadTrue if the DICOM image header has been read. -
ID_OFFSET
private final int ID_OFFSETLocation of 'DICM'.- See Also:
-
image
Reference to the image read into the application. -
tagTable
The tag table for the base FileInfoDicom. -
dirInfo
Holds sequence of files described in DICOMDIR. -
jpegData
private int[] jpegDataBuffer used when reading in encapsulated JPEG images. -
RLEData
private int[] RLEData -
JPEG_LSData
private int[] JPEG_LSData -
TAMARData
private int[] TAMARData -
lossy
private boolean lossyJPEG compression may be lossy or lossless. -
metaGroupLength
private int metaGroupLengthNumber of bytes following this File Meta Element (end of the Value field) up to and including the last File Meta Element of the Group 2 File Meta Information.See DICOM3 part 10 pages 12-14 (1988).
-
nameSQ
Name of the sequence tag. -
quiet
private boolean quietIf the file is quiet no user-interaction is performed. Useful for determining whether or not to display the MipavUtil.displayError() is to be called. This allows the option of leaving the user-interaction and notification of an error to occur here or to be handled somewhere else (as in, when an IOException is thrown but we'd prefer to notify the user once, rather than for each exception.) based on programming preferences or user-debug preference settings. -
rawFile
DOCUMENT ME! -
UNDEFINED_LENGTH
private final int UNDEFINED_LENGTHUndefined element length.- See Also:
-
vrBytes
private byte[] vrBytesValue Representation - see FileDicomTagInfo. -
stampSecondary
private boolean stampSecondaryWhether MIPAV should be written to this dicom file as the secondary stamp * -
isEnhanced
private boolean isEnhanced -
enhancedTagTables
-
isEnhanced4D
private boolean isEnhanced4D -
enhancedNumSlices
private int enhancedNumSlices -
enhancedNumVolumes
private int enhancedNumVolumes -
bytesV
-
extents
private int[] extentsThe currently known extents of the image, as indicated by the header -
endianess
private boolean endianessStores the endianess of the header, used for processing sequence tags -
imageLoadReady
private boolean imageLoadReadyWhether adequate processing of the file has occurred to allowed image to be extracted, this includes getting offset and pixel representation. -
flag
private boolean flagHeader loop keeps executing when true -
privatePublisher
Private tag for current publisher name -
haveFloatPixelData
private boolean haveFloatPixelData -
haveDoublePixelData
private boolean haveDoublePixelData -
b3
private int b3
-
-
Constructor Details
-
FileDicom
DICOM reader/writer constructor. Creates the access files and ensures that the files are opened for read-write access; it will fall back to read-only if read-write access to the image file is not granted. The file info gets the DICOM dictionary set, as well as the endianess property is set. The image itself is not read.- Parameters:
fDirPlusName- full file name (with directory)- Throws:
IOException- if there is an error constructing the files.
-
FileDicom
DICOM reader/writer constructor. Creates the access files and ensures that the files are opened for read-write access; it will fall back to read-only if read-write access to the image file is not granted. The file info gets the DICOM dictionary set, as well as the endianess property is set. The image itself is not read.- Parameters:
fName- File name.fDir- File directory.- Throws:
IOException- if there is an error constructing the files.
-
-
Method Details
-
close
Closes random access file associated with this object.- Throws:
IOException- DOCUMENT ME!
-
doStampSecondary
public void doStampSecondary(boolean stampSecondary) Sets whether MIPAV will edit the DICOM tags of this image with a secondary stamp. This occurs when the image is being saved. -
finalize
public void finalize()Prepares this class for cleanup. Calls thefinalizemethod for existing elements, closes any open files and sets other elements tonull. Exceptions which occur while this method runs (for instance, the possibility of getting aIOExceptionwhen closing the image file) is ignored quietly.- Overrides:
finalizein classFileDicomBase
-
getFileInfo
Accessor that returns the file info.- Returns:
- Structure containing the file info.
-
getDirFileInfo
Accessor that returns the DICOMDIR sequence file info.- Returns:
- Structure containing the file info.
-
isDICOM
Looks for the DICM _tag_ in the File header. If present, the image is DICOM 3.0 format.- Returns:
- boolean true if the DICM tag was found in the image header.
- Throws:
IOException- Indicates error reading the file
-
isDICOM_ver2
Dicom version 2: Does not have a preamble in which to search for "DICM" So...the solution will be to search that it has at least a couple of beginning "08" tags However, we do not know if its Little Endian or Big Endian..so need to handle both- Returns:
- Throws:
IOException
-
isQuiet
public final boolean isQuiet()gets the quiet option on the class.The idea is that for all output messages, there should be the option to not bother the user with the message. Ie., if an exception is thrown, and we normally tell the user that an error occurred, a calling class can set this option so that the calling class can handle (either loudly or quietly, as needed) the error with its own message. this could be upgraded to call with quiet to prevent user-queries from interrupting an automatic process. But that is in the future.
Note: In the future, this method and variable is to be moved to FileBase.
- Returns:
- whether this class should consider itself quiet, and by internal inspection, not notify the user.
Trueis to consider itself to not notify the user.Falseis to notify the user, and is the default behaviour.
-
isDir
public final boolean isDir()- Returns:
- true if file is a DICOMDIR
-
readHeader
Reads in all the tags available in the file and stores them in the Hashtable in FileInfoDicom. This method handles the various tags that are present at the beginning of a DICOM image file. It also sets the important File Info variables based on what it finds.The method will return with a failure code if it finds the tag "0000,0000" or it mis-reads the header and starts reading from an odd byte.
As the reader runs through the tags in the header, it reads them based on the type. There are 7 types:
- typeString
- typeShort
- typeInt
- typeFloat
- typeDouble
- typeSequence
- typeUnknown
Any special handling based on type occurs for each tag (@see FileInfoDicom), then it is added to the DICOM tags table. Each tag is checked against a small list of individual tags, as some tags have an effect on the way the following tags are interpreted.
This method also affects some of the properties of the FileInfoDicom.
- MetaGroupLength
- Units of Measure
- Transfer Syntax
- Extents
- Color Pallete for each color channel
Display type changes the modality; image length is then also recalculated.
- Returns:
trueif successful, otherwisefalse.- Throws:
IOException- if there is an error reading the file- See Also:
-
getNextTag
- Throws:
IOException
-
putPrivateTagInfo
private FileDicomTagInfo putPrivateTagInfo(FileDicomTagTable tagTable, FileDicomKey key, boolean implicit) -
processNextTag
private boolean processNextTag(FileDicomTagTable tagTable, FileDicomKey key, boolean endianess, boolean inSequence) throws IOException - Parameters:
tagTable- The tag table where this key will be storedkey- The key that is being processedendianess-- Returns:
- Throws:
IOException
-
processTransferSyntax
-
processSequence
private void processSequence(FileDicomTagTable tagTable, FileDicomKey key, String name, boolean endianess) throws IOException - Throws:
IOException
-
checkMaxSlice
Helper method for enhanced dicom which finds the maximum slice number in the dataset. Also determines whether the dataset is a 4D enhanced dataset.- Parameters:
tagTable2-
-
processUnknownVR
private void processUnknownVR(FileDicomTagTable tagTable, String name, FileDicomKey key, int tagVM, String strValue) throws IOException - Throws:
IOException
-
processImageData
private boolean processImageData(int[] extents2, int imageNumber, int imageTagLoc) throws IOException Processes image data from the defined image tag location. When the image tag's location is unknown, use locateImageTag to find it- Throws:
IOException
-
guessImageLength
Helper method for dicom files that do not specify a valid extents- Throws:
IOException
-
getEnhancedNumVolumes
public int getEnhancedNumVolumes() -
readImage
Reads a DICOM image file and stores the data into the given float buffer. This method reads the image header (@see readHeader()) then sets various fields within the FileInfo which are relevant to correctly interpreting the image. This list includes:- units of measure
- pixel pad
- file info minimum and maximum
- Parameters:
buffer- 2D buffer used for temporary storage of dataimageType- The type of image (i.e. SHORT, BYTE, ...)imageNo- For multiFrame images, imageNo >=1. For single slice image imageNo = 0.- Throws:
IOException- if there is an error reading the file- See Also:
-
readImage
Reads a DICOM image file and stores the data into the given double buffer. This method reads the image header (@see readHeader()) then sets various fields within the FileInfo which are relevant to correctly interpreting the image. This list includes:- units of measure
- pixel pad
- file info minimum and maximum
- Parameters:
buffer- 2D buffer used for temporary storage of dataimageType- The type of image (i.e. SHORT, BYTE, ...)imageNo- For multiFrame images, imageNo >=1. For single slice image imageNo = 0.- Throws:
IOException- if there is an error reading the file- See Also:
-
readImage
Reads a DICOM image file and stores the data into the given short buffer. This method reads the image header (@see readHeader()) then sets various fields within the FileInfo which are relevant to correctly interpreting the image. This list includes:- units of measure
- pixel pad
- file info minimum and maximum
This method would be used for short- (byte-) size image datasuch as PET data. This method is faster than the float buffer version of this method since not as much type-conversion is needed.
- Parameters:
buffer- 2D buffer used for temporary storage of dataimageType- The type of image (i.e. SHORT, BYTE, ...)imageNo- For multiFrame images, imageNo >=1. For single slice image imageNo = 0.- Throws:
IOException- if there is an error reading the file- See Also:
-
readShortToFloatImage
public void readShortToFloatImage(float[] floatBuffer, int imageType, int imageNo) throws IOException Reads a DICOM image file and stores the data into the given short buffer. This method reads the image header (@see readHeader()) then sets various fields within the FileInfo which are relevant to correctly interpreting the image. This list includes:- units of measure
- pixel pad
- file info minimum and maximum
This method would be used for short- (byte-) size image datasuch as PET data. This method is faster than the float buffer version of this method since not as much type-conversion is needed.
- Parameters:
imageType- The type of image (i.e. SHORT, BYTE, ...)imageNo- For multiFrame images, imageNo >=1. For single slice image imageNo = 0.buffer- 2D buffer used for temporary storage of data- Throws:
IOException- if there is an error reading the file- See Also:
-
setFileInfo
Sets the file info and sets the hasHeaderBeenRead to true.- Parameters:
fiDicom- File info structure
-
readImage
Reads a DICOM image file and stores the data into the given short buffer. This method reads the image header (@see readHeader()) then sets various fields within the FileInfo which are relevant to correctly interpreting the image. This list includes:- units of measure
- pixel pad
- file info minimum and maximum
This method would be used for short- (byte-) size image datasuch as PET data. This method is faster than the float buffer version of this method since not as much type-conversion is needed.
- Parameters:
buffer- 2D buffer used for temporary storage of dataimageType- The type of image (i.e. SHORT, BYTE, ...)imageNo- For multiFrame images, imageNo >=1. For single slice image imageNo = 0.- Throws:
IOException- if there is an error reading the file- See Also:
-
setFileName
Accessor that sets the file name and allocates new FileInfo, File and RandomAccess file objects based on the new image file based on the new filename and the old directory. This method sets the filename property of the FileDicom, recreates a raw file for random access file to read the image file pointed to by the filename (the file is opened for reading only; it cannot be written to). A new file info is created with this file info and the old DICOM dictionary is used. Finally, the endianess is set to be little-endian.Should an out-of-memory condition occur an IOException will be thrown.
- Parameters:
fName- File name for the image file.refInfo- The reference file info, containing the reference tag table.- Throws:
IOException- if there is an error constructing the files.
-
isEnhanced
public boolean isEnhanced() -
isEnhanced4D
public boolean isEnhanced4D() -
setEnhanced4D
public void setEnhanced4D(boolean isEnhanced4D) -
getEnhancedNumSlices
public int getEnhancedNumSlices() -
setEnhancedNumSlices
public void setEnhancedNumSlices(int enhancedNumSlices) -
getEnhancedTagTables
-
setEnhancedTagTables
public void setEnhancedTagTables(int numTables) -
setEnhancedTagTablesNull
public void setEnhancedTagTablesNull() -
setFileName
Accessor that sets the file name and allocates new FileInfo, File and RandomAccess file objects based on the new image file based on the new filename and the new directory. This method sets the filename property of the FileDicom, recreates a raw file for random access file to read the image file pointed to by the filename (the file is opened for reading only; it cannot be written to). A new file info is created with this file info and the old DICOM dictionary is used. Finally, the endianess is set to be little-endian.Should an out-of-memory condition occur an IOException will be thrown.
- Parameters:
f- image file to point to.refInfo- The reference file info, containing the reference tag table.- Throws:
IOException- if there is an error constructing the files.
-
setFileName
Accessor that sets the file name and allocates new FileInfo, File and RandomAccess file objects based on the new image file based on the new filename and the new directory. This method sets the filename property of the FileDicom, recreates a raw file for random access file to read the image file pointed to by the filename (the file is opened for reading only; it cannot be written to). A new file info is created with this file info and the old DICOM dictionary is used. Finally, the endianess is set to be little-endian.Should an out-of-memory condition occur an IOException will be thrown.
- Parameters:
fName- File name for the image file.fDir- Directory to locate the image file.refInfo- The reference file info, containing the reference tag table.- Throws:
IOException- if there is an error constructing the files.
-
setQuiet
public final void setQuiet(boolean q) sets the quiet option on the class.The idea is that for all output messages, there should be the option to not bother the user with the message. Ie., if an exception is thrown, and we normally tell the user that an error occurred, a calling class can set this option so that the calling class can handle (either loudly or quietly, as needed) the error with its own message. this could be upgraded to call with quiet to prevent user-queries from interrupting an automatic process. But that is in the future.
Note: In the future, this method and variable is to be moved to FileBase.
- Parameters:
q- whether this class should consider itself quiet, and by internal inspection, not notify the user.Trueis to consider itself to not notify the user.Falseis to notify the user, and is the default behaviour.
-
writeImage
public void writeImage(ModelImage image, int start, int end, int index, boolean saveAsEncapJP2) throws IOException Writes a dicom format type image.- Parameters:
image- Image model where the data is stored.start- Where in the buffer to start (begin slice).end- Where in the buffer to end (end slice).index- Index of the file information.- Throws:
IOException- if there is an error writing the file- See Also:
-
writeMultiFrameImage
public void writeMultiFrameImage(ModelImage image, int startSlice, int endSlice, int startTime, int endTime) throws IOException Writes a dicom format type image.- Parameters:
image- Image model where the data is stored.startSlice- Start image index (begin slice).endSlice- End image index (end slice).startTime- beginning time indexendTime- end time index- Throws:
IOException- if there is an error writing the file.- See Also:
-
convertGroupElement
Converts the integer values of the group word and element word into a string that is the hexadecimal representation of group word and element word, separated by a comma.- Parameters:
groupWord- The group word of the element.elementWord- The element word of the element.- Returns:
- String representation of the group element.
-
TAMARImageData
- Throws:
IOException
-
encapsulatedJPEG_LSImageData
- Throws:
IOException
-
RLEImageData
- Throws:
IOException
-
encapsulatedJP2ImageData
- Throws:
IOException
-
encapsulatedImageData
Starts with image tag. goes with OB/OW. image file must be open, file ptr: raFile.- Returns:
- int[] the extracted/decapsulated RGB image data
- Throws:
IOException- it cannot return the RGB image data, it'll just throw it.
-
extractLossyJPEGImage
Brute force removal of 1st fragment of JPEG encoded image. Cuts out JPEG encapsulated data and stores a temp JPEG image to the temp directory. Calls the MediaTracker utility to decode the JPEG image.- Parameters:
imageFrag- Image fragment.- Returns:
- RGB image buffer (int[])- the JPEG image
- Throws:
IOException- DOCUMENT ME!
-
getByte
Reads a length of the data and deposits it into a single Short or an array of Short as needed by the tag's VM.- Parameters:
vm- value multiplicity of the DICOM tag data. VM does not represent how many to find.length- number of bytes to read out of data stream; the length is not used.endianess- byte order indicator; heretrueindicates big-endian andfalseindicates little-endian.- Returns:
- Object
- Throws:
IOException- DOCUMENT ME!
-
getColorPallete
private boolean getColorPallete(FileDicomTagTable tagTable, FileDicomKey palleteKey) throws IllegalArgumentException, IOException Reads a pallete (look-up table) out of the given DICOM key and interprets the data based on the data-size specification tag. The DICOM key given defines for which colour table (either red, blue or green) the pallete is to be active. Only DICOM keys 0028,1201, 0028,1202 and 0028,1203 are accepted for use in this method and all others cause an exception to be thrown. If the DICOM color pallete size tag exists in the dictionary and is correct, then the data is read out of the color pallete tag as-specified; if the size in the color pallete tag is invalid for DICOM standard v3, the data is assumed to be 16 bits wide; if the size-specifier tag does not exist, the data in this tag is ignored. Parsing one particular key does not verify that the other colour channel pallete keys exist.While this method ensures that the tag in the dictionary is set
, it does not actually load the ModelLUTinvalid reference
FileInfoDicom#setValue(String, Object, int)ModelLUT- Parameters:
palleteKey- The DICOM key which contains some pallete or LUT information.- Throws:
IOException- A problem occurs when reading the image file.IllegalArgumentException- See Also:
-
getDataSet
Reads a set of DICOM tags from a DICOM sequence item, ending with the data-element end tagFFFE,E00D. This list of tags in a DICOM sequence item and places them into a hashtable held within a FileDicomItem.- Parameters:
itemLength- Length of the item in bytes.endianess- Big (true) or little (false).- Returns:
- The sequence item read in.
- Throws:
IOException- See Also:
-
getDouble
Reads a length of the data and deposits it into a single Double or an array of Double as needed by the tag's VM.- Parameters:
vm- value multiplicity of the DICOM tag data. VM does not represent how many to find.length- number of bytes to read out of data stream; the length is not used.endianess- byte order indicator; heretrueindicates big-endian andfalseindicates little-endian.- Returns:
- Object
- Throws:
IOException- DOCUMENT ME!
-
getFloat
Reads a length of the data and deposits it into a single Float or an array of Float as needed by the tag's VM.- Parameters:
vm- value multiplicity of the DICOM tag data. VM does not represent how many to find.length- number of bytes to read out of data stream; the length is not used.endianess- byte order indicator; heretrueindicates big-endian andfalseindicates little-endian.- Returns:
- Object
- Throws:
IOException- DOCUMENT ME!
-
getInteger
Reads a length of the data and deposits it into a single Integer or an array of Integer as needed by the tag's VM.- Parameters:
vm- value multiplicity of the DICOM tag data. VM does not represent how many to find.length- number of bytes to read out of data stream; the length is not used.endianess- byte order indicator; heretrueindicates big-endian andfalseindicates little-endian.- Returns:
- Object
- Throws:
IOException- DOCUMENT ME!
-
getLong
Reads a length of the data and deposits it into a single Integer or an array of Integer as needed by the tag's VM.- Parameters:
vm- value multiplicity of the DICOM tag data. VM does not represent how many to find.length- number of bytes to read out of data stream; the length is not used.endianess- byte order indicator; heretrueindicates big-endian andfalseindicates little-endian.- Returns:
- Object
- Throws:
IOException- DOCUMENT ME!
-
getLength
Reads in four integers, then tests for implicit Value Representation(VR) or explicit VR. If explicit, it finds out what the VR is and stores it.See DICOM Specification Part 5 (1998) Section 7 pages 24-34.
- Parameters:
endianess- Big or little.b1- First byte of the tag to be tested before applying endianess.b2- Second byte of the tag to be tested before applying endianess.b3- Third byte of the tag to be tested before applying endianess.b4- Fourth byte of the tag to be tested before applying endianess.- Returns:
- Length of the element.
- Throws:
IOException- DOCUMENT ME!
-
getNextElement
Increments the location, then reads the elementWord, groupWord, and elementLength. It also tests for an end of file and resets the elementWord if it encounters one.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- DOCUMENT ME!
-
getSequence
Gets the sequence in a sequence tag. Sequences of items have special encodings that are detailed in the DICOM standard. There is usually an "item" tag, then a dataset encoded exactly like other tags, then a tag indicating the end of the sequence.For further information see the DICOM Standard, Part 5, Section 7.
- Parameters:
endianess- Big or littleseqLength- Length of this sequence, although possibly left undefined.- Returns:
- A DicomSQ object which stores the new tags and their info
- Throws:
IOException- See Also:
-
getShort
Reads a length of the data and deposits it into a single Short or an array of Short as needed by the tag's VM.- Parameters:
vm- value multiplicity of the DICOM tag data. VM does not represent how many to find.length- number of bytes to read out of data stream; the length is not used.endianess- byte order indicator; heretrueindicates big-endian andfalseindicates little-endian.- Returns:
- Object
- Throws:
IOException- DOCUMENT ME!
-
readUnknownData
Gets private tags or other tags where the type is unknown; does not change the data, so it may be written out correctly.- Returns:
- A Byte array of length elementLength with the data stored in it.
- Throws:
IOException- DOCUMENT ME!
-
stampSecondaryCapture
Writing a file to disk likely indicates that it was changed in some way. Notify any users opening this file later that it is different from the original machine which created the image and what changed it.- Parameters:
fileInfo- File info structure to set.
-
writeNextTag
private void writeNextTag(FileDicomTag tag, RandomAccessFile outputFile, int[] lengthReduction) throws IOException Writes a dicom tag to the provided output file. This method uses the transfer syntax of the file to determine the format of the tag.- Throws:
IOException
-
writeTags
public void writeTags(RandomAccessFile outputFile, FileInfoDicom fileInfo, FileDicomKey[] editKeys, FileDicomTag[] editTags) throws IOException Writes selected tag values (location specified by editKeys, value specified by editTags), to existing dicom file specified by outputFile.- Throws:
IOException
-
replaceTag
private void replaceTag(RandomAccessFile raFile, FileDicomKey key, FileDicomTag newTag, int oldTagElementLength) throws IOException newTag is written to raFile to replace old tag of tagElementLength- Throws:
IOException
-
changeDicomFileSize
private void changeDicomFileSize(RandomAccessFile raFile, long sizeChange, long pointerLoc, int oldTagElementLength) throws IOException - Parameters:
raFile-sizeChange- - change in tag lengthpointerLoc- - beginning of tag valueoldTagElementLength- - old tag length- Throws:
IOException
-
writeHeader
public void writeHeader(RandomAccessFile outputFile, FileInfoDicom fileInfo, boolean saveAsEncapJP2) throws IOException Writes the tags of the DICOM header.- Parameters:
outputFile- Output file to write to.fileInfo- File info structure for this file.- Throws:
IOException- if there is an error writing the file.- See Also:
-
reduceStringLengthTo16
-
writeSequence
private void writeSequence(RandomAccessFile outputFile, FileInfoDicom.VRtype vr_type, FileDicomSQ sq, boolean endianess) throws IOException Writes out a sequence tag and its data. The routine writes the Sequence as undefined-length and each of the items as undefined length. The appropriate write-methods are used to output the various tags to the file.- Parameters:
outputFile- File to write to.vr_type- VR type, explicit or implicitsq- Sequence to write outendianess- Big istrueorfalsefor little endian byte-order.- Throws:
IOException- if write fails
-
doEnhanced
public void doEnhanced(boolean doEnhanced, int[] extents)
-