Saving an array as a .raw image

17 views (last 30 days)
JoaquinB
JoaquinB on 20 Mar 2020
Commented: JoaquinB on 23 Mar 2020
Hello, i am working with image processing using Matlab.
My inputs are some 3D .raw tomography images, which i process with matlab. After the operations i would like to save my image with the original format (which is .raw) so I don't lose any information ( I know I could use other images formats but I want the original format).
B is a 280x3072x4000 logical array, which contains my image and its the array I want to save as .raw.
I tried the following code:
fid = fopen('17_M91_40J_POLAR_DMG_INF_1_8b_3072x280x4000.raw','r','b');
fwrite(fid,B,'uint8');
fclose(fid);
I generated the '17_M91_40J_POLAR_DMG_INF_1_8b_3072x280x4000.raw' just copying the original image with Windows and changing the name manually since I dont know how to generate a 'blank' raw file. The code seems to work but when I open the file it's the same as the original, it seems like fwrite don't do anything.
I attach screenshots of the original .raw image and the B array (image processed) which I would like to save
Any ideas? Thanks

Accepted Answer

Ganesh Regoti
Ganesh Regoti on 23 Mar 2020
Hi,
As per my understanding, you are reading data from a .raw file, processing the data and trying to store the processed data in the same file. But as per your code, you have given only read access to the file, as per the code
fid = fopen('17_M91_40J_POLAR_DMG_INF_1_8b_3072x280x4000.raw','r','b'); %r->read access. Change it to r+ or a+
I assume that might be the issue for the data not being updated in the file. You can try changing the file access types. 'r+' and 'a+' might fit for your case. Refer the following link
Hope this helps!

More Answers (0)

Categories

Find more on Biomedical Imaging 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!