Hello
I'm trying to read in a 3D .raw file into MATLAB. The file was obtained from Volume Graphics studio max, a licensed program used for CT scans. We are only interested in the middle 2D plane of data, or in other words the middle 2D array. This may be a horizontal or vertical slice. There is no need to read in all of the data.
Is there a way to only read in one column of the data and then use that to find the middle value? The size is N x N x N but we do not know what N is.
This is all information I have. Any suggestions?

 Réponse acceptée

Walter Roberson
Walter Roberson le 31 Mai 2016

0 votes

Unfortunately, Volume Graphics does not choose to put its manuals online. Fortunately someone else put one of their manuals online.
Page 250 of http://www.esrf.eu/files/live/sites/www/files/UsersAndScience/Experiments/Imaging/ID19/microtomography/vgstudiomax.pdf describes RAW files in section 5.2.2, indicating the data order has x vary most quickly, then y, then z. There is no indication of whether there is a file header; I would expect there to be one.
You would fopen() the file and read the header.
Then for a horizontal slice, you would fseek() forward by N * N * (bytes per element) * (zplane - 1), after which you would fread(fid, [N, N], PRECISION) where PRECISION is '*uint8' or '*uint16' or as required for your data.
For a vertical slice, you would fseek() forward by N * (bytes per element) * (yplane - 1), after which you would fread(fid, [1, N], PRECISION) and then you would fseek forward by N * (N-1) * (bytes per element) and fread() again, and keep repeating that until the entire slice was read.
If the slice is in the other direction, I would have to work it out but I suspect you could make use of the "skip" option.
I suspect, though, that what might be easiest is to memmapfile() and then index into it.

3 commentaires

francis steyn
francis steyn le 31 Mai 2016
Thank you very much for the answer, I'll give this a try.
Walter Roberson
Walter Roberson le 31 Mai 2016
If there is no header then you can take the cube root of the size of the file to calculate N. If that doesn't work out, divide by 2 first and try -- that would cover the case where the data is 16 bits. I think it is likely that there is a header, though.
francis steyn
francis steyn le 12 Juin 2016
It's working (thanks again). For the X-slice would it be possible to avoid a nested loop? At the moment I'm only saving one X-entry per row that is read. This is taking long for a high res tiff image, where the Y and Z slices are fast.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by