Compressing DICOM Files with LEADTOOLS

It’s easy to take compression for granted with the availability of cheap storage. Many of the common file formats used in many applications are intrinsically compressed as well, like JPEGs and PNGs. However, when you get into the Medical Imaging market and the prevalent DICOM file format, it is a very different ballgame. Like any good preschooler, you might be asking, “Why?”.

The importance of compression in Medical Imaging

  • Large images – Some DICOM images can be very large; microscopy images with dimensions of 61,440 x 14,848 (2.6 GB) are not uncommon.
  • Many images – Modalities like CT and MRI can generate hundreds of image slices per study and take up space very rapidly without good compression.
  • Grayscale images – Medical imaging relies heavily on extended grayscale images, which are up to 16bpp. The most common compression algorithms only support 8bpp images. This means you have to either lose image data or utilize software capable of dealing with these specialized images.
  • Storage Bottlenecks – The processing power you can get out of just a hand-held device nowadays is incredible, but there are still bottlenecks that occur in any system. Compressed images will require less bandwidth for the viewing station or device when consuming and transmitting data over the LAN and/or Internet.
  • Cloud storage pricing – Physical storage may be cheap, but cloud storage is immensely popular and can become costly if large images are eating up the storage limits.
  • Liability and HIPAA – Medical records and their associated images are a very big deal in terms of privacy and retention. In some cases multiple copies are required to satisfy HIPAA. Maintaining the visual integrity of the images is also important, leading some to err on the unnecessarily safe side and leave images uncompressed to guarantee data won’t be lost.

Compress an existing DICOM file with LEADTOOLS

Not every DICOM library is created equal! There are minimum requirements for being DICOM-compliant, but LEADTOOLS DICOM SDK Technology goes above and beyond, making sure that it keeps up with all the latest supplements and updates, especially when it comes to compression. Even when using the same compression standard (e.g., JPEG, JPEG2000, etc.) one library may implement the standard slightly differently or include additional compression steps that squeeze out every little bit possible.

Finally, there’s the simple fact that LEADTOOLS is easy to code with. Below is a code snippet that takes a DICOM file and saves it back out with JPEG2000 compression. In this example, the uncompressed image was 596KB and the compressed result was only 13KB!


DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
   //Load DICOM File 
   ds.Load(input, DicomDataSetLoadFlags.None);

   //Initialize J2K Options
   DicomJpeg2000Options options = ds.DefaultJpeg2000Options;

   //Set Options
   options.CompressionControl = DicomJpeg2000CompressionControl.Ratio;
   options.CompressionRatio = 50;

   //Add options to the dataset
   ds.Jpeg2000Options = options;

   //Change the transfer syntax to J22K
   ds.ChangeTransferSyntax(DicomUidType.JPEG2000, 2, ChangeTransferSyntaxFlags.MinimizeJpegSize);

   //Save Dicom file
   ds.Save(dest, DicomDataSetSaveFlags.None);

   //Shut down the DICOM engine
   DicomEngine.Shutdown();
}

If you don’t want to make any change to the image data, JPEG2000 lossless compression can be used as well with even less code. Naturally, a lossless image will usually be larger than a lossy-compressed image, but this still gave me a much better result than leaving it uncompressed: 320KB. With that kind of compression, you can easily save both a high and low resolution version of the same image with nearly half the space of the single, uncompressed image.


DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
   //Load DICOM File 
   ds.Load(input, DicomDataSetLoadFlags.None);

   //Change the transfer syntax to J22K
   ds.ChangeTransferSyntax(DicomUidType.JPEG2000LosslessOnly, 0, ChangeTransferSyntaxFlags.None);

   //Save Dicom file
   ds.Save(dest, DicomDataSetSaveFlags.None);

   //Shut down the DICOM engine
   DicomEngine.Shutdown();
}

Try LEADTOOLS on your own DICOM files

The unique situation at your practice, hospital, or office is likely different from the one across town, but almost everyone can benefit from better compression. Even if you're not working with DICOM or Medical Imaging, LEADTOOLS has you covered with the world's leading imaging SDK. Download our free evaluation to get started today or try some of our demos and sample applications.

About 

Developer Advocate

This entry was posted in Medical Imaging and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *