how to convert a matrix with values in decimal point to an image
6 views (last 30 days)
Show older comments
I want to convert a matrix having decimal(.) values with in range of 0-255 into an image. e.g the matrix contains the values like [ 122.0456 33.6785 47.0048; 233.8765 121.6743 45.6780]. floor/ceil/round will round off the decimal values . But i want to retrieve the same matrix with decimal points after retrieving the matrix from image. please help
6 Comments
Stephen23
on 3 Sep 2015
Edited: Stephen23
on 3 Sep 2015
As Guillaume has already pointed out, your matrix is already an image. Every matrix is an image. Ergo if you save the matrix, you still have an image. And if you save the matrix with its decimal values, then you will have an image with decimal values.
If you are not planning on viewing the image using any standard image viewing tools (which require integer values in the file), then why not just save the matrix exactly as it is using any standard MATLAB matrix-saving tool?
Answers (1)
Walter Roberson
on 26 Aug 2015
You will need to use TIFF files with the TIFF Class and configure the SampleFormat as Tiff.SampleFormat.IEEEFP . That will allow you to store single precision floating point values.
t = Tiff(filename, 'w');
tagstruct.ImageLength = size(YourArray, 1);
tagstruct.ImageWidth = size(YourArray, 2);
tagstruct.Compression = Tiff.Compression.None;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 32;
tagstruct.SamplesPerPixel = size(YourArray, 3);
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.MinSampleValue = 0.0;
tagstruct.MaxSampleValue = 255.0;
t.setTag(tagstruct);
t.write(YourArray);
t.close();
Note: more work might be necessary to be able to view this with any particular viewer.
0 Comments
See Also
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!