putAndInsertSint16Array Problem

All other questions regarding DCMTK

Moderator: Moderator Team

Message
Author
guelfobianco
Posts: 4
Joined: Wed, 2005-02-09, 15:41

putAndInsertSint16Array Problem

#1 Post by guelfobianco »

Hello, In the code that follows I am trying to write signed short array to file Dicom

Code: Select all

short *pDataInt16 = new short[memsize/sizeof(short)];
unsigned long  m_imgAllSize = 256*256;
[...]
result = dataset->putAndInsertSint16Array(DCM_PixelData, (const Sint16*)pDataInt16, m_imgAllSize);
if (result.bad())
   AfxMessageBox((LPCTSTR)result.text());
Error message: Illegal Call, perhaps wrong parameters


if I change code and write

Code: Select all

[...]
result = dataset->putAndInsertUint16Array(DCM_PixelData, (const Uint16 *)pDataInt16, m_imgAllSize);
[...]
No error message, bat I write unsigned data. Unfortunately DCMTK example code not include "putAndInsertSint16Array".

Thanks a lot
with WindowsXP & Visual Studio .Net 2003
-------------------------------------------------
Bologna University - Italy

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

As you can read in the DICOM standard (part 6) "Pixel Data" can only be stored as OB (unsigned 8 bit) or OW (unsigned 16 bit). See part 5 for details on the encoding of pixel data.

Sic
Posts: 3
Joined: Fri, 2007-07-20, 16:21

#3 Post by Sic »

As I read in the DICOM standard 2007 version, both OB (A string of bytes) and OW (A string of 16-bit words) specify that "the encoding of the contents is specified by the negotiated Transfer Syntax".

With Pixel Representation (0028, 0103) equals "0001H", two?s complement integer can be the encoding of pixel data now. And I did see such example file from David Clunie's enhanced DICOM test dataset.

So is now the time to allow dataset->putAndInsertSint16Array(DCM_PixelData, ...)?
Last edited by Sic on Sat, 2011-02-12, 15:15, edited 2 times in total.

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

#4 Post by Marco Eichelberg »

So is now the time to allow dataset->putAndInsertSint16Array(DCM_PixelData, ...)?
No. You have to understand that the encoding of uncompressed DICOM pixel data has two distinct levels. The first level is the pixel cell, which is defined by BitsAllocated. The pixel data is actually a sequence of bits containing a list of cells, where each cell uses "BitsAllocated" bits, directly concatenated without any pad bits. This sequence of bits is then split into 8-bit or 16-bit fields and encoded as OB or OW (implies byte swapping on Big Endian architectures for OW). Note that typically the cell size is a multiple of 8, but this is not a requirement for all DICOM SOP classes. You might actually encounter 12-bit cells, although I am not aware of any commercial system producing such images. The second level is the cell content, as defined by BitsStored, HighBit, PixelRepresentation and, possibly the various (60xx,yyyy) Overlay attributes. Not all bits of the cell might actually be used for pixel data, some might be used for overlay data and some might be empty (used as pad bits). Only the bits actually used for pixel data (as defined by BitsStored and HighBit) must be interpreted as an integer number of "BitsStored" bits, either unsigned or 2-complement, and all further transformations are applied to this value. In particular you might very well find a 13-bit 2-complement integer number, and some manipulation will be needed to actually make that look like a signed integral number on whatever platform you use. For display purposes, all of this complexity is hidden when you use the dcmimage library (class DicomImage and related classes), for a good reason. It is not easy to completely understand and to correctly implement this rather complex encoding.

Sic
Posts: 3
Joined: Fri, 2007-07-20, 16:21

#5 Post by Sic »

I understand it's tricky to handle the read-in right, but users who beg for dataset->putAndInsertSint16Array(DCM_PixelData, ...) are most probably only trying to write out pure pixel data with no overlay etc., and I just think it would be nice if they can do this.

But even now users can still write signed integer array as pixel data with the current DCMTK interface by cheating:

Sint16 *data = new Sint16[...];
...
dataset->putAndInsertUint16(DCM_SamplesPerPixel, 1);
dataset->putAndInsertUint16(DCM_BitsAllocated, 16);
dataset->putAndInsertUint16(DCM_BitsStored, 16);
dataset->putAndInsertUint16(DCM_HighBit, 15);
dataset->putAndInsertUint16(DCM_PixelRepresentation, 1);
...
dataset->putAndInsertUint16Array(DCM_PixelData, (const Uint16*)data, ...);
Last edited by Sic on Sat, 2011-02-12, 15:15, edited 2 times in total.

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

#6 Post by Marco Eichelberg »

putAndInsertSint16Array() would only ever be useful for people encoding images with BitsAllocated=16, BitsStored=16, HighBit=15, PixelRepresentation=1. This is a rare special case and certainly not worth special support in the API. Casting the pixel data to Uint16 is not even cheating - in your case this is exactly the right thing to do: Asking the system to interpret the array which was filled with Sint16 (signed short) values as an OW array and encode it as such. This is how DICOM represents pixel data in this case.

Sic
Posts: 3
Joined: Fri, 2007-07-20, 16:21

#7 Post by Sic »

Thanks for the clarification. I need to save functional imaging calculation result in DICOM format. Besides scaling, sometimes save pixel data in signed short may be handy.

How sad double precision is not an option here. :cry:

ali.m.habib
Posts: 85
Joined: Sun, 2010-12-26, 17:34

#8 Post by ali.m.habib »

hi , I am facing the same problem i am trying to insert signed pixel data but it gives the same error when i use the putAndInsertSint16Array and when i used the putAndInsertUint16Array the result seems to be wrong , it's not as the original image .. can any one tell me the steps to overcome this problem ??

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

#9 Post by J. Riesmeier »

Did you also set PixelRepresentation to 1?

ali.m.habib
Posts: 85
Joined: Sun, 2010-12-26, 17:34

#10 Post by ali.m.habib »

yes i did

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

#11 Post by J. Riesmeier »

So what do you mean by the following:
when i used the putAndInsertUint16Array the result seems to be wrong
And, did you make sure that the unused bits are masked out (in case of BitsStored < BitsAllocated)?

ali.m.habib
Posts: 85
Joined: Sun, 2010-12-26, 17:34

#12 Post by ali.m.habib »

the bits stored is equal to the bits allocated it CT signed ,Monochrome2, 16 bitsstored , 16 bits allocated,& after insertion of the pixel data when applying the original ww and wl on the image it seems darker than the original image ..
i tried the above steps but they were useless , any suggestion

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

#13 Post by J. Riesmeier »

Is there a Modality LUT Transformation (e.g. Rescale Slope/Intercept) in the DICOM image? Is it really appropriate for the signed pixel data, i.e. is the output in Hounsfield Units (HU)? Also, depending on what you mean by "original" Window Center/Width, the VOI LUT Transformation might be appropriate or not.

ali.m.habib
Posts: 85
Joined: Sun, 2010-12-26, 17:34

#14 Post by ali.m.habib »

yes it contains Rescale slope and intercept but the pixel data after insertion is different that the original data , i was wondering if i can insert the pixel data by looping on the array and inserting it using putAndInsertSint16 ...

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

#15 Post by J. Riesmeier »

the pixel data after insertion is different that the original data
Then it shouldn't be surprising that the rendered output is also different - depending on your use case, of course.
i was wondering if i can insert the pixel data by looping on the array and inserting it using putAndInsertSint16
No, because putAndInsertSint16() is not applicable to the PixelData element, which has a VR of "OB" or "OW".

Post Reply

Who is online

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