How to Read Pixel Data when Pixel Representation=1

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

How to Read Pixel Data when Pixel Representation=1

#1 Post by samee »

Hello there.

I am trying to use the DCMTK API to read some dicom files. The following piece of code works when the Pixel Representation value is 0 (uncompressed image, as I understand). However, when I am trying to read an image with pixel representation value 1, I get an error: Pixel representation cannot be changed

Code: Select all

    auto dcm_ff = DcmFileFormat();
    dcm_ff.loadFile("/mnt/hdd8/axle/dev/dcmtk_reader/data/pydicom-data/data/693_J2KR.dcm");
    auto dcm_tag_pixel_data = DcmTagKey(0x7fe0,0x0010) ;
    DcmElement* pixel_data_ptr = nullptr;
    auto stat = dcm_ff.getDataset()->findAndGetElement(DCM_PixelData, pixel_data_ptr);
    DcmPixelData* pixel_data = OFreinterpret_cast(DcmPixelData*, pixel_data_ptr);
    std::cout << stat.text() << std::endl;
    uint32_t frame_size = 0;
    pixel_data->getUncompressedFrameSize(dcm_ff.getDataset(),frame_size);
    frame_size % 2 == 0 ? frame_size = frame_size : frame_size = frame_size + 1;
    auto buffer = std::vector<uint16_t>(frame_size);
    uint32_t start_fragment = 0;
    OFString decompressed_color_model;
    uint32_t frame_no = 0;


    auto status = pixel_data->getUncompressedFrame(dcm_ff.getDataset(), 
                                    frame_no,  
                                    start_fragment, 
                                    buffer.data(),
                                    frame_size,
                                    decompressed_color_model, NULL);

    std::cout << status.text()<<std::endl;

The images that I am using are from pydicom-data repository: https://github.com/pydicom/pydicom-data.
Can anyone please tell me what should I do differently to read images with pixel representation value of 1?

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to Read Pixel Data when Pixel Representation=1

#2 Post by Michael Onken »

Hi,

Looking at the filename 693_J2KR the file is maybe compressed using JPEG 2000? The open source DCMTK does not support to decompress this.

The error message has nothing to do with the tag Pixel Representation.

Best regards,
Michael

samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

Re: How to Read Pixel Data when Pixel Representation=1

#3 Post by samee »

Yes, the image is compressed with JPEG200. Here is the tag value.

Code: Select all

(0002, 0010) Transfer Syntax UID                 UI: JPEG 2000 Image Compression (Lossless Only)
Is there a way to find the list of the supported compressions for open source DCMTK?

Thanks,

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to Read Pixel Data when Pixel Representation=1

#4 Post by Michael Onken »

No, I don't think there is a list. From the top of my head

- All classic JPEG transfer syntaxes (use dcmcjpeg/dcmdjpeg for compression/decompression)
- Deflated (dcmconv for compression and decompression)
- RLE (dcmcrle/dcmdrle)
- JPEG-LS variants (dcmcjpls/dcmdjpls)
- All uncompressed: dcmconv

- JPEG 2000 transfer syntaxes are available as a commercial extension from OFFIS (google dcmjp2k), there is also a evaluation version available on request.

BR Michael

samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

Re: How to Read Pixel Data when Pixel Representation=1

#5 Post by samee »

Thanks for the reply.
However, I still think something is wrong in my code. I picked another image from the pydicom-data repository (emri_small_jpeg_ls_lossless.dcm) which has the following properties.

Code: Select all

(0002, 0010) Transfer Syntax UID                 UI: JPEG-LS Lossless Image Compression
(0002, 0012) Implementation Class UID            UI: 1.2.826.0.1.3680043.2.1143.107.104.103.115.2.2.4
(0002, 0013) Implementation Version Name         SH: 'GDCM 2.2.4'
(0002, 0016) Source Application Entity Title     AE: 'gdcmconv'
(0028, 0002) Samples per Pixel                   US: 1
(0028, 0004) Photometric Interpretation          CS: 'MONOCHROME2'
(0028, 0008) Number of Frames                    IS: '10'
(0028, 0010) Rows                                US: 64
(0028, 0011) Columns                             US: 64
(0028, 0100) Bits Allocated                      US: 16
(0028, 0101) Bits Stored                         US: 12
(0028, 0102) High Bit                            US: 11
(0028, 0103) Pixel Representation                US: 0
(0028, 0301) Burned In Annotation                CS: 'NO'
(0028, 2110) Lossy Image Compression             CS: '00'
(0028, 9001) Data Point Rows                     UL: 1
(0028, 9002) Data Point Columns                  UL: 0
(2050, 0020) Presentation LUT Shape              CS: 'IDENTITY'
(7fe0, 0010) Pixel Data                          OW: Array of 40474 elements
For this file also, I get the same error message (Pixel representation cannot be changed), when I call getUncompressedFrame(...).

Also, I am fairly new to Dicom and dcmtk toolkit. I am working creating a data streamer that can feed Dicom pixel data to a downstream ML model. I am trying to support as many as Dicom formats possible using dcmtk.

-Samee

samee
Posts: 17
Joined: Thu, 2023-03-30, 15:27

Re: How to Read Pixel Data when Pixel Representation=1

#6 Post by samee »

I think I have figured out the issue. I needed to register the codecs to be able to read the compressed image.

Adding the following lines before everything seems to work.

Code: Select all

    DJDecoderRegistration::registerCodecs(); 
    DJLSDecoderRegistration::registerCodecs();
    DcmRLEDecoderRegistration::registerCodecs();

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to Read Pixel Data when Pixel Representation=1

#7 Post by Michael Onken »

Hi,

exactly :)

BR,
Michael

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest