Dicom image if failing to render into BMP

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Dicom image if failing to render into BMP

#1 Post by bluergost »

Hi,
I am trying to render a dicom image. I have tried using the programmatic approach and also the console application. But I am getting the following error.

The output of the programmatic approach is:
E: can't change to unencapsulated representation for pixel data
E: can't determine 'PhotometricInterpretation' of decompressed image
E: mandatory attribute 'PhotometricInterpretation' is missing or can't be determined
The output when I use dcmj2pnm:
E: can't change to unencapsulated representation for pixel data
E: can't determine 'PhotometricInterpretation' of decompressed image
E: mandatory attribute 'PhotometricInterpretation' is missing or can't be determined
F: Missing attribute
The output when I use dcmp2pgm:
E: can't change to unencapsulated representation for pixel data
E: can't determine 'PhotometricInterpretation' of decompressed image
E: can't convert input pixel data
F: Can't open input file(s).
Here is the code I am trying to render the file:

Code: Select all

bool renderImage(char* dicomFilePath, char* renderedFilePath)
{
    DicomImage* dicomImage = new DicomImage(dicomFilePath);

    if (dicomImage != NULL)
    {
        if (dicomImage->getStatus() == EIS_Normal)
        {
            if (dicomImage->writeBMP(renderedFilePath, 8))
            {
                return true;
            }
        }
    }
    return false;
}
I am still new to using this software and inexperienced in using C++. But from reading the message and seeing questions posted by others having a similar issue I am guessing that the image does not have the required information for rendering the image.
But what confuses me is that other Dicom Viewers are able to render the image just fine. Also Fo-Dicom a C# dicom library can also render the image.

So, I was wondering if I was making some mistakes.

Thank You in advance for your help.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Dicom image if failing to render into BMP

#2 Post by J. Riesmeier »

What is the Transfer Syntax of the DICOM dataset?

bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Re: Dicom image if failing to render into BMP

#3 Post by bluergost »

J. Riesmeier wrote: Tue, 2023-01-31, 09:07 What is the Transfer Syntax of the DICOM dataset?
Transfer Syntax UID is 1.2.840.10008.1.2.4.90 (JPEG 2000 Image Compression(Lossless Only))

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Dicom image if failing to render into BMP

#4 Post by J. Riesmeier »

Then, the answer is easy: as you can read in the documentation, the public DCMTK does not support JPEG 2000 compression (e.g., there is a list of supported Transfer Syntaxes in the manpage of each tool).
If you want to decompress JPEG 2000 compressed images (or compress DICOM images with JPEG 2000), you need e.g. DCMJP2K, an extension of the DCMTK that has to be licensed separately.

bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Re: Dicom image if failing to render into BMP

#5 Post by bluergost »

J. Riesmeier wrote: Tue, 2023-01-31, 09:33 Then, the answer is easy: as you can read in the documentation, the public DCMTK does not support JPEG 2000 compression (e.g., there is a list of supported Transfer Syntaxes in the manpage of each tool).
If you want to decompress JPEG 2000 compressed images (or compress DICOM images with JPEG 2000), you need e.g. DCMJP2K, an extension of the DCMTK that has to be licensed separately.
So, I have to chain the conversion.
<dicom file with compressed JPEG 2000 image> → dcmdjp2k → <dicom file with decompressed JPEG 2000 image> → dcm2pnm → <bmp file>.

I have just now tried this approach using console applications. The jpeg decompression works fine. I am able to open the image at this stage.
dcm2pnm also does not show any errors during the rendering to bmp image.
But I can not view the resulting bmp image in any of the viewers.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Dicom image if failing to render into BMP

#6 Post by J. Riesmeier »

So, I have to chain the conversion.
<dicom file with compressed JPEG 2000 image> → dcmdjp2k → <dicom file with decompressed JPEG 2000 image> → dcm2pnm → <bmp file>.
This is correct, unless you extend the command line tool dcm2pnm with JPEG 2000 support, which is rather easy if you've licenced DCMJP2K.
I have just now tried this approach using console applications. The jpeg decompression works fine. I am able to open the image at this stage.
dcm2pnm also does not show any errors during the rendering to bmp image.
But I can not view the resulting bmp image in any of the viewers.
Did you specify the output format "BMP" with dcm2pnm's option --write-bmp (+wb)? If not, you should know that this tool creates PGM/PNM images by default (as you can read in the documentation and also in the --help output of this tool). This is also where the name of the tool comes from.

bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Re: Dicom image if failing to render into BMP

#7 Post by bluergost »

J. Riesmeier wrote: Tue, 2023-01-31, 10:03
So, I have to chain the conversion.
<dicom file with compressed JPEG 2000 image> → dcmdjp2k → <dicom file with decompressed JPEG 2000 image> → dcm2pnm → <bmp file>.
This is correct, unless you extend the command line tool dcm2pnm with JPEG 2000 support, which is rather easy if you've licenced DCMJP2K.
I have just now tried this approach using console applications. The jpeg decompression works fine. I am able to open the image at this stage.
dcm2pnm also does not show any errors during the rendering to bmp image.
But I can not view the resulting bmp image in any of the viewers.
Did you specify the output format "BMP" with dcm2pnm's option --write-bmp (+wb)? If not, you should know that this tool creates PGM/PNM images by default (as you can read in the documentation and also in the --help output of this tool). This is also where the name of the tool comes from.
Thank you, not using the flag was the issue. Previously I tried without using any flag on another image and I was able to open the rendered image. So, I didn't think the flag would be the problem :oops: .

Also, what is the +wb flag for? I checked the documentation(https://support.dcmtk.org/docs/dcm2pnm.html). Couldn't find the flag there. Also, the console app threw error when I tried to use it.

I am guessing for extending the tool you need the source code access package.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Dicom image if failing to render into BMP

#8 Post by J. Riesmeier »

Sorry for the confusion, +wb was a typo. I wanted to write +ob, which is just the short version of --write-bmp.
I am guessing for extending the tool you need the source code access package.
Correct.

bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Re: Dicom image if failing to render into BMP

#9 Post by bluergost »

J. Riesmeier wrote: Tue, 2023-01-31, 10:32 Sorry for the confusion, +wb was a typo. I wanted to write +ob, which is just the short version of --write-bmp.
I am guessing for extending the tool you need the source code access package.
Correct.
I understand, Thank you for the help :mrgreen:

Post Reply

Who is online

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