Aspose.Medical  for .NET

DICOM JPEG 2000 Support in .NET C#

Read, write, and transcode DICOM files with JPEG 2000 compression. Lossless and lossy modes, monochrome and color pixel data from 1 to 16 bits, HTJ2K included - all in pure .NET.

  Download Free Trial

JPEG 2000 in Medical Imaging

JPEG 2000 (ISO/IEC 15444) is the most widely used wavelet-based compression standard in medical imaging. Unlike traditional JPEG, it offers both lossless and lossy compression in a single codec, progressive decoding for region-of-interest access, and superior compression ratios — making it ideal for archiving large studies and transmitting images over constrained networks.

Aspose.Medical for .NET provides a pure C# implementation of the JPEG 2000 codec with no native dependencies. The library can read, render, and transcode DICOM files compressed with both JPEG 2000 Part 1 transfer syntaxes, lossless and lossy.

Supported JPEG 2000 Transfer Syntaxes

Transfer SyntaxUIDModeReadWrite
JPEG 2000 Lossless Only1.2.840.10008.1.2.4.90LosslessMonochrome and color, 1 to 16 bitsMonochrome, palette color and RGB, 1 to 16 bits
JPEG 20001.2.840.10008.1.2.4.91Lossy or losslessMonochrome and color, 1 to 16 bitsMonochrome and RGB, 1 to 16 bits
JPEG 2000 Part 2 Multi-component Lossless Only1.2.840.10008.1.2.4.92LosslessNot supportedNot supported
JPEG 2000 Part 2 Multi-component1.2.840.10008.1.2.4.93Lossy or losslessNot supportedNot supported
HTJ2K Lossless Only1.2.840.10008.1.2.4.201LosslessMonochrome and colorMonochrome and color
HTJ2K with RPCL Options Lossless Only1.2.840.10008.1.2.4.202LosslessMonochrome and colorMonochrome and color
HTJ2K1.2.840.10008.1.2.4.203Lossy or losslessMonochrome and colorMonochrome and color

Pixel Data from 1 to 16 Bits

Medical images often use 16 bits per sample to capture the full dynamic range of modalities like CT (typically 12-bit stored in 16-bit) and MRI. Aspose.Medical handles every depth from 1 to 16 bits for JPEG 2000, in 8-bit or 16-bit samples:

  • Reading (decompression): monochrome files (CT, MRI, X-ray), palette color files and three-component color files (RGB, YBR_RCT, YBR_ICT, and other color labels such as YBR_FULL, decoded as coded) with 1 to 16 bits per sample, signed or unsigned. CMYK, ICC-profile, JP2 palette and sub-sampled color code streams are rejected with a clear exception instead of a silently wrong image.
  • Writing (compression): monochrome and RGB images with 1 to 16 bits per sample, signed or unsigned, and palette color images with JPEG 2000 Lossless. YBR images are not encoded unless they decode to RGB, as lossy JPEG YBR files do.

Read and inspect JPEG 2000 compressed DICOM - C#

// Open a JPEG 2000 compressed DICOM file (8-bit or 16-bit)
DicomFile dicomFile = DicomFile.Open("j2k_compressed.dcm");

// Check transfer syntax
TransferSyntax? ts = dicomFile.MetaInfo.TransferSyntax;
if (ts is null)
    return; // the file meta information carries no transfer syntax
Console.WriteLine($"Transfer Syntax: {ts}");
Console.WriteLine($"Encapsulated: {ts.IsEncapsulated}");
Console.WriteLine($"Lossy: {ts.IsLossy}");

// Inspect pixel data bit depth
PixelData pixelData = PixelData.Create(dicomFile.Dataset);
Console.WriteLine($"Bits Allocated: {pixelData.BitsAllocated}");
Console.WriteLine($"Bits Stored: {pixelData.BitsStored}");
Console.WriteLine($"High Bit: {pixelData.HighBit}");
Console.WriteLine($"Samples Per Pixel: {pixelData.SamplesPerPixel}");

Transcode to JPEG 2000

Use the Transcode method to compress any DICOM file to JPEG 2000 or to convert between JPEG 2000 modes:

Compress DICOM to JPEG 2000 Lossless - C#

// Load an uncompressed DICOM file
DicomFile dicomFile = DicomFile.Open("uncompressed.dcm");

// Transcode to JPEG 2000 Lossless — no quality loss, reduced file size
DicomFile lossless = dicomFile.Transcode(TransferSyntax.Jpeg2000Lossless);
lossless.Save("j2k_lossless.dcm");

