rzaratx
rzaratx

Reputation: 824

How can I tell if my dicom files are compressed?

I have been working with dicom files that are about 4 MB each but I recently received some which are 280 KB each. I am not sure whether this is because they are from different CT scanners or if the new dicoms were compressed before being given to me. Is there a way to find out and if they are compressed is there a way to uncompressed them to the original size?

Upvotes: 4

Views: 3731

Answers (3)

amin_nejad
amin_nejad

Reputation: 1090

Using pydicom, you can do the following:

import pydicom

dataset = pydicom.dcmread("<filename>")
dataset.decompress()

# Now access the pixel array
dataset.pixel_array  # numpy array

There is no need to check whether the file is compressed or not beforehand. If it is not compressed, calling decompress will have no significant effect.

Documentation: https://pydicom.github.io/pydicom/dev/reference/generated/pydicom.dataset.Dataset.html#pydicom.dataset.Dataset.decompress

Upvotes: 0

Amit Joshi
Amit Joshi

Reputation: 16389

This is in continuation to the other answer from @kritzel_sw.

If you see any of the following UIDs in (0002,0010) Transfer Syntax UID element:

1.2.840.10008.1.2   Implicit VR Endian: Default Transfer Syntax for DICOM    
1.2.840.10008.1.2.1 Explicit VR Little Endian    
1.2.840.10008.1.2.2 Explicit VR Big Endian

then the Pixel Data (7FE0,0010) Pixel Data is uncompressed. You will generally observe bigger file size here.

Not a part of your question, but objects other than image (PDF may be in case of Structured Report) can be encapsulated with following Transfer Syntax:

1.2.840.10008.1.2.1.99  Deflated Explicit VR Little Endian   

Other well known values for Transfer Syntax mean that the Pixel Data is compressed.

Note that there are also private Transfer Syntax values possible for data set. Implementation of those values is generally private to the respective manufacturer.

Upvotes: 5

Markus Sabin
Markus Sabin

Reputation: 4013

Yes and yes.

I recommend the binary tools from the OFFIS DICOM toolkit, but you will be able to achieve the same results with different toolkits. You can find the dcmtk here.

How to find out if your files are compressed:

dcmdump <filename>

Have a look at the metaheader, the attribute Transfer Syntax UID (0002,0010) in particular. Dcmdump "translates" the unique identifier to the human readable transfer syntax, e.g.

(0002,0010) UI =LittleEndianExplicit                    #  20, 1 TransferSyntaxUID

The Transfer Syntax tells you whether or not the pixel data in this DICOM file is compressed.

How to decompress compressed images:

dcmdjpeg <compressed DICOM file in> <uncompressed DICOM file out>

Upvotes: 3

Related Questions