Package loci.formats.in
Class DicomReader
java.lang.Object
loci.formats.FormatHandler
loci.formats.FormatReader
loci.formats.SubResolutionFormatReader
loci.formats.in.DicomReader
- All Implemented Interfaces:
Closeable,AutoCloseable,ICompressedTileReader,IFormatHandler,IFormatReader,IMetadataConfigurable,IPyramidHandler
DicomReader is the file format reader for DICOM files.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate Numberprivate Stringprivate loci.common.RandomAccessInputStreamprivate Stringstatic final Stringprivate static final String[]private booleanstatic final intprivate intprivate Stringprivate Stringprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate byte[][]private intprivate Stringprivate Stringprivate intprivate Stringprivate Stringprivate Stringprivate intprivate intprivate Stringprivate Stringprivate Doubleprivate short[][]private Stringprivate booleanFields inherited from class loci.formats.SubResolutionFormatReader
coreFields inherited from class loci.formats.FormatReader
coreIndex, datasetDescription, domains, fillColor, filterMetadata, flattenedResolutions, group, hasCompanionFiles, in, indexedAsRGB, metadata, metadataStore, normalizeData, resolution, saveOriginalMetadata, series, suffixNecessary, suffixSufficient, THUMBNAIL_DIMENSIONFields inherited from class loci.formats.FormatHandler
COMPRESSION_SUFFIXES, currentId, format, LOGGER, metadataOptions, suffixesFields inherited from interface loci.formats.IFormatReader
CAN_GROUP, CANNOT_GROUP, MUST_GROUP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddFileToList(String file, boolean checkSeries) Determine if the given file belongs in the same dataset as this file.private voidprivate voidaddOriginalMetadata(String key, DicomTag info) Store the given tag's value (if present) in the original metadata hashtable using the provided key.private voidaddZOffset(int coreIndex, Double z) private voidDICOM datasets produced by: http://www.ct-imaging.de/index.php/en/ct-systeme-e/mikro-ct-e.html contain a bunch of extra metadata and log files.private voidcalculatePixelsOffsets(long baseOffset) Calculate offsets to all pixel data (tiles or planes) in the file, starting from the given offset.private voidvoidclose(boolean fileOnly) Closes the currently open file.private DicomFileInfocreateFileInfo(String file) Construct a DicomFileInfo for the given file.private booleanencloses(loci.common.Region a, loci.common.Region b) intReturns an indication of whether the files in a multi-file dataset can be handled individually.short[][]Gets the 16-bit color lookup table associated with the most recently opened image.byte[][]Gets the 8-bit color lookup table associated with the most recently opened image.intintReturns the optimal sub-image height for use with openBytes.intReturns the optimal sub-image width for use with openBytes.ome.units.quantity.Lengthome.units.quantity.Lengthome.units.quantity.LengthintgetRequiredDirectories(String[] files) Returns the number of parent directories that are important when processing the given list of files.String[]getSeriesUsedFiles(boolean noPixels) Returns an array of filenames needed to open the current series.private loci.common.RandomAccessInputStreamgetTags()Provide the complete hierarchy of DICOM tags.private voidDecompress pixel data associated with the given DicomTile.getTileCodec(int no) Retrieve a codec that can be used to decompress compressed tiles.private CodecgetTileCodec(DicomTile tile) Get a Codec that can be used to decompress the given tile.getTileCodecOptions(int no, int x, int y) Retrieve codec options that can be used to decompressed the specified tile.private CodecOptionsgetTileCodecOptions(DicomTile tile) Get a CodecOptions that can be used to decompress the given tile.intgetTileColumns(int no) Get the number of columns of tiles in the specified plane in the current series.getTileList(int no, loci.common.Region boundingBox, boolean firstTileOnly) Get a list of tiles corresponding to the given plane.intgetTileRows(int no) Get the number of rows of tiles in the specified plane in the current series.getTiles()getTiles(int coreIndex) ome.xml.model.primitives.Timestampprivate longConvert the timestamp from a TM value to microseconds.getZOffsets(int coreIndex) private voidhandleReferencedFile(DicomTag tag, String currentType) protected voidInitializes the given file (parsing header information, etc.).booleanbooleanisThisType(String name, boolean open) Checks if a file matches the type of this format reader.booleanisThisType(loci.common.RandomAccessInputStream stream) Checks if the given stream is a valid stream for this file format.private voidBuild a list of files that belong with the current file.byte[]openBytes(int no, byte[] buf, int x, int y, int w, int h) Obtains a sub-image of the specified image plane into a pre-allocated byte array.byte[]openCompressedBytes(int no, byte[] buf, int x, int y) Retrieve the specified tile without performing any decompression.byte[]openCompressedBytes(int no, int x, int y) Retrieve the specified tile without performing any decompression.private intparseIntValue(Number v, int defaultValue) private voidparsePixelSpacing(String value) private voidscanDirectory(loci.common.Location dir, boolean checkSeries) Scan the given directory for files that belong to this dataset.protected org.perf4j.slf4j.Slf4JStopWatchprivate voidMethods inherited from class loci.formats.SubResolutionFormatReader
coreIndexToSeries, flattenHashtables, getCoreIndex, getCoreMetadataList, getCurrentCore, getResolution, getResolutionCount, getSeries, getSeriesCount, seriesToCoreIndex, setCoreIndex, setResolution, setSeriesMethods inherited from class loci.formats.FormatReader
addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMetaList, addMeta, addMetaList, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMetaList, close, getAcquisitionMode, getAdvancedSeriesUsedFiles, getAdvancedUsedFiles, getArcType, getAvailableOptions, getBinning, getBitsPerPixel, getCompression, getContrastMethod, getCorrection, getCurrentFile, getDatasetStructureDescription, getDetectorType, getDimensionOrder, getDimensionOrder, getDomains, getEffectiveSizeC, getExperimentType, getFilamentType, getFillColor, getFillRule, getFilterType, getFontFamily, getFontStyle, getGlobalMeta, getGlobalMetadata, getIlluminationType, getImageCount, getImmersion, getIndex, getIndex, getLaserMedium, getLaserType, getMarker, getMedium, getMetadataStore, getMetadataStoreRoot, getMetadataValue, getMicrobeamManipulationType, getMicroscopeType, getModuloC, getModuloT, getModuloZ, getNamingConvention, getPixelType, getPixelType, getPossibleDomains, getPulse, getRGBChannelCount, getRotationTransform, getSeriesMeta, getSeriesMetadata, getSeriesMetadataValue, getSeriesUsedFiles, getSizeC, getSizeT, getSizeX, getSizeY, getSizeZ, getThumbSizeX, getThumbSizeY, getUnderlyingReaders, getUsedFiles, getUsedFiles, getZCTCoords, getZCTModuloCoords, hasCompanionFiles, hasFlattenedResolutions, isFalseColor, isGroupFiles, isIndexed, isInterleaved, isInterleaved, isLittleEndian, isMetadataComplete, isMetadataFiltered, isNormalized, isOrderCertain, isOriginalMetadataPopulated, isRGB, isSingleFile, isThisType, isThisType, isThumbnailSeries, isUsedFile, makeFilterMetadata, openBytes, openBytes, openBytes, openPlane, openThumbBytes, readPlane, readPlane, readPlane, reopenFile, setFillColor, setFlattenedResolutions, setGroupFiles, setId, setMetadataFiltered, setMetadataStore, setNormalized, setOriginalMetadataPopulated, updateMetadataListsMethods inherited from class loci.formats.FormatHandler
checkSuffix, checkSuffix, getFormat, getMetadataOptions, getNativeDataType, getSuffixes, getSupportedMetadataLevels, setMetadataOptionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface loci.formats.IFormatHandler
getFormat, getNativeDataType, getSuffixesMethods inherited from interface loci.formats.IMetadataConfigurable
getMetadataOptions, getSupportedMetadataLevels, setMetadataOptions
-
Field Details
-
DICOM_MAGIC_STRING
- See Also:
-
HEADER_LENGTH
public static final int HEADER_LENGTH- See Also:
-
DICOM_SUFFIXES
-
lut
private byte[][] lut -
shortLut
private short[][] shortLut -
maxPixelRange
private int maxPixelRange -
centerPixelValue
private int centerPixelValue -
inverted
private boolean inverted -
date
-
time
-
imageType
-
pixelSizeX
-
pixelSizeY
-
pixelSizeZ
-
positionX
-
positionY
-
positionZ
-
channelNames
-
isJPEG
private boolean isJPEG -
isRLE
private boolean isRLE -
isJP2K
private boolean isJP2K -
isDeflate
private boolean isDeflate -
fileList
-
imagesPerFile
private int imagesPerFile -
instanceUID
-
originalDate
-
originalTime
-
originalInstance
-
originalSeries
private int originalSeries -
originalX
private int originalX -
originalY
private int originalY -
originalSpecimen
-
originalStudyTime
-
wsi
private boolean wsi -
companionFiles
-
tilePositions
-
zOffsets
-
concatenationNumber
-
edf
private boolean edf -
tags
-
currentTileFile
-
currentTileStream
private transient loci.common.RandomAccessInputStream currentTileStream -
privateContentHighWords
-
-
Constructor Details
-
DicomReader
public DicomReader()Constructs a new DICOM reader.
-
-
Method Details
-
getTileRows
public int getTileRows(int no) Description copied from interface:ICompressedTileReaderGet the number of rows of tiles in the specified plane in the current series.- Specified by:
getTileRowsin interfaceICompressedTileReader- Overrides:
getTileRowsin classFormatReader- Parameters:
no- plane index- Returns:
- tile row count
-
getTileColumns
public int getTileColumns(int no) Description copied from interface:ICompressedTileReaderGet the number of columns of tiles in the specified plane in the current series.- Specified by:
getTileColumnsin interfaceICompressedTileReader- Overrides:
getTileColumnsin classFormatReader- Parameters:
no- plane index- Returns:
- tile column count
-
openCompressedBytes
Description copied from interface:ICompressedTileReaderRetrieve the specified tile without performing any decompression.- Parameters:
no- plane indexx- tile X index (indexed from 0, @see getTileColumns(int))y- tile Y index (indexed from 0, @see getTileRows(int))- Returns:
- compressed tile bytes
- Throws:
FormatExceptionIOException
-
openCompressedBytes
public byte[] openCompressedBytes(int no, byte[] buf, int x, int y) throws FormatException, IOException Description copied from interface:ICompressedTileReaderRetrieve the specified tile without performing any decompression.- Parameters:
no- plane indexbuf- pre-allocated buffer in which to store compressed bytesx- tile X index (indexed from 0, @see getTileColumns(int))y- tile Y index (indexed from 0, @see getTileRows(int))- Returns:
- compressed tile bytes
- Throws:
FormatExceptionIOException
-
getTileCodec
Description copied from interface:ICompressedTileReaderRetrieve a codec that can be used to decompress compressed tiles.- Parameters:
no- plane index- Returns:
- codec that can be used for compressed tiles in the specified plane
- Throws:
FormatExceptionIOException- See Also:
-
getTileCodecOptions
Description copied from interface:ICompressedTileReaderRetrieve codec options that can be used to decompressed the specified tile.- Parameters:
no- plane indexx- tile X index (indexed from 0, @see getTileColumns(int))y- tile Y index (indexed from 0, @see getTileRows(int))- Returns:
- codec options
- Throws:
FormatExceptionIOException- See Also:
-
isThisType
Description copied from class:FormatReaderChecks if a file matches the type of this format reader. Checks filename suffixes against those known for this format. If the suffix check is inconclusive and the open parameter is true, the file is opened and tested withFormatReader.isThisType(RandomAccessInputStream).- Specified by:
isThisTypein interfaceIFormatReader- Overrides:
isThisTypein classFormatReader- Parameters:
open- If true, and the file extension is insufficient to determine the file type, the (existing) file is opened for further analysis.
-
isThisType
Description copied from interface:IFormatReaderChecks if the given stream is a valid stream for this file format. The number of bytes read is format-dependent.- Specified by:
isThisTypein interfaceIFormatReader- Overrides:
isThisTypein classFormatReader- Parameters:
stream- A RandomAccessInputStream representing the file to check. The first byte in the stream is assumed to be the first byte in the file.- Returns:
- true if the file represented by the stream can be read by this reader; false otherwise.
- Throws:
IOException
-
getRequiredDirectories
Description copied from interface:IFormatReaderReturns the number of parent directories that are important when processing the given list of files. The number of directories is relative to the common parent. For example, given a list with these two files: /path/to/file/foo /path/to/file/that/is/related A return value of 0 indicates that "/path/to/file/" is irrelevant. A return value of 1 indicates that "/path/to/" is irrelevant. Return values less than 0 are invalid. All listed files are assumed to belong to datasets of the same format.- Specified by:
getRequiredDirectoriesin interfaceIFormatReader- Overrides:
getRequiredDirectoriesin classFormatReader- Throws:
FormatExceptionIOException
-
get8BitLookupTable
public byte[][] get8BitLookupTable()Description copied from interface:IFormatReaderGets the 8-bit color lookup table associated with the most recently opened image. If no image planes have been opened, or ifIFormatReader.isIndexed()returns false, then this may return null. Also, ifIFormatReader.getPixelType()returns anything other thanFormatTools.INT8orFormatTools.UINT8, this method will return null.- Specified by:
get8BitLookupTablein interfaceIFormatReader- Overrides:
get8BitLookupTablein classFormatReader
-
get16BitLookupTable
public short[][] get16BitLookupTable()Description copied from interface:IFormatReaderGets the 16-bit color lookup table associated with the most recently opened image. If no image planes have been opened, or ifIFormatReader.isIndexed()returns false, then this may return null. Also, ifIFormatReader.getPixelType()returns anything other thanFormatTools.INT16orFormatTools.UINT16, this method will return null.- Specified by:
get16BitLookupTablein interfaceIFormatReader- Overrides:
get16BitLookupTablein classFormatReader
-
getSeriesUsedFiles
Description copied from interface:IFormatReaderReturns an array of filenames needed to open the current series. If the 'noPixels' flag is set, then only files that do not contain pixel data will be returned. The first element in the array is expected to be the path passed toIFormatHandler.setId(String), if appropriate based upon 'noPixels'. The remaining elements are expected to be in a consistent order; if a directory listing is necessary to build the list then it should be sorted first.- Specified by:
getSeriesUsedFilesin interfaceIFormatReader- Overrides:
getSeriesUsedFilesin classFormatReader
-
fileGroupOption
Description copied from interface:IFormatReaderReturns an indication of whether the files in a multi-file dataset can be handled individually. This method is only useful for formats and datasets which contain multiple files.- Specified by:
fileGroupOptionin interfaceIFormatReader- Overrides:
fileGroupOptionin classFormatReader- Parameters:
id- a file in the multi-file dataset- Returns:
- an int indicating that we cannot, must, or might group the files.
A return value of
FormatTools.MUST_GROUPindicates that the files cannot be handled separately; the reader will always detect and read all files in the dataset.FormatTools.CAN_GROUPindicates that the files may be handled separately, but file grouping must then be disabled viaIFormatReader.setGroupFiles(boolean).FormatTools.CANNOT_GROUPindicates that the files must be handled separately; the reader will not attempt to read all files in the dataset (this is rare). - Throws:
FormatExceptionIOException- See Also:
-
getOptimalTileWidth
public int getOptimalTileWidth()Description copied from interface:IFormatReaderReturns the optimal sub-image width for use with openBytes.- Specified by:
getOptimalTileWidthin interfaceIFormatReader- Overrides:
getOptimalTileWidthin classFormatReader
-
getOptimalTileHeight
public int getOptimalTileHeight()Description copied from interface:IFormatReaderReturns the optimal sub-image height for use with openBytes.- Specified by:
getOptimalTileHeightin interfaceIFormatReader- Overrides:
getOptimalTileHeightin classFormatReader
-
openBytes
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException Description copied from interface:IFormatReaderObtains a sub-image of the specified image plane into a pre-allocated byte array.- Specified by:
openBytesin interfaceIFormatReader- Specified by:
openBytesin classFormatReader- Parameters:
no- the plane index within the current series.buf- a pre-allocated buffer.x- X coordinate of the upper-left corner of the sub-imagey- Y coordinate of the upper-left corner of the sub-imagew- width of the sub-imageh- height of the sub-image- Returns:
- the pre-allocated buffer
buffor convenience. - Throws:
FormatException- if there was a problem parsing the metadata of the file.IOException- if there was a problem reading the file.- See Also:
-
close
Description copied from interface:IFormatReaderCloses the currently open file. If the flag is set, this is all that happens; if unset, it is equivalent to callingCloseable.close().- Specified by:
closein interfaceIFormatReader- Overrides:
closein classSubResolutionFormatReader- Throws:
IOException
-
initFile
Description copied from class:SubResolutionFormatReaderInitializes the given file (parsing header information, etc.). Most subclasses should override this method to perform initialization operations such as parsing metadata.- Overrides:
initFilein classSubResolutionFormatReader- Throws:
FormatException- if a parsing error occurs processing the file.IOException- if an I/O error occurs processing the file
-
addInfo
- Throws:
IOException
-
addOriginalMetadata
Store the given tag's value (if present) in the original metadata hashtable using the provided key. Any children of the tag will be added to the table as well. Note that the "Per-Frame Functional Groups Sequence" and "Referenced Image Navigation Sequence" and any children will be omitted, as will any values that are byte or short arrays (e.g. lookup tables). This is necessary to prevent memory exhaustion. Applications that need to traverse the complete hierarchy of DICOM tags should use getTags() to access tags directly and not rely upon the original metadata table. -
makeFileList
Build a list of files that belong with the current file.- Throws:
FormatExceptionIOException
-
scanDirectory
private void scanDirectory(loci.common.Location dir, boolean checkSeries) throws FormatException, IOException Scan the given directory for files that belong to this dataset.- Throws:
FormatExceptionIOException
-
addFileToList
Determine if the given file belongs in the same dataset as this file.- Throws:
FormatExceptionIOException
-
parseIntValue
-
getTimestampMicroseconds
Convert the timestamp from a TM value to microseconds. The timestamp format defined in the standard is HHMMSS.FFFFFF but HH:MM:SS.FFFFFF is supported as well since some files incorrectly use that format. -
attachCompanionFiles
DICOM datasets produced by: http://www.ct-imaging.de/index.php/en/ct-systeme-e/mikro-ct-e.html contain a bunch of extra metadata and log files. We do not parse these extra files, but do locate and attach them to the DICOM file(s).- Throws:
IOException
-
getStream
- Throws:
IOException
-
getTileCodec
Get a Codec that can be used to decompress the given tile. -
getTileCodecOptions
Get a CodecOptions that can be used to decompress the given tile. -
getTileList
Get a list of tiles corresponding to the given plane. If the bounding box is not null, then only tiles intersecting with the bounding box will be returned. If the "firstTileOnly" flag is set, then this will return as soon as one matching tile is found. -
calculateTilePlaneIndexes
private void calculateTilePlaneIndexes() -
getTile
private void getTile(DicomTile tile, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException Decompress pixel data associated with the given DicomTile.- Throws:
FormatExceptionIOException
-
parsePixelSpacing
-
handleReferencedFile
-
calculatePixelsOffsets
Calculate offsets to all pixel data (tiles or planes) in the file, starting from the given offset.- Throws:
FormatExceptionIOException
-
createFileInfo
Construct a DicomFileInfo for the given file. If the file is the currently initialized file, don't parse it again.- Throws:
FormatExceptionIOException
-
encloses
private boolean encloses(loci.common.Region a, loci.common.Region b) -
updateCoreMetadata
-
getImageType
-
getTiles
-
getTiles
-
addZOffset
-
getZOffsets
-
getZOffsets
-
getConcatenationIndex
public int getConcatenationIndex() -
getPixelSizeX
public ome.units.quantity.Length getPixelSizeX() -
getPixelSizeY
public ome.units.quantity.Length getPixelSizeY() -
getPixelSizeZ
public ome.units.quantity.Length getPixelSizeZ() -
getPositionX
-
getPositionY
-
getPositionZ
-
getChannelNames
-
isExtendedDepthOfField
public boolean isExtendedDepthOfField() -
getTimestamp
public ome.xml.model.primitives.Timestamp getTimestamp() -
getTags
Provide the complete hierarchy of DICOM tags. Applications that need to query or display the complete tag structure should use this method to retrieve tags instead of relying upon original metadata. -
stopWatch
protected org.perf4j.slf4j.Slf4JStopWatch stopWatch()
-