how to write double value of matrix and read it as double
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hi, i have applied fastica algorithm and and got matrix containing double values ,now i want to write it in folder (but when i use imwrite it writes in uint8), and when i read using imread it reads in uint8, the values are truncated (1.234 is saved as 1), but i want to use as 1.234.
0 Kommentare
Antworten (3)
KSSV
am 5 Nov. 2016
You can convert uint8 to double using double. Doc double.
3 Kommentare
Image Analyst
am 5 Nov. 2016
1 and 1.000 are the same value.
If you use im2double() or mat2gray() it will scale your image to the 0 to 1 range. If you use double() it will not scale and 1.234 will remain 1.234 - it will not be converted to 1.000.
Walter Roberson
am 5 Nov. 2016
Not really relevant, as the user's difficulty is that when they imwrite() the double, the image is put through im2uint8() and written in uint8 format and pulled back in uint8(). There is a loss of precision involved that is inevitable.
We tend to see this question, about wanting to write floating point values into images and read them back as the same floating point values, in the context of people doing steganography with a wavelet component (or sometimes a DCT component); for such people, it is important that they be able to write out to the same file format as they read back in, and they want to be able to read back non-integer results. It often proves to be ... a challenge... to convince them that typical image file formats supported by imwrite() are completely unable to handle floating point values.
Walter Roberson
am 5 Nov. 2016
imwrite() does not support writing floating point values for any file format.
You could use the TIFF class to write single precision numbers; see http://www.mathworks.com/matlabcentral/answers/7184-how-can-i-write-32-bit-floating-point-tifs-with-nans#comment_15023
However, you should consider instead using save() as text format, or dlmwrite(), or fopen/fwrite/fclose to save as binary. Support for TIFF floating point is not common in file browsers.
0 Kommentare
Image Analyst
am 5 Nov. 2016
To save a friendly version of your arbitrary floating point image in a format that other programs will be happy with, do this:
uint8Image = uint8(255 * mat2gray(yourDoubleImage));
fullFileName = fullfile(folder, 'whatever.PNG');
imwrite(uint8Image, fullFileName);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!