How can I write a raw double precision image to disk?
Show older comments
I have a double precision image with small values and a very small dynamic range. I want to write this image to disk "as is": if I change it to the interval [0 255] the image is quantized and all the information is lost.
How can I write the image just the way it is stored in memory? By the way, using MATLAB's save is not a real option, I want to write a raw image.
Accepted Answer
More Answers (2)
Ali Can ARIK
on 28 Jun 2011
You can write the image on the disk as if writing a double precision array. However the image cannot be viewed by any image display tool, it can only be read again in Matlab.
filename = 'image.dat';
x = magic(5);
fid = fopen(filename,'w');
fwrite(fid,x);
fclose(fid);
% Following reads the file back into Matlab.
fid = fopen(filename,'r');
x_read = fread(fid);
fclose(fid);
Hope this is what you're looking for.
2 Comments
David Young
on 28 Jun 2011
If the intention is to read it again in MATLAB, why not just use save and load?
Ali Can ARIK
on 28 Jun 2011
Good point. It makes it possible to read it using another programming language though and this is why I thought it would be useful.
Bjorn's solution above is actually what Michael needs imo.
Peter Manley-Cooke
on 28 Jun 2011
0 votes
Could you not expand the dynamic range before quantization and shrink it again when the image is re-loaded?
Categories
Find more on Image Arithmetic 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!