I have been using the DCMTK for the last couple months. Recently, I have been having trouble with compressing a DICOM image file with lossless JPEG. I have been following the code example at https://support.dcmtk.org/docs/mod_dcmjpeg.html, but I am still having problems. When calling the "chooseRepresentation" method of DcmDataset, I receive the OFCondition text "E: Unable to choose representation: Pixel representation cannot be changed". Below I have included the code snippet where I am seeing this issue. Note that I am calling the "newFileFormat.writeXML(std::cout)" method to show the contents of the dataset. The output to std::cout is also included below:
Code: Select all
// Compress previously-created DICOM file with lossless JPEG and create new DICOM file
// Register JPEG codecs
DJEncoderRegistration::registerCodecs();
DcmFileFormat newFileFormat;
if (newFileFormat.loadFile(dcmFileNameOF).good()) {
newFileFormat.writeXML(std::cout);
DcmDataset* newDataset = newFileFormat.getDataset();
DcmItem* metaInfo = newFileFormat.getMetaInfo();
DJ_RPLossless params;
// Create lossless JPEG version of the dataset
result = newDataset->chooseRepresentation(EXS_JPEGProcess14SV1, ¶ms);
if (result.bad()) {
DCMNET_ERROR("Unable to choose representation: " << result.text());
}
if (newDataset->canWriteXfer(EXS_JPEGProcess14SV1)) {
// Store in lossless JPEG format
qDebug() << "Creating lossless version!";
newFileFormat.saveFile(testDcmFileNameOF, EXS_JPEGProcess14SV1);
}
}
DJEncoderRegistration::cleanup();
"newFileFormat.writeXML(std::cout)" output:
<file-format>
<meta-header xfer="1.2.840.10008.1.2.1" name="Little Endian Explicit">
<element tag="0002,0000" vr="UL" vm="1" len="4" name="FileMetaInformationGroupLength">210</element>
<element tag="0002,0001" vr="OB" vm="1" len="2" name="FileMetaInformationVersion" binary="hidden"></element>
<element tag="0002,0002" vr="UI" vm="1" len="30" name="MediaStorageSOPClassUID">1.2.840.10008.5.1.4.1.1.77.1.1</element>
<element tag="0002,0003" vr="UI" vm="1" len="60" name="MediaStorageSOPInstanceUID">1.2.276.0.7230010.3.1.4.1532761246.3195384.1659625141.276059</element>
<element tag="0002,0010" vr="UI" vm="1" len="22" name="TransferSyntaxUID">1.2.840.10008.1.2.4.50</element>
<element tag="0002,0012" vr="UI" vm="1" len="28" name="ImplementationClassUID">1.2.276.0.7230010.3.0.3.6.7</element>
<element tag="0002,0013" vr="SH" vm="1" len="16" name="ImplementationVersionName">OFFIS_DCMTK_367</element>
</meta-header>
<data-set xfer="1.2.840.10008.1.2.4.50" name="JPEG Baseline">
<element tag="0008,0016" vr="UI" vm="1" len="30" name="SOPClassUID">1.2.840.10008.5.1.4.1.1.77.1.1</element>
<element tag="0008,0018" vr="UI" vm="1" len="60" name="SOPInstanceUID">1.2.276.0.7230010.3.1.4.1532761246.3195384.1659625141.276059</element>
<element tag="0008,0020" vr="DA" vm="1" len="8" name="StudyDate">20220624</element>
E: Unable to choose representation: Pixel representation cannot be changed
Writing new file format contents:
<element tag="0008,0030" vr="TM" vm="1" len="4" name="StudyTime">5:48</element>
<element tag="0008,0050" vr="SH" vm="1" len="10" name="AccessionNumber">987654321</element>
<element tag="0008,0064" vr="CS" vm="1" len="4" name="ConversionType">WSD</element>
<element tag="0008,0080" vr="LO" vm="1" len="8" name="InstitutionName">HospTest</element>
<element tag="0008,0090" vr="PN" vm="1" len="8" name="ReferringPhysicianName">Dr. Test</element>
<element tag="0010,0010" vr="PN" vm="1" len="12" name="PatientName">PatientSteve</element>
<element tag="0010,0020" vr="LO" vm="1" len="10" name="PatientID">123456789</element>
<element tag="0010,0030" vr="DA" vm="1" len="10" name="PatientBirthDate">199610317</element>
<element tag="0010,0040" vr="CS" vm="1" len="2" name="PatientSex">M</element>
<element tag="0020,000d" vr="UI" vm="1" len="60" name="StudyInstanceUID">1.2.276.0.7230010.3.1.2.1532761246.3195384.1659625141.276058</element>
<element tag="0020,000e" vr="UI" vm="1" len="60" name="SeriesInstanceUID">1.2.276.0.7230010.3.1.3.1532761246.3195384.1659625141.276057</element>
<element tag="0020,0010" vr="SH" vm="1" len="6" name="StudyID">12346</element>
<element tag="0020,0011" vr="IS" vm="0" len="0" name="SeriesNumber"></element>
<element tag="0020,0013" vr="IS" vm="0" len="0" name="InstanceNumber"></element>
<element tag="0020,0020" vr="CS" vm="0" len="0" name="PatientOrientation"></element>
<element tag="0028,0002" vr="US" vm="1" len="2" name="SamplesPerPixel">3</element>
<element tag="0028,0004" vr="CS" vm="1" len="12" name="PhotometricInterpretation">YBR_FULL_422</element>
<element tag="0028,0006" vr="US" vm="1" len="2" name="PlanarConfiguration">0</element>
<element tag="0028,0010" vr="US" vm="1" len="2" name="Rows">130</element>
<element tag="0028,0011" vr="US" vm="1" len="2" name="Columns">195</element>
<element tag="0028,0100" vr="US" vm="1" len="2" name="BitsAllocated">8</element>
<element tag="0028,0101" vr="US" vm="1" len="2" name="BitsStored">8</element>
<element tag="0028,0102" vr="US" vm="1" len="2" name="HighBit">7</element>
<element tag="0028,0103" vr="US" vm="1" len="2" name="PixelRepresentation">0</element>
<sequence tag="7fe0,0010" vr="OB" card="2" name="PixelData">
<pixel-item len="0" binary="hidden"></pixel-item>
<pixel-item len="4020" binary="hidden"></pixel-item>
</sequence>
</data-set>
</file-format>
I'm not sure if there's something wrong with my DICOM file I'm extracting the dataset from. Does anyone have any suggestions?
Thanks,
Steve