View Full Version : reading raw 3d volumes?
abahena 04-28-2010, 07:57 PM Hi,
Anybody knows how to read raw volumes in c++.
thanks in advance,
Alex
|
|
Gravedigger
04-28-2010, 11:25 PM
hey alex
what kind of format are you talking about?
is the volume defined with voxels?
grs
Gravedigger
abahena
04-29-2010, 06:11 AM
yes from http://www.volvis.org/
abahena
04-29-2010, 06:42 AM
I'm able to read it with fstream but what its the value of a voxel represent? I guess is a discrete way to represent a xyz in local space. But how can you change that discrete value in x y z ?
thanks
Gravedigger
04-29-2010, 02:52 PM
hei abahena
this format is really raw :D
for example:
Head MRT Angiography 16Bits
(10bits set)
416 x 512 x 112
0.412, 0.412, 0.412
size in bytes: 47'710'208
ok lets see how much the voxels need: 416*512*112*16bits/8 = 47'710'208
means there is no header at all! usually, even in a raw format, there's a header giving some information about the dimensions and wether it's 8/16bit. like this the format is veeery limited.
it's difficult to say how to read that file correctly because i haven't found anything about it but i think the structure is very simple. it seems as if there's only one channel per voxel which will represent density.
what isn't clear is how the voxels are ordered. because the files are still pretty small you can load, depending on your hardware, the whole file to ram. so simply create an array (16bit per element) of the dimension 416*512*112. this would then be an array containing the densities of the volume
does that help?
grs
Gravedigger
abahena
04-30-2010, 10:33 AM
Yes, thanks! Im reading values from -128 to 127 from a 8 bit, I tryed with 16 bits with a short int, but I didnt get a correct range of a 16bits(12 bits data set). Which should be 4096 range of values. But its ok to play with 8 bit at first, if you dont have a machine with to much ram.
Thanks,
Alex
Gravedigger
04-30-2010, 11:55 AM
hei alex
according to the text the example i took "Head MRT Angiography 16Bits (10bits set)" is stored as a 16bit per voxel data. actually there are only 10 bits set the others are 0
a short int would have 16bits and a range of 65536 values. if only 10 bits are set the maximum value would be 2^10 = 1024
so you could use unsigned shorts to read the data. to get a float value out of this you'd need to divide by 1024.0. the density range would then be from 0 to 1 with 1024 steps.
you don't need much ram to load the whole volume into your ram. for the one i've mentioned you'd need 45.5MB ram to load all voxels into an unsigned short array
grs
Gravedigger
misterbk
05-08-2010, 10:25 PM
You can make an assumption based on programmers' tendency to think in terms of "first X, then Y, then Z" to get the ordering.
If the file is symmetric i.e. 256x256x256, I think the order you read won't matter (and you won't know if you got it right) because if you read an axis out of order it will just transpose the image.
If you start with an asymmetric file like 256x128x512 then an incorrect order will look like a glitchy mess, and you should get the right axis order in 5 tries or less. :)
Suggestion for optimizing RAM, you could just do a once through the file and find the maximum value, then choose what you store in from that. Or use that to choose what to divide everything by to store an array of floats.
The number of bits used in those files is probably related to the capabilities of the machine.
(And you probably knew all that!)
CGTalk Moderation
05-08-2010, 10:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.