Compress DICOM to JPEG 2000 Lossy - C#

// Load a DICOM file
DicomFile dicomFile = DicomFile.Open("input.dcm");

// Transcode to JPEG 2000 Lossy — smaller file size for transmission
DicomFile lossy = dicomFile.Transcode(TransferSyntax.Jpeg2000Lossy);
lossy.Save("j2k_lossy.dcm");

Decompress JPEG 2000 DICOM Files

Decompress JPEG 2000 files to an uncompressed transfer syntax for processing, analysis, or compatibility with systems that do not support JPEG 2000:

Decompress JPEG 2000 to uncompressed - C#

// Load a JPEG 2000 compressed DICOM file
DicomFile compressed = DicomFile.Open("j2k_compressed.dcm");

// Decompress to Explicit VR Little Endian
DicomFile uncompressed = compressed.Transcode(TransferSyntax.ExplicitVrLittleEndian);
uncompressed.Save("decompressed.dcm");

You can also decompress and transcode to other compression formats in a single step:

Transcode between compression formats - C#

// Convert JPEG 2000 to JPEG-LS Lossless
DicomFile j2kFile = DicomFile.Open("j2k_lossless.dcm");
DicomFile jlsFile = j2kFile.Transcode(TransferSyntax.JpegLsLossless);
jlsFile.Save("jpegls_lossless.dcm");

Render JPEG 2000 DICOM Images

JPEG 2000 compressed DICOM files can be rendered to pixel data for display or export, just like any other transfer syntax:

Render a JPEG 2000 compressed frame - C#

// Open JPEG 2000 DICOM file
DicomFile dicomFile = DicomFile.Open("j2k_compressed.dcm");

// Render the first frame — decompression is handled automatically
using PixelImage<Bgra32> image = dicomFile.RenderImage(0);

// Copy the BGRA32 pixel data for display or export
int width = image.Width;
int height = image.Height;
Bgra32[] pixels = new Bgra32[width * height];
image.CopyPixelsTo(pixels);

Lossless vs Lossy JPEG 2000

AspectJPEG 2000 LosslessJPEG 2000 Lossy
Transfer SyntaxJpeg2000Lossless (1.2.840.10008.1.2.4.90)Jpeg2000Lossy (1.2.840.10008.1.2.4.91)
Image qualityPixel-perfect — identical to originalVisually similar, some data permanently lost
Compression ratioTypically 2:1 to 3:1Typically 10:1 to 30:1 or higher
Best forDiagnostic archival, legal records, primary readingPreliminary review, telemedicine, network transmission
Round-trip safeYesNo — re-encoding further degrades quality

High-Throughput JPEG 2000 (HTJ2K)

HTJ2K (ISO/IEC 15444-15) replaces the slow arithmetic coder of JPEG 2000 with a faster block coder. It keeps the same wavelet transform, progression orders and quality, and decodes and encodes several times faster. Aspose.Medical implements all three DICOM HTJ2K transfer syntaxes in pure .NET, for monochrome and color images, and transcodes between HTJ2K and every other supported syntax:

  • HTJ2KLossless (1.2.840.10008.1.2.4.201) — lossless only
  • HTJ2KLosslessRPCL (1.2.840.10008.1.2.4.202) — lossless with RPCL progression order
  • HTJ2K (1.2.840.10008.1.2.4.203) — lossy or lossless

Transcode JPEG 2000 to HTJ2K and back - C#

// Transcode a JPEG 2000 file to HTJ2K, and back to classic JPEG 2000
DicomFile j2kFile = DicomFile.Open("j2k_lossless.dcm");
DicomFile htj2kFile = j2kFile.Transcode(TransferSyntax.HTJ2KLossless);
htj2kFile.Save("htj2k_lossless.dcm");

// HTJ2K with RPCL progression order, lossless
DicomFile rpclFile = j2kFile.Transcode(TransferSyntax.HTJ2KLosslessRPCL);
rpclFile.Save("htj2k_rpcl.dcm");

// HTJ2K lossy
DicomFile htj2kLossy = j2kFile.Transcode(TransferSyntax.HTJ2K);
htj2kLossy.Save("htj2k_lossy.dcm");

// Any HTJ2K file decodes back to an uncompressed transfer syntax
DicomFile uncompressed = htj2kFile.Transcode(TransferSyntax.ExplicitVrLittleEndian);
uncompressed.Save("decoded.dcm");
  

Support and Learning Resources