Save matrix as image format file
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a matrix with a 61x89x6 double length. I want to save it as a tiff or another image format file. I've checked the help and I've seen that I have to use the multibandwrite comand but it doesn't work.
This is what I'm doing.
% the matrix creation after some operations
image_output(:,:,1)= yl1;
image_output(:,:,2)= yl2;
image_output(:,:,3)= yl3;
image_output(:,:,4)= yl4;
image_output(:,:,5)= yl5;
image_output(:,:,6)= yl7;
%the comand
multibandwrite(image_output,'image_output.bil','bil');
Am I doing something wrong? Really thanks in advance,
1 个评论
Jan
2013-2-4
Please explain the details of "it doesn't work" instead of hoping, that we can guess whats going on. Thanks.
回答(1 个)
Ashish Uthama
2013-2-4
If you have a current version of MATLAB, the Tiff class provides a way to write multi sample image data.
Note: This is a direct interface to LibTIFF, if you need more help, please look up the link in the code below:
%% Write a 61x89x6 double matrix as a TIFF file
data = reshape(1:61*89*6, [ 61 89 6]);
% pref the TIFF object
t = Tiff('output.tif','w');
% http://www.mathworks.com/help/matlab/import_export/exporting-to-images.html
tags.ImageLength = size(data,1);
tags.ImageWidth = size(data,2);
tags.Photometric = Tiff.Photometric.MinIsBlack;
tags.BitsPerSample = 64;
tags.SampleFormat = Tiff.SampleFormat.IEEEFP;
tags.RowsPerStrip = 16;
tags.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tags.SamplesPerPixel = 6;
unspec = Tiff.ExtraSamples.Unspecified;
tags.ExtraSamples = [ unspec, unspec, unspec, unspec, unspec];
t.setTag(tags);
disp(t);
t.write(data);
t.close();
wdata = imread('output.tif');
flag = isequal(data,wdata);
disp(flag);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!