# ho can I read 3d volumes in raw format?

## Recommended Posts

abahena    122
hi, Any idea ho can I read 3d volumes in raw format? Also how can I turn discrete values in xyz coordinates? thanks in advance, Alex

##### Share on other sites
Evil Steve    2017

What language?
What API?
What do you mean "turn discrete values in xyz coordinates"?

##### Share on other sites
glaeken    294

The typical volume data stored in a .RAW file is usually stored linearly:

slice1, slice2....sliceN where each slice is Width x Height long.

Pseudo code for reading a RAW volume data file (note: assumes scalars):
Size = Width * Height * Depth;for i to Size  data[i] = read NBytes.

where NBytes is the storage size of the data (sizeof( byte ) for 8-bit, sizeof( byte * 2) for 16-bit, etc). This, of course depending on the language, could be much faster. Example in C:

fread( data, NBytes * Width * Height * Depth, RAWfile );

Then to access a point at x, y, z: data[x + (y * Width) + (z * Width * Height)]