All other questions regarding DCMTK
Moderator: Moderator Team
vignesh
Posts: 14 Joined: Mon, 2020-01-20, 11:44
#1
Post
by vignesh » Wed, 2024-08-14, 11:58
Hi,
I used DCMTK-3.6.4 to decompress a DICOM file from JPEG-LS Lossless Image Compression to LittleEndianExplicit. However, when I called the
chooseRepresentation function, the application crashed for the attached DICOM file.
Here is what I have tried in my application.
Sample code:
Code: Select all
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcpixel.h"
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcddirif.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcrledrg.h"
#include "dcmtk/dcmdata/dcrleerg.h"
#include "dcmtk/dcmjpls/djlsutil.h"
#include "dcmtk/dcmjpls/djdecode.h"
#include "dcmtk/dcmjpls/djcodecd.h"
#include "dcmtk/dcmjpls/djcodece.h"
#include "dcmtk/dcmjpls/djcparam.h"
#include "dcmtk/dcmjpls/djencode.h"
#include "dcmtk/ofstd/ofcond.h"
#include "dcmtk/ofstd/ofdefine.h"
#include "dcmtk/ofstd/ofstd.h"
#include "dcmtk/dcmimage/diregist.h"
#include "dcmtk/dcmjpeg/djdecode.h"
#include "dcmtk/dcmjpeg/djencode.h"
#include "dcmtk/oflog/oflog.h"
int main()
{
OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
DcmRLEDecoderRegistration::registerCodecs();
DJDecoderRegistration::registerCodecs();
DJLSDecoderRegistration::registerCodecs();
DcmFileFormat fileFormat;
std::string filePath = "filepath/img.dcm";
OFCondition error = fileFormat.loadFile(filePath.c_str());
if (error.bad())
{
std::cout << "Load Failed" << std::endl;
return 0;
}
else
std::cout << "File Loading succeed" << std::endl;
DcmDataset *dataset = fileFormat.getDataset();
error = dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
if (error.bad())
std::cout<<"Decompress Failed" << std::endl;
else
std::cout<<"Decompress succeed" << std::endl;
return 0;
}
Log:
Code: Select all
D: DcmMetaInfo::checkAndReadPreamble() TransferSyntax="Little Endian Explicit"
D: DcmDataset::read() TransferSyntax="JPEG-LS Lossless"
File Loading Success
D: JPEG-LS decoder processes frame 1
How to fix this issue?
Thanks!
Last edited by
vignesh on Tue, 2024-08-27, 06:36, edited 1 time in total.
Michael Onken
DCMTK Developer
Posts: 2073 Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:
#2
Post
by Michael Onken » Wed, 2024-08-14, 14:21
Hi,
this is what your program ("jpgls") returns on my computer running the current version if DCMTK (master branch as of
https://github.com/DCMTK/dcmtk/ ):
Code: Select all
❯ bin/jpegls
D: DcmDataDictionary: Loading file: /home/michael/data/builds/install/dcmtk_linux_368/share/dcmtk-3.6.8/dicom.dic
D: DcmMetaInfo::checkAndReadPreamble() TransferSyntax="Little Endian Explicit"
D: DcmDataset::read() TransferSyntax="JPEG-LS Lossless"
File Loading succeed
D: JPEG-LS decoder processes frame 1
W: invalid value for PlanarConfiguration (0028,0006), should be "0"
W: Color Transformation 1 is a non-standard HP/JPEG-LS extension
D: different planar configuration in JPEG-LS bitstream, converting to "1"
Decompress succeed
❯ bin/jpegls
I just removed the line DJDecoderRegistration::registerCodecs() to make it easier for me to compile. But that should not make a difference.
Did you try latest DCMTK code? If not, please do so.
Best regards,
Michael
vignesh
Posts: 14 Joined: Mon, 2020-01-20, 11:44
#3
Post
by vignesh » Tue, 2024-08-20, 06:59
Hi,
Thanks for your reply.
I checked the sample code in DCMTK-3.6.8, and it works fine. I also used dcmdjpls.exe in DCMTK-3.6.4 to decompress the DICOM file from JPEG-LS Lossless to LittleEndianExplicit.
The decompression was successful, and the decompressed file was saved correctly.
dcmdjpls.exe output :
Code: Select all
D:\dcmtk-3.6.4\dcmtk3.6.4\bin\Release>.\dcmdjpls.exe -d -v "D:\Dicom_images\JPEG_LS\13.dcm" "D:\Dicom_images\JPEG_LS\output\13_output_364.dcm"
I: reading input file D:\Dicom_images\JPEG_LS\13.dcm
I: decompressing file
W: different planar configuration in JPEG stream, converting to "1"
I: creating output file D:\Dicom_images\JPEG_LS\output\13_output_364.dcm
I: conversion successful
However, when I tried the sample code with DCMTK-3.6.4, the application crashed. Despite this, the sample DICOM file was successfully decompressed using dcmdjpls.exe.
Is there anything missing in my sample code?
Code: Select all
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcpixel.h"
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcddirif.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcdatset.h"
#include "dcmtk/dcmdata/dcrledrg.h"
#include "dcmtk/dcmdata/dcrleerg.h"
#include "dcmtk/dcmjpls/djlsutil.h"
#include "dcmtk/dcmjpls/djdecode.h"
#include "dcmtk/dcmjpls/djcodecd.h"
#include "dcmtk/dcmjpls/djcodece.h"
#include "dcmtk/dcmjpls/djcparam.h"
#include "dcmtk/dcmjpls/djencode.h"
#include "dcmtk/ofstd/ofcond.h"
#include "dcmtk/ofstd/ofdefine.h"
#include "dcmtk/ofstd/ofstd.h"
#include "dcmtk/dcmimage/diregist.h"
#include "dcmtk/dcmjpeg/djdecode.h"
#include "dcmtk/dcmjpeg/djencode.h"
#include "dcmtk/oflog/oflog.h"
int main()
{
OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
DcmRLEDecoderRegistration::registerCodecs();
DJLSDecoderRegistration::registerCodecs();
DcmFileFormat fileFormat;
std::string filePath = "D:\\Dicom_images\\JPEG_LS\\13.dcm";
OFCondition error = fileFormat.loadFile(filePath.c_str());
if (error.bad())
{
std::cout << "Load Failed" << std::endl;
}
else
std::cout << "File Loading succeed" << std::endl;
DcmDataset *dataset = fileFormat.getDataset();
if (!dataset)
{
std::cout << "Dataset is Null" << std::endl;
}
E_TransferSyntax xfer = EXS_LittleEndianExplicit;
error = dataset->chooseRepresentation(xfer, NULL);
if (error.bad())
{
std::cout << "Decompress Failed" << std::endl;
}
else
std::cout<<"Decompress succeed" << std::endl;
std::string outputPath = "D:\\Dicom_images\\JPEG_LS\\output\\13_output_364.dcm";
error = fileFormat.saveFile(outputPath.c_str(), EXS_LittleEndianExplicit);
if (error.bad())
{
std::cout << "Save Failed: " << error.text() << std::endl;
}
else
{
std::cout << "Decompressed file saved successfully to: " << outputPath << std::endl;
}
return 0;
}
How to fix this issue?
Thanks
Marco Eichelberg
OFFIS DICOM Team
Posts: 1507 Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:
#4
Post
by Marco Eichelberg » Mon, 2024-08-26, 15:41
I cannot see anything obviously wrong in your code. If the code works with DCMTK 3.6.8 but crashes with 3.6.4, then a bug fix in DCMTK is probably the cause of the difference in behavior. If you cannot migrate to DCMTK 3.6.8, then you will have to check each commit that affected the dcmjpls module to see if this may be the bugfix you are looking for (i.e. clone the git repository at
http://git.dcmtk.org/ ). Unfortunately, 3.6.4 is six years old now, so there will be many commits to check.
Furthermore, if your sample file is not fully anonymized, I would suggest that you remove the Google drive link.
vignesh
Posts: 14 Joined: Mon, 2020-01-20, 11:44
#5
Post
by vignesh » Tue, 2024-08-27, 06:35
Thank you. I will upgrade to the latest version of DCMTK.
Users browsing this forum: No registered users and 1 guest