Write HU numbers to file

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
ghleclerc
Posts: 9
Joined: Thu, 2013-11-07, 06:18
Location: Canada

Write HU numbers to file

#1 Post by ghleclerc »

Hello.

I am writing, for a class I teach, a dicom rectangular water phantom generator. Basically, I want someone to be able to say "give me a water phantom of 10 x 20 x 30 cm³" and the program will generate the CT images.

I have a proof of concept with pydicom, but because I want to be able to distribute a .exe, I had two options: learn how to make a "python to .exe" converter program work (pyinstaller, cx_freeze), or rewrite the program in another language. I know C++ and have a bit of experience with DCMTK, so I thought I should rewrite in C++.

I have found all the necessary DICOM modules (otherwise the python program wouldn't work) and I have been able to do most of the work in C++ (although some things are not as intuitive/easy as in python ;-) ).

The point where I am stuck is this: I am generating "pure" (for lack of a better term) hounsfield numbers, i.e. I use a random number generator to generate numbers between -1000 and -980 for the air in a slice and a second one to generate numbers between -30 and -5 for the water in a slice. I want to write these numbers in the slice. Haven't found a proper way.

At first, I thought of converting the numbers to unsigned (which yeilds very large integers because of sign unsigned conversion) and using putAndInsertUint16Array() to insert the values. But I am not certain if this makes sense. It kind of worked, (opened the images in ImageJ and seemed to give proper images), but I might just have been lucky or I might be missing something.

Then, I thought I might use putAndInsertSint16Array, but that does not work with the VR for pixel data.

Now, I am thinking of using putAndInsertString() and writing out the numbers in a string (-987\-999\-989\-1000...), but that would probably be a disaster performance wise.

What is the proper way to achieve what I want ? Any idea would be appreciated.

ghleclerc
Posts: 9
Joined: Thu, 2013-11-07, 06:18
Location: Canada

Re: Write HU numbers to file

#2 Post by ghleclerc »

Reading this post, I think that the first method I tried (going through putAndInsertUint16() ) is actually OK.

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

Re: Write HU numbers to file

#3 Post by J. Riesmeier »

Pixel Data (7fe0,010) is either stored as a sequence of bytes (VR=OB) or words (VR=OW), that's why only putAndInsertUint8Array() or putAndInsertUint16Array() can be used. This is also documented in the API documentation.

Post Reply

Who is online

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