binary data reading into an image

I need some help with a bin file i have downloaded.it contains slices of the brain mri. this is the info i got about the .bin file
The suffix “bin” indicates that the file is a stream of binary numbers. The numbers are encoded as two-byte two's complement integers. The byte order is big-endian. This order is the standard for Sun workstations. Odd and even bytes must be interchanged for DEC VAX computers and Intel 80x86 microprocessors. The “.bin” file contains the voxels in row-column-slice order, meaning that the first voxel in the file should be displayed in the upper left of the screen, the second voxel should be displayed to the right of the first, etc., until the end of the row is reached. The next voxel should be displayed below the first voxel of the file, the next to the right of that, etc., until one complete slice is displayed. The first voxel of the second slice follows the last voxel of the first slice, etc.
thank you

 Accepted Answer

Walter Roberson
Walter Roberson on 11 Nov 2012
fread() with '*int16' as the precision. reshape() the linear stream into a cuboid and then permute() [2 1 3] to change the data order to MATLAB's data order.

5 Comments

thank you Walter .It did help to some extent.but see the data size is 1572864.rows are 256 columns: 256 slices: 24 and dimension :3 how do i shape up the data?i am missing something about slicing .reshape reads data column wise and i need to read it row wise then how to see the slices as image as given here http://www.insight-journal.org/rire/data_format.php i am not able to get hold of dimensions given on the site about data?
thanks again.
permute(reshape(TheData,256,256,24), [2 1 3])
That is, you allow reshape to fill data down columns, but then you switch rows and columns afterwards.
thank you Walter .It was very helpful .Now i am able to get the images .Last thing if you could guide me about is the image quality ,its blackand white .I am converting it in uint8 to display but then its turning into grey . How to get good quality image from binary data?
Instead of converting it to uint8(), try using imagesc() on the int16 data.
thanks it worked absolutely fine .

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!