Effacer les filtres
Effacer les filtres

Save matrix as image format file

8 vues (au cours des 30 derniers jours)
Emmanuelle
Emmanuelle le 4 Fév 2013
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 commentaire
Jan
Jan le 4 Fév 2013
Please explain the details of "it doesn't work" instead of hoping, that we can guess whats going on. Thanks.

Connectez-vous pour commenter.

Réponses (1)

Ashish Uthama
Ashish Uthama le 4 Fév 2013
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);

Community Treasure Hunt

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

Start Hunting!

Translated by