How to read a binary file with below description?
Afficher commentaires plus anciens
Each of our tumor segmentation files is a binary file, consisting of the following format:
1. six uint16 values for the inclusive coordinates of the lesion’s cuboid , relative to the image:
y_start y_end
x_start x_end
z_start z_end
2. the N int8 on/off voxels (0 or 1) for the above specified cube, where
N = (y_end-y_start +1) * (x_end - x_start + 1) * (z_end - z_start + 1).
A voxel value of 1 denotes that it is part of the lesion, while a value of zero denotes it is not.
update: I attached the files so if some one wants to test
1 commentaire
dpb
le 17 Jan 2020
What are the characteristics of the file system/data storage writing the data as to endianess, etc.?
Best would be to attach a file for folks to test against; bester yet to also have the right answer to go along with it.
Réponse acceptée
Plus de réponses (2)
dpb
le 17 Jan 2020
Well, one can take a stab at it assuming is compatible w/ most common desktop architecture at the moment and see if it works or not--
fid=fopen('youfile.bin');
x1=fread(fid,1,'int16');
x2=fread(fid,1,'int16');
y1=fread(fid,1,'int16');
y2=fread(fid,1,'int16');
z1=fread(fid,1,'int16');
z2=fread(fid,1,'int16');
N=(x2-x1+1)*(y2-y1+1)*(z2-z1+1);
v=fread(fid,N);
fid=fclose(fid);
What's unspecified is the orientation in which the voxels are written...the above will return a 1D vector; it will be necessary to reshape() appropriately based on the output scheme used.
As noted above, a small sample data file would be about only way to really test it...a link to the devices documentation could/would also probably supply the required information. But, there's nothing like the test.
1 commentaire
salman rezaie
le 18 Jan 2020
Walter Roberson
le 17 Jan 2020
Modifié(e) : Walter Roberson
le 17 Jan 2020
filename = 'appropriatefile.les';
[fid, msg] = fopen(filename);
if fid < 0
error('Filed to open file "%s" because "%s"', filename, msg);
end
y_start = fread(fid, 1, '*uint16');
y_end = fread(fid, 1, '*uint16');
x_start = fread(fid, 1, '*uint16');
x_end = fread(fid, 1, '*uint16');
z_start = fread(fid, 1, '*uint16');
z_end = fread(fid, 1, '*uint16');
Ny = y_end-y_start + 1;
Nx = x_end - x_start + 1;
Nz = z_end - z_start + 1;
N = double(Ny) * double(Nx) * double(Nz);
voxel_mask = fread(fid, [Ny, Nx, Nz], '*int8'); %or maybe [Nx, Ny, Nz] or some other order
fclose(fid);
Catégories
En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!