LEADTOOLS Support
Medical
Medical SDK Examples
HOW TO: Control J2K compression in DICOM Files
#1
Posted
:
Thursday, August 31, 2017 4:07:19 PM(UTC)
Groups: Registered
Posts: 119
Was thanked: 4 time(s) in 4 post(s)
Below you will find a basic C# code sample on how you can load in your DICOM then save it out to a JPEG2000 compression type which will greatly decrease the file size.
When doing this compression, you will be using the
DicomJpeg2000Options structure. Once you have your options initialized, then you can begin setting the options for the new DICOM file.
There are two main enumerations that will be used in this process:
- CompressionControl - Gets or sets the flag that indicates how to determine the resulting compression.
- CompressionRatio - Gets or sets the integer value that indicates the compression ratio to use.
Once you have these enumerations set for the
DicomJpeg2000Options you will need to give the options to the dataset itself.
Now you can use
ChangeTransferSyntax to change the transfer syntax of the data set.
Finally, you can save the data set using the
Save method.
With these setting I was able to compress a DICOM file from 854kb down to 36KB.
Code:
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();
}
Edited by moderator Friday, December 29, 2017 8:51:29 AM(UTC)
| Reason: Changed subject to better reflect content
Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Medical
Medical SDK Examples
HOW TO: Control J2K compression in DICOM Files
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.