Class FileDicom


  • public class FileDicom
    extends FileDicomBase
    This class reads and writes DICOM files. The DICOM file format consists of header information marked by tags, with the pixel data as the last tag. Each tag has a length field that contains the length of the tag, so it is possible to skip over tags that are unrecognized. This class is entirely based on DICOM version 3.0 published by ACR/NEMA and so tests for all the tags in the Data Dictionary (DICOM v. 3.0 Part 6). It stores these in a table found in FileInfoDicom.

    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:
    FileIO, FileInfoDicom, FileRaw, FileRawChunk
    • Field Detail

      • IMAGE_TAG

        public static final java.lang.String IMAGE_TAG
        The tag marking the start of the image data.
        See Also:
        Constant Field Values
      • FLOAT_IMAGE_TAG

        public static final java.lang.String FLOAT_IMAGE_TAG
        The tag marking the start of the float image data.
        See Also:
        Constant Field Values
      • DOUBLE_IMAGE_TAG

        public static final java.lang.String DOUBLE_IMAGE_TAG
        The tag marking the start of the double image data.
        See Also:
        Constant Field Values
      • TAMAR_COMPRESSED_PIXEL_DATA

        public static final java.lang.String TAMAR_COMPRESSED_PIXEL_DATA
        See Also:
        Constant Field Values
      • SPECTROSCOPY_DATA

        public static final java.lang.String SPECTROSCOPY_DATA
        See Also:
        Constant Field Values
      • SEQ_ITEM_BEGIN

        public static final java.lang.String SEQ_ITEM_BEGIN
        The tag marking the beginning of a dicom sequence.
        See Also:
        Constant Field Values
      • SEQ_ITEM_END

        public static final java.lang.String SEQ_ITEM_END
        The tag marking the end of a dicom sequence.
        See Also:
        Constant Field Values
      • SEQ_ITEM_UNDEF_END

        public static final java.lang.String SEQ_ITEM_UNDEF_END
        The tag marking the end of an undefined length dicom sequence.
        See Also:
        Constant Field Values
      • PIXEL_MEASURES_SEQUENCE

        public static final java.lang.String PIXEL_MEASURES_SEQUENCE
        See Also:
        Constant Field Values
      • SPACING_BETWEEN_SLICES

        public static final java.lang.String SPACING_BETWEEN_SLICES
        See Also:
        Constant Field Values
      • PLANE_POSITION_SEQUENCE

        public static final java.lang.String PLANE_POSITION_SEQUENCE
        See Also:
        Constant Field Values
      • PLANE_ORIENTATION_SEQUENCE

        public static final java.lang.String PLANE_ORIENTATION_SEQUENCE
        See Also:
        Constant Field Values
      • IMAGE_ORIENTATION

        public static final java.lang.String IMAGE_ORIENTATION
        See Also:
        Constant Field Values
      • transferSyntaxValue

        private java.util.Vector<java.lang.String> transferSyntaxValue
      • transferSyntaxLocation

        private java.util.Vector<java.lang.Integer> transferSyntaxLocation
      • transferSyntaxInSequence

        private java.util.Vector<java.lang.Boolean> transferSyntaxInSequence
      • doGEBigEndianPixelData

        private boolean doGEBigEndianPixelData
      • isComplex

        private boolean isComplex
      • elementLength

        private int elementLength
        Length of the value field of data element.
      • elementWord

        private int elementWord
        Second number (DICOM element in a group) in ordered pair of numbers that uniquely identifies a data element.
      • encapsulated

        private boolean encapsulated
        When 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
      • fileDir

        private java.lang.String fileDir
        Directory of the image file.
      • fileHeader

        private java.io.File fileHeader
        File object of the image.
      • fileInfo

        private FileInfoDicom fileInfo
        Meta data structure in which to save all the DICOM tags.
      • fileName

        private java.lang.String fileName
        Name of the file to be read in.
      • FIRST_ELEMENT

        private final int FIRST_ELEMENT
        Location of first element.
        See Also:
        Constant Field Values
      • groupWord

        private int groupWord
        First number (DICOM group) in ordered pair of numbers that uniquely identifies a data element.
      • hasHeaderBeenRead

        private boolean hasHeaderBeenRead
        True if the DICOM image header has been read.
      • image

        private ModelImage image
        Reference to the image read into the application.
      • tagTable

        private FileDicomTagTable tagTable
        The tag table for the base FileInfoDicom.
      • dirInfo

        private FileDicomSQ dirInfo
        Holds sequence of files described in DICOMDIR.
      • jpegData

        private int[] jpegData
        Buffer used when reading in encapsulated JPEG images.
      • RLEData

        private int[] RLEData
      • TAMARData

        private int[] TAMARData
      • lossy

        private boolean lossy
        JPEG compression may be lossy or lossless.
      • metaGroupLength

        private int metaGroupLength
        Number 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

        private java.lang.String nameSQ
        Name of the sequence tag.
      • quiet

        private boolean quiet
        If 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

        private FileRaw rawFile
        DOCUMENT ME!
      • UNDEFINED_LENGTH

        private final int UNDEFINED_LENGTH
        Undefined element length.
        See Also:
        Constant Field Values
      • vrBytes

        private byte[] vrBytes
        Value Representation - see FileDicomTagInfo.
      • stampSecondary

        private boolean stampSecondary
        Whether MIPAV should be written to this dicom file as the secondary stamp *
      • isEnhanced

        private boolean isEnhanced
      • isEnhanced4D

        private boolean isEnhanced4D
      • enhancedNumSlices

        private int enhancedNumSlices
      • enhancedNumVolumes

        private int enhancedNumVolumes
      • bytesV

        private java.lang.Byte[] bytesV
      • extents

        private int[] extents
        The currently known extents of the image, as indicated by the header
      • endianess

        private boolean endianess
        Stores the endianess of the header, used for processing sequence tags
      • imageLoadReady

        private boolean imageLoadReady
        Whether adequate processing of the file has occurred to allowed image to be extracted, this includes getting offset and pixel representation.
      • flag

        private boolean flag
        Header loop keeps executing when true
      • privatePublisher

        private PrivateFileDicomKey privatePublisher
        Private tag for current publisher name
      • haveFloatPixelData

        private boolean haveFloatPixelData
      • haveDoublePixelData

        private boolean haveDoublePixelData
      • b3

        private int b3
    • Constructor Detail

      • FileDicom

        public FileDicom​(java.lang.String fDirPlusName)
                  throws java.io.IOException
        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:
        java.io.IOException - if there is an error constructing the files.
      • FileDicom

        public FileDicom​(java.lang.String fName,
                         java.lang.String fDir)
                  throws java.io.IOException
        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:
        java.io.IOException - if there is an error constructing the files.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Closes random access file associated with this object.
        Throws:
        java.io.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 the finalize method for existing elements, closes any open files and sets other elements to null. Exceptions which occur while this method runs (for instance, the possibility of getting a IOException when closing the image file) is ignored quietly.
        Overrides:
        finalize in class FileDicomBase
      • getFileInfo

        public final FileInfoBase getFileInfo()
        Accessor that returns the file info.
        Returns:
        Structure containing the file info.
      • getDirFileInfo

        public final FileDicomSQ getDirFileInfo()
        Accessor that returns the DICOMDIR sequence file info.
        Returns:
        Structure containing the file info.
      • isDICOM

        public boolean isDICOM()
                        throws java.io.IOException
        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:
        java.io.IOException - Indicates error reading the file
      • isDICOM_ver2

        public boolean isDICOM_ver2()
                             throws java.io.IOException
        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:
        java.io.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. True is to consider itself to not notify the user. False is to notify the user, and is the default behaviour.
      • isDir

        public final boolean isDir()
        Returns:
        true if file is a DICOMDIR
      • readHeader

        public boolean readHeader​(boolean loadTagBuffer)
                           throws java.io.IOException
        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:
        true if successful, otherwise false.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileInfoDicom, getNextElement(boolean), convertGroupElement(int, int)
      • getNextTag

        private FileDicomKey getNextTag​(boolean endianess)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • processNextTag

        private boolean processNextTag​(FileDicomTagTable tagTable,
                                       FileDicomKey key,
                                       boolean endianess,
                                       boolean inSequence)
                                throws java.io.IOException
        Parameters:
        tagTable - The tag table where this key will be stored
        key - The key that is being processed
        endianess -
        Returns:
        Throws:
        java.io.IOException
      • processTransferSyntax

        private boolean processTransferSyntax​(java.lang.String strValue)
      • processSequence

        private void processSequence​(FileDicomTagTable tagTable,
                                     FileDicomKey key,
                                     java.lang.String name,
                                     boolean endianess)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • checkMaxSlice

        private int checkMaxSlice​(FileDicomTagTable tagTable,
                                  int numSlices,
                                  java.util.TreeSet<java.lang.Integer> sliceInt)
        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,
                                      java.lang.String name,
                                      FileDicomKey key,
                                      int tagVM,
                                      java.lang.String strValue)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • processImageData

        private boolean processImageData​(int[] extents2,
                                         int imageNumber,
                                         int imageTagLoc)
                                  throws java.io.IOException
        Processes image data from the defined image tag location. When the image tag's location is unknown, use locateImageTag to find it
        Throws:
        java.io.IOException
      • guessImageLength

        private int[] guessImageLength​(int[] extents)
                                throws java.io.IOException
        Helper method for dicom files that do not specify a valid extents
        Throws:
        java.io.IOException
      • getEnhancedNumVolumes

        public int getEnhancedNumVolumes()
      • readImage

        public void readImage​(float[] buffer,
                              int imageType,
                              int imageNo)
                       throws java.io.IOException
        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 data
        imageType - The type of image (i.e. SHORT, BYTE, ...)
        imageNo - For multiFrame images, imageNo >=1. For single slice image imageNo = 0.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileRaw
      • readImage

        public void readImage​(double[] buffer,
                              int imageType,
                              int imageNo)
                       throws java.io.IOException
        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 data
        imageType - The type of image (i.e. SHORT, BYTE, ...)
        imageNo - For multiFrame images, imageNo >=1. For single slice image imageNo = 0.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileRaw
      • readImage

        public void readImage​(short[] buffer,
                              int imageType,
                              int imageNo)
                       throws java.io.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:
        buffer - 2D buffer used for temporary storage of data
        imageType - The type of image (i.e. SHORT, BYTE, ...)
        imageNo - For multiFrame images, imageNo >=1. For single slice image imageNo = 0.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileRaw
      • readShortToFloatImage

        public void readShortToFloatImage​(float[] floatBuffer,
                                          int imageType,
                                          int imageNo)
                                   throws java.io.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:
        buffer - 2D buffer used for temporary storage of data
        imageType - The type of image (i.e. SHORT, BYTE, ...)
        imageNo - For multiFrame images, imageNo >=1. For single slice image imageNo = 0.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileRaw
      • setFileInfo

        public final void setFileInfo​(FileInfoDicom fiDicom)
        Sets the file info and sets the hasHeaderBeenRead to true.
        Parameters:
        fiDicom - File info structure
      • readImage

        public void readImage​(int[] buffer,
                              int imageType,
                              int imageNo)
                       throws java.io.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:
        buffer - 2D buffer used for temporary storage of data
        imageType - The type of image (i.e. SHORT, BYTE, ...)
        imageNo - For multiFrame images, imageNo >=1. For single slice image imageNo = 0.
        Throws:
        java.io.IOException - if there is an error reading the file
        See Also:
        FileRaw
      • setFileName

        public final void setFileName​(java.lang.String fName,
                                      FileInfoDicom refInfo)
                               throws java.io.IOException
        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:
        java.io.IOException - if there is an error constructing the files.
      • isEnhanced

        public boolean isEnhanced()
      • isEnhanced4D

        public boolean isEnhanced4D()
      • getEnhancedNumSlices

        public int getEnhancedNumSlices()
      • setFileName

        public void setFileName​(java.io.File f,
                                FileInfoDicom refInfo)
                         throws java.io.IOException
        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:
        java.io.IOException - if there is an error constructing the files.
      • setFileName

        public final void setFileName​(java.lang.String fName,
                                      java.lang.String fDir,
                                      FileInfoDicom refInfo)
                               throws java.io.IOException
        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:
        java.io.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. True is to consider itself to not notify the user. False is to notify the user, and is the default behaviour.
      • writeImage

        public void writeImage​(ModelImage image,
                               int start,
                               int end,
                               int index,
                               boolean saveAsEncapJP2)
                        throws java.io.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:
        java.io.IOException - if there is an error writing the file
        See Also:
        FileRawChunk
      • writeMultiFrameImage

        public void writeMultiFrameImage​(ModelImage image,
                                         int startSlice,
                                         int endSlice,
                                         int startTime,
                                         int endTime)
                                  throws java.io.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).
        endTime - end time index
        startTime - beginning time index
        Throws:
        java.io.IOException - if there is an error writing the file.
        See Also:
        FileRawChunk
      • convertGroupElement

        private java.lang.String convertGroupElement​(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.
        Parameters:
        groupWord - The group word of the element.
        elementWord - The element word of the element.
        Returns:
        String representation of the group element.
      • TAMARImageData

        private int[] TAMARImageData()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • RLEImageData

        private int[] RLEImageData​(int imageType)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • encapsulatedJP2ImageData

        private int[] encapsulatedJP2ImageData​(int imageType)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • encapsulatedImageData

        private int[] encapsulatedImageData()
                                     throws java.io.IOException
        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:
        java.io.IOException - it cannot return the RGB image data, it'll just throw it.
      • extractLossyJPEGImage

        private int[] extractLossyJPEGImage​(byte[] imageFrag)
                                     throws java.io.IOException
        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:
        java.io.IOException - DOCUMENT ME!
      • getByte

        private java.lang.Object getByte​(int vm,
                                         int length,
                                         boolean endianess)
                                  throws java.io.IOException
        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; here true indicates big-endian and false indicates little-endian.
        Returns:
        Object
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getColorPallete

        private boolean getColorPallete​(FileDicomTagTable tagTable,
                                        FileDicomKey palleteKey)
                                 throws java.lang.IllegalArgumentException,
                                        java.io.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 FileInfoDicom#setValue(String, Object, int), it does not actually load the ModelLUT ModelLUT

        Parameters:
        palleteKey - The DICOM key which contains some pallete or LUT information.
        Throws:
        java.io.IOException - A problem occurs when reading the image file.
        java.lang.IllegalArgumentException
        See Also:
        "DICOM PS 3.3, Information Object Definitions"
      • getDataSet

        private FileDicomSQItem getDataSet​(int itemLength,
                                           boolean endianess)
                                    throws java.io.IOException
        Reads a set of DICOM tags from a DICOM sequence item, ending with the data-element end tag FFFE,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:
        java.io.IOException
        See Also:
        FileDicomItem
      • getDouble

        private java.lang.Object getDouble​(int vm,
                                           int length,
                                           boolean endianess)
                                    throws java.io.IOException
        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; here true indicates big-endian and false indicates little-endian.
        Returns:
        Object
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getFloat

        private java.lang.Object getFloat​(int vm,
                                          int length,
                                          boolean endianess)
                                   throws java.io.IOException
        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; here true indicates big-endian and false indicates little-endian.
        Returns:
        Object
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getInteger

        private java.lang.Object getInteger​(int vm,
                                            int length,
                                            boolean endianess)
                                     throws java.io.IOException
        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; here true indicates big-endian and false indicates little-endian.
        Returns:
        Object
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getLong

        private java.lang.Object getLong​(int vm,
                                         int length,
                                         boolean endianess)
                                  throws java.io.IOException
        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; here true indicates big-endian and false indicates little-endian.
        Returns:
        Object
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getLength

        private int getLength​(boolean endianess,
                              byte b1,
                              byte b2,
                              byte b3,
                              byte b4)
                       throws java.io.IOException
        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:
        java.io.IOException - DOCUMENT ME!
      • getNextElement

        private void getNextElement​(boolean bigEndian)
                             throws java.io.IOException
        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 - true indicates big endian byte order, false indicates little endian.
        Throws:
        java.io.IOException - DOCUMENT ME!
      • getSequence

        private FileDicomSQ getSequence​(boolean endianess,
                                        int seqLength)
                                 throws java.io.IOException
        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 little
        seqLength - Length of this sequence, although possibly left undefined.
        Returns:
        A DicomSQ object which stores the new tags and their info
        Throws:
        java.io.IOException
        See Also:
        DicomSQ
      • getShort

        private java.lang.Object getShort​(int vm,
                                          int length,
                                          boolean endianess)
                                   throws java.io.IOException
        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; here true indicates big-endian and false indicates little-endian.
        Returns:
        Object
        Throws:
        java.io.IOException - DOCUMENT ME!
      • readUnknownData

        private java.lang.Object readUnknownData()
                                          throws java.io.IOException
        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:
        java.io.IOException - DOCUMENT ME!
      • stampSecondaryCapture

        private void stampSecondaryCapture​(FileInfoDicom fileInfo)
        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,
                                  java.io.RandomAccessFile outputFile,
                                  int[] lengthReduction)
                           throws java.io.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:
        java.io.IOException
      • writeTags

        public void writeTags​(java.io.RandomAccessFile outputFile,
                              FileInfoDicom fileInfo,
                              FileDicomKey[] editKeys,
                              FileDicomTag[] editTags)
                       throws java.io.IOException
        Writes selected tag values (location specified by editKeys, value specified by editTags), to existing dicom file specified by outputFile.
        Throws:
        java.io.IOException
      • replaceTag

        private void replaceTag​(java.io.RandomAccessFile raFile,
                                FileDicomKey key,
                                FileDicomTag newTag,
                                int oldTagElementLength)
                         throws java.io.IOException
        newTag is written to raFile to replace old tag of tagElementLength
        Throws:
        java.io.IOException
      • changeDicomFileSize

        private void changeDicomFileSize​(java.io.RandomAccessFile raFile,
                                         long sizeChange,
                                         long pointerLoc,
                                         int oldTagElementLength)
                                  throws java.io.IOException
        Parameters:
        raFile -
        sizeChange - - change in tag length
        pointerLoc - - beginning of tag value
        oldTagElementLength - - old tag length
        Throws:
        java.io.IOException
      • writeHeader

        public void writeHeader​(java.io.RandomAccessFile outputFile,
                                FileInfoDicom fileInfo,
                                boolean saveAsEncapJP2)
                         throws java.io.IOException
        Writes the tags of the DICOM header.
        Parameters:
        outputFile - Output file to write to.
        fileInfo - File info structure for this file.
        Throws:
        java.io.IOException - if there is an error writing the file.
        See Also:
        FileInfoDicom
      • reduceStringLengthTo16

        java.lang.String reduceStringLengthTo16​(java.lang.String str)
      • writeSequence

        private void writeSequence​(java.io.RandomAccessFile outputFile,
                                   FileInfoDicom.VRtype vr_type,
                                   FileDicomSQ sq,
                                   boolean endianess)
                            throws java.io.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 implicit
        sq - Sequence to write out
        endianess - Big is true or false for little endian byte-order.
        Throws:
        java.io.IOException - if write fails
      • doEnhanced

        public void doEnhanced​(boolean doEnhanced,
                               int[] extents)