how to convert a matrix with values in decimal point to an image

6 次查看(过去 30 天)
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 个评论
studentambitious
studentambitious 2015-9-3
my interest is not in visualising the image but to preserve the data (which is in form of matrix) to image form which i can reconstruct later with same values. So visualisaton is not the issue, the issue is to recover floating values. thanks in advance
Stephen23
Stephen23 2015-9-3
编辑:Stephen23 2015-9-3
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?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-8-26
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by