how to convert a matrix with values in decimal point to an image
조회 수: 5 (최근 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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!