Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#1 Post by Arnoj.Saha »

We are trying to import an IVUS (Intra vascular ultrasound) Dicom file to our application using DCMTK library.
While importing, we have a flow where the DicomImage::Init() method in dcmimage.cc gets called.
What we have seen in the function is that we have implementation for DiMono1Image and DiMono2Image but nothing specific to RGB.
Note: When the tag “Photometric Interpretation” (0028,0004) has MONOCHROME2, import of the dcm file is successful but when it is RGB the import fails

Currently, we are using DCMTK library and the constructor “DicomImage(string filepath)” (in dcmimage.h) to construct DicomImage from a dicom file with given path.
image = std::make_unique<DicomImage>(path.string().c_str());
But the above function call is able to construct a DicomImage object only if the “Photometric Interpretation” tag is MONOCHROME2 and fails to construct if it is RGB.

My question:
Is there a constructor which can create a DicomImage object (using DicomImage in dcmimage.h) with the tag “Photometric Interpretation” being RGB?
Is there a way we can also import DCM file which has the tag “Photometric Interpretation” (0028,0004) as RGB?
Both above questions are abviously related.

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

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#2 Post by J. Riesmeier »

Yes, the DicomImage also supports processing of color images, such as those with a photometric interpretation of "RGB". However, for historical reasons, the support for monochrome and color images is split into two libraries: dcmimgle and dcmimage. In order to register support for color images to the DicomImage class you should include the header file "dcmtk/dcmimage/diregist.h" into your program (see "dcmimage/apps/dcm2pnm.cc" for an example) and link the dcmimage library to it.

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#3 Post by Arnoj.Saha »

Thank you for your reply.
My findings:
I included "diregist.h" in my code (not dcmtk library code) and tried to call:
DiImage *createImage(const DiDocument *docu,const EI_Status status,const EP_Interpretation photo);
DiMonoPixel *createMonoImageData(const DiColorImage *image,const double red,const double green,const double blue);

diregist.h has only above two functions.

None of them are used in "dcm2pnm.cc".
Also, none of them seem to create DicomImage object by taking in a "string filepath" parameter.
I need to create a DicomImage object by taking a in a "string filepath" parameter.

Is there a possibility that I can work with you in a call? This will help immensely.
Please let me know if its possible.

Best regards.

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

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#4 Post by Michael Onken »

As Jörg said, it is all "said" in dcm2pnm. By including diregist.h support of color images is automatically enabled. The API calls stay the same as without diregist.h.

You only have to follow the lines dcm2pnm::905 ff.

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#5 Post by Arnoj.Saha »

I included "dcmtk/dcmimage/diregist.h" and kept everything else same. With this I was able to create a DicomImage with DicomImage constructor.
But after creating the image, when I am viewing the image, I see the image RGB-IVUS-after-including-deregist.PNG (Not able to attach screenshots - How can I attach?) which opens an image but kind of looks zoomed in or something.

Where as same dicom file when I open in MicroDicomViewer, I see the image RGB-IVUS-MicroDicomViewer.PNG (Not able to attach screenshots - How can I attach?) which is proper image.

Are we sure we do not have to do anything else?

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

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#6 Post by J. Riesmeier »

You could upload the PNG images to another public server and add links to your posting.

By the way, what is the output of the dcm2pnm tool for this particular DICOM image?

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#7 Post by Arnoj.Saha »

We have a way to send the screenshots via secure email from our company.
Can you please share your email id so that I can share the screenshots?

BTW, dcm2pnm is just a C++ file in the repo that we have. Do we have a command line tool for dcm2pnm which I can run?
Where can I get that?

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

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#8 Post by J. Riesmeier »

You could send the files by email to bugs/at/dcmtk/dot/org.

Of course, when you download the source code package, dcm2pnm is provided as a source file. You could either compile and link the DCMTK or you could download pre-compiled binaries, e.g. here: https://dcmtk.org/en/dcmtk/dcmtk-tools/

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#9 Post by Arnoj.Saha »

I have sent the screenshots in an email.

Could you please have a look and give suggestions on why the image may look different when we include "dcmtk/dcmimage/diregist.h" and import the IVUS dicom file (with photometric interpretation as RGB)?

Regards.

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#10 Post by Arnoj.Saha »

I installed dcmtk in Debian environment using:
sudo apt install dcmtk

Then I ran this command:
dcm2pnm Ivus-KUYRJER4 DICOM-RGB.PNG

After that I copied DICOM-RGB.PNG in my Windows environment and tried opening.
It gives an error:
"It looks like we dont support the file format"

Also sent you email with the screenshots as I said in previous comment.

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

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#11 Post by J. Riesmeier »

By default, dcm2pnm creates PGM/PPM images as output. For the PNG format, you need to specify option --write-png (+on). See documentation for details.

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#12 Post by Arnoj.Saha »

Posting the replies from Jorg and Marco for continuity:
Jorg:
I suspect that the DICOM encoding is incorrect. So could you please also send us the original DICOM file (possibly in anonymized form) for further analysis.
Marco:
Hi Arnoj,

> I suspect that the DICOM encoding is incorrect. So could you please also send > us the original DICOM file (possibly in anonymized form) for further analysis.

More specifically, the image looks as if the value of

(0028,0006) PlanarConfiguration

is wrong. It is will possible that the MicroDicomViewer has a built-in workaround that silency fixes the problem. This kind of problem is often the result of a compression/decompression cycle with a faulty decoder.

My comment:
Since I am not able to send the DICOM file over email, I checked that:
(0028,0006) PlanarConfiguration is 0 in the original DICOM file.
I shared the screenshots in email since they cannot be attached here.

Any suggestions?
NOTE: We have some reservations to send the Dicom file since it is taken from a clinical site and not our own produced data.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1437
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#13 Post by Marco Eichelberg »

I have looked at the anonymized sample file, and it seems to be perfectly OK. dcm2pnm and other tools based on dcmimage can correctly process the image. This means that there must be some bug in the code that uses DicomImage. Are you taking into account that DicomImage::getOutputData() delivers a different kind of bitmap in the case of color images? See https://support.dcmtk.org/docs/classDic ... 0fcd60258e

When called as getOutputData(8), the bitmap will contain one byte per pixel in the case of a monochrome image, and three bytes per pixel (R, G, B) in the case of a color image.

Arnoj.Saha
Posts: 13
Joined: Fri, 2023-05-05, 09:34

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#14 Post by Arnoj.Saha »

I have done some analysis on the 4th parameter of below function call:
int DicomImage::getOutputData (void * buffer, const unsigned long size,
const int bits = 0, const unsigned long frame = 0, const int planar = 0)

When we pass the planar as 1 (which denotes the planar configuration tag), we are able to get the returned buffer in a way which we are able to display correctly.
(In the dicom file sent to you, you can see the planar Configuration tag is 0)

Any comments from your side on why when we pass planar as 1 to above function, we can render it correctly and when we pass planar as 0, we cannot render it properly?

Thanks for your help.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1437
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Does DCMTK support creating DicomImage object if the dcm file has "Photometric Interpretation" as RGB?

#15 Post by Marco Eichelberg »

Any comments from your side on why when we pass planar as 1 to above function, we can render it correctly and when we pass planar as 0, we cannot render it properly?
Well, apparently you are correctly interpreting the output data in the case of planar configuration 1 (color-by-plane), but not in the case of planar configuration 0 (color-by-pixel).
This parameter describes the format of the output data, not the format of the input data.

Post Reply

Who is online

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