Hi,
I have built an application that works with CT and PET scans. As I need to use HU and SUV values I extract the data using di.getInterData() which returns in some cases 16 bit and in other cases 32 bit representations of the images. I use getRepresentation() to determine the internal format correctly. I then re-insert the modified image arrays into the original DICOM structures using:
code = ds->putAndInsertUint16Array(DCM_PixelData, (Uint16 *)image->getMat()->data, image->getWidth() * image->getHeight(), OFTrue)
and
code = ds->putAndInsertUint32Array(DCM_PixelData, (UInt32 *)image->getMat()->data, image->getWidth() * image->getHeight(), OFTrue);
for 8 or 16 bit arrays the insertion is working fine and the modified images display fine.
but for 32 bit arrays the system returns an error with the text "Illegal call, perhaps wrong parameters"
the following also returns an error:
int memsize = 256*256*4;
UInt32 *mem = new UInt32[memsize];
code = ds->putAndInsertUint32Array(DCM_PixelData, mem, 256 * 256, OFTrue);
I have not been able to work out why this is not working, any pointers much appreciated.
Andrew
Problem re-inserting 32 bit image to a DICOM file
Moderator: Moderator Team
-
- DCMTK Developer
- Posts: 2049
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: Problem re-inserting 32 bit image to a DICOM file
Hi Andrew,
the DcmItem API that you are using offers calls for nearly all data types like Uint8, Uint32, OFString and so on. However, if the data type (VR) and the respective DCMTK class of the addressed attribute (e.g. Pixel Data) does not offer this call, the method will fail.
For Pixel Data, you must provide your data as Uint8 or Uint16 array. The main reason is that DICOM always stores pixel data in 8 bit or 16 bit chunks (at least for integer data), no matter whether the actual bit depth is (i.e. Bits Allocated in the DICOM file). Just cast your pixel data array to one of these data types and use the corresponding API call.
On the other hand, the dcmimage API that you are using (getInterData()) interprets the Pixel Data attribute based on its actual bit depths, i.e. it combines those 8 or 16 bit pixel cells in the right way to return the output data in a decent data type (like Uint32). However, as you also already found out I guess, dcmimage does not allow you to create DICOM images, or to replace the pixel data, i.e. its meant for reading or more specifically, rendering (e.g. for visualization) of the Pixel Data attribute. So you are on the right track to use the "low level" dcmdata API (e.g. DcmItem) instead, as you correctly did.
Best regards,
Michael
the DcmItem API that you are using offers calls for nearly all data types like Uint8, Uint32, OFString and so on. However, if the data type (VR) and the respective DCMTK class of the addressed attribute (e.g. Pixel Data) does not offer this call, the method will fail.
For Pixel Data, you must provide your data as Uint8 or Uint16 array. The main reason is that DICOM always stores pixel data in 8 bit or 16 bit chunks (at least for integer data), no matter whether the actual bit depth is (i.e. Bits Allocated in the DICOM file). Just cast your pixel data array to one of these data types and use the corresponding API call.
On the other hand, the dcmimage API that you are using (getInterData()) interprets the Pixel Data attribute based on its actual bit depths, i.e. it combines those 8 or 16 bit pixel cells in the right way to return the output data in a decent data type (like Uint32). However, as you also already found out I guess, dcmimage does not allow you to create DICOM images, or to replace the pixel data, i.e. its meant for reading or more specifically, rendering (e.g. for visualization) of the Pixel Data attribute. So you are on the right track to use the "low level" dcmdata API (e.g. DcmItem) instead, as you correctly did.
Best regards,
Michael
Re: Problem re-inserting 32 bit image to a DICOM file
Hi Michael,
Thanks for your very fast and helpful response.
Regards
Andrew
Thanks for your very fast and helpful response.
Regards
Andrew
Who is online
Users browsing this forum: Ahrefs [Bot], Baidu [Spider], Bing [Bot] and 1 guest