How to write DICOM file with Sint16 pixel representation

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
artemmikheev
Posts: 32
Joined: Mon, 2018-11-12, 20:01

How to write DICOM file with Sint16 pixel representation

#1 Post by artemmikheev »

Hi there,
I had no problem in the past writing the DICOM file using unsigned Uint16 type.
Now I try to write a DICOM file with Sint16 datatype (and Rescale\Intercept).
I tried 2 different ways and both give me various trouble in my scenario:


What am I doing wrong? Is there a better way? Thank you.

a)
Sint16* pixdata;
DcmFileFormat* FF;
.....
DcmDataSet* dDS = FF->getDataSet();
BytesPerPixel = 2;
dDS->putAndInsertUint8Array(DCM_PixelData,(Uint8*)(pixdata),NumPix*BytesPerPixel );
dDS->putAndInsertUint16( DCM_PixelRepresentation,EPR_Sint16 );
....
FF->saveFile( Name,...

b)
Sint16* pixdata;
DcmFileFormat* FF;
.....
DcmDataSet* dDS = FF->getDataSet();
dDS->putAndInsertSint16Array(DCM_PixelData,(Sint16*)(pixdata),NumPix );
..............
FF->saveFile( Name,...

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

Re: How to write DICOM file with Sint16 pixel representation

#2 Post by Michael Onken »

Hi,

Integer Pixel Data always has data type OB or OW and the only methods that work on that are putAndInsertUint8() or. ..16 respectively.

So you have to prepare your Sint16 array and insert it using putAndInsertUint16() by casting it to Uint16. In the end its just raw data and the reader must interpret it by looking at tags like Bits Allocated/Stored, High Bit (...) and Pixel Representation where the latter tells whether to interpret values signed (Pixel Representation=1) or unsigned (=0).

Best regards,
Michael

artemmikheev
Posts: 32
Joined: Mon, 2018-11-12, 20:01

Re: How to write DICOM file with Sint16 pixel representation

#3 Post by artemmikheev »

Thank you so much - you advice worked.
Confusion came from using the "representation" from the DicomImage object

DicomImage* Img;
...
const DiPixel *obp = Img->getInterData();
EP_Representation PixRep = obp->getRepresentation();

Now it is clear that the DCM_PixelRepresentation {0,1} is entirely different from the EP_Representation.

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

Re: How to write DICOM file with Sint16 pixel representation

#4 Post by Michael Onken »

Great, happy that it worked. I could have stated the difference to EP_Representation more clearly.

Best regards,
Michael

Post Reply

Who is online

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