Transcoding DICOM file
Transcoding DICOM file
DICOM files use various Transfer Syntaxes, which define how image data is encoded. To ensure compatibility across different systems, you may need to transcode (convert) a DICOM file from one transfer syntax to another.
Aspose.Medical provides a simple API to transcode DICOM files efficiently.
Transcode returns a new DICOM file and leaves the source file unchanged. Choose an output syntax whose encoder supports the source pixel layout and bit depth; decoding support alone does not make a syntax a valid encoding target. See supported transfer syntaxes. Lossy transcoding can change pixel values, and transcoding requires a license that enables this operation.
To transcode a DICOM file, please follow the steps below:
- Load an existing
DICOMfile. - To transcode the
DICOMfile to another format, use theAspose.Medical.Dicom.DicomFile.Transcode()method. - Save the transcoded file for further use.
// Load existing file
Aspose.Medical.Dicom.DicomFile dcm = DicomFile.Open("input.dcm");
// Transcode the loaded file to Jpeg 2000 Lossy Transfer Syntax.
Aspose.Medical.Dicom.DicomFile transcodedDcm = dcm.Transcode(TransferSyntax.Jpeg2000Lossy);
// Save the transcoded file
transcodedDcm.Save("output.dcm");
Transcoding to JPEG
Aspose.Medical encodes these JPEG transfer syntaxes:
JpegProcess1- JPEG Baseline (1.2.840.10008.1.2.4.50), lossy, for 8-bit monochrome and color images.JpegExtended24- JPEG Extended (1.2.840.10008.1.2.4.51), lossy, for monochrome images: 8-bit samples as 8-bit frames, and 16-bit samples with up to 12 stored bits as 12-bit frames.JpegProcess14andJpegProcess14Sv1- JPEG Lossless (1.2.840.10008.1.2.4.57and1.2.840.10008.1.2.4.70), lossless for images of 1 to 16 stored bits in 8-bit or 16-bit samples: the frames decode to exactly the source pixel values. Releases before 26.11 encoded these two transfer syntaxes with lossy JPEG.
// Load existing file
Aspose.Medical.Dicom.DicomFile dcm = DicomFile.Open("input.dcm");
// Transcode the loaded file to JPEG Lossless, First-Order Prediction Transfer Syntax.
Aspose.Medical.Dicom.DicomFile transcodedDcm = dcm.Transcode(TransferSyntax.JpegProcess14Sv1);
// Save the transcoded file
transcodedDcm.Save("output.dcm");
Transcoding to JPEG XL
Aspose.Medical supports the JPEG XL transfer syntaxes. Encoding is available for:
JpegXLLossless- lossless JPEG XL (1.2.840.10008.1.2.4.110).JpegXL- JPEG XL (1.2.840.10008.1.2.4.112); this encoder produces lossy output using XYB at distance 1.0. UseJpegXLLosslessfor lossless encoding.
JpegXLJpegRecompression (1.2.840.10008.1.2.4.111) can be decoded but not yet encoded, so it cannot be used as a transcoding target.
// Load existing file
Aspose.Medical.Dicom.DicomFile dcm = DicomFile.Open("input.dcm");
// Transcode the loaded file to JPEG XL Lossless Transfer Syntax.
Aspose.Medical.Dicom.DicomFile transcodedDcm = dcm.Transcode(TransferSyntax.JpegXLLossless);
// Save the transcoded file
transcodedDcm.Save("output.dcm");