Class FileDicom

java.lang.Object
gov.nih.mipav.model.file.FileDicomBase
gov.nih.mipav.model.file.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:
  • Field Details

    • IMAGE_TAG

      public static final String IMAGE_TAG
      The tag marking the start of the image data.
      See Also:
    • FLOAT_IMAGE_TAG

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

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

      public static final String TAMAR_COMPRESSED_PIXEL_DATA
      See Also:
    • SPECTROSCOPY_DATA

      public static final String SPECTROSCOPY_DATA
      See Also:
    • SEQ_ITEM_BEGIN

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

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

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

      public static final String PIXEL_MEASURES_SEQUENCE
      See Also:
    • SLICE_THICKNESS

      public static final String SLICE_THICKNESS
      See Also:
    • PIXEL_SPACING

      public static final String PIXEL_SPACING
      See Also:
    • SPACING_BETWEEN_SLICES

      public static final String SPACING_BETWEEN_SLICES
      See Also:
    • PLANE_POSITION_SEQUENCE

      public static final String PLANE_POSITION_SEQUENCE
      See Also:
    • IMAGE_POSITION

      public static final String IMAGE_POSITION
      See Also:
    • PLANE_ORIENTATION_SEQUENCE

      public static final String PLANE_ORIENTATION_SEQUENCE
      See Also:
    • IMAGE_ORIENTATION

      public static final String IMAGE_ORIENTATION
      See Also:
    • transferSyntaxValue

      private Vector<String> transferSyntaxValue
    • transferSyntaxLocation

      private Vector<Integer> transferSyntaxLocation
    • transferSyntaxInSequence

      private Vector<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
    • JPEG_LS

      private boolean JPEG_LS
    • fileDir

      private String fileDir
      Directory of the image file.
    • fileHeader

      private File fileHeader
      File object of the image.
    • fileInfo

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

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

      private final int FIRST_ELEMENT
      Location of first element.
      See Also:
    • 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.
    • ID_OFFSET

      private final int ID_OFFSET
      Location of 'DICM'.
      See Also:
    • 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
    • JPEG_LSData

      private int[] JPEG_LSData
    • 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 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:
    • 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
    • enhancedTagTables

      private FileDicomTagTable[] enhancedTagTables
    • isEnhanced4D

      private boolean isEnhanced4D
    • enhancedNumSlices

      private int enhancedNumSlices
    • enhancedNumVolumes

      private int enhancedNumVolumes
    • bytesV

      private 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 Details

    • FileDicom

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

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

    • close

      public void close() throws IOException
      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 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 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:
      IOException - Indicates error reading the file
    • isDICOM_ver2

      public boolean isDICOM_ver2() throws 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:
      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 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:
      IOException - if there is an error reading the file
      See Also:
    • getNextTag

      private FileDicomKey getNextTag(boolean endianess) throws IOException
      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 stored
      key - The key that is being processed
      endianess -
      Returns:
      Throws:
      IOException
    • processTransferSyntax

      private boolean processTransferSyntax(String strValue)
    • processSequence

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

      private int checkMaxSlice(FileDicomTagTable tagTable, int numSlices, TreeSet<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, 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

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

      public int getEnhancedNumVolumes()
    • readImage

      public void readImage(float[] buffer, int imageType, int imageNo) throws 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:
      IOException - if there is an error reading the file
      See Also:
    • readImage

      public void readImage(double[] buffer, int imageType, int imageNo) throws 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:
      IOException - if there is an error reading the file
      See Also:
    • readImage

      public void readImage(short[] buffer, 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:
      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:
      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

      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 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:
      IOException - if there is an error reading the file
      See Also:
    • setFileName

      public final void setFileName(String fName, FileInfoDicom refInfo) throws 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:
      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

      public FileDicomTagTable[] getEnhancedTagTables()
    • setEnhancedTagTables

      public void setEnhancedTagTables(int numTables)
    • setEnhancedTagTablesNull

      public void setEnhancedTagTablesNull()
    • setFileName

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

      public final void setFileName(String fName, String fDir, FileInfoDicom refInfo) throws 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:
      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 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 index
      endTime - end time index
      Throws:
      IOException - if there is an error writing the file.
      See Also:
    • convertGroupElement

      private 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 IOException
      Throws:
      IOException
    • encapsulatedJPEG_LSImageData

      private int[] encapsulatedJPEG_LSImageData() throws IOException
      Throws:
      IOException
    • RLEImageData

      private int[] RLEImageData(int imageType) throws IOException
      Throws:
      IOException
    • encapsulatedJP2ImageData

      private int[] encapsulatedJP2ImageData(int imageType) throws IOException
      Throws:
      IOException
    • encapsulatedImageData

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

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

      private Object getByte(int vm, int length, boolean endianess) throws 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:
      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

      invalid reference
      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:
      IOException - A problem occurs when reading the image file.
      IllegalArgumentException
      See Also:
      • "DICOM PS 3.3, Information Object Definitions"
    • getDataSet

      private FileDicomSQItem getDataSet(int itemLength, boolean endianess) throws 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:
      IOException
      See Also:
      • invalid reference
        FileDicomItem
    • getDouble

      private Object getDouble(int vm, int length, boolean endianess) throws 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:
      IOException - DOCUMENT ME!
    • getFloat

      private Object getFloat(int vm, int length, boolean endianess) throws 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:
      IOException - DOCUMENT ME!
    • getInteger

      private Object getInteger(int vm, int length, boolean endianess) throws 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:
      IOException - DOCUMENT ME!
    • getLong

      private Object getLong(int vm, int length, boolean endianess) throws 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:
      IOException - DOCUMENT ME!
    • getLength

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

      private void getNextElement(boolean bigEndian) throws 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:
      IOException - DOCUMENT ME!
    • getSequence

      private FileDicomSQ getSequence(boolean endianess, int seqLength) throws 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:
      IOException
      See Also:
      • invalid reference
        DicomSQ
    • getShort

      private Object getShort(int vm, int length, boolean endianess) throws 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:
      IOException - DOCUMENT ME!
    • readUnknownData

      private Object readUnknownData() throws 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:
      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, 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 length
      pointerLoc - - beginning of tag value
      oldTagElementLength - - 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

      String reduceStringLengthTo16(String str)
    • 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 implicit
      sq - Sequence to write out
      endianess - Big is true or false for little endian byte-order.
      Throws:
      IOException - if write fails
    • doEnhanced

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