How to print a matrix as an uncompressed image file.

2 vues (au cours des 30 derniers jours)
Corrado
Corrado le 13 Mai 2011
I have a matrix M (600x600) and I make a color plot with
imagesc(M)
set(gca,'YDir','normal')
axis equal
axis off
The problem is that I need to export what I get but exactly what I get and only that. I want an image (tiff or something else that is not compressed) of 600x600 pixels, each one of the color I have get by imagesc(M).
Ideally, if I go to the information of my output file I'll can read 600x600pixels 24bit RGB.
Or if I have a 1200x1200 with 600dpi resolution (2inch by 2 inch image) I need to export that exactly and only that..
I tried with print -r600 -zbuffer -dtiffn (with -loose or -noui too) but I always save back ground too.
In my mind my wish is to obtain, for a plot 300x300, a file .tiff (...or .eps or anything else that may be open with different pc with different installed programs..) maybe of 720KB...but the most important request is that if i want it with 100dpi, the file produced is 3inch x 3inch and with exactly 90000 points.

Réponses (4)

Doug Hull
Doug Hull le 16 Mai 2011
Have you tried IMWRITE?

Walter Roberson
Walter Roberson le 16 Mai 2011
Note the reference to imagesc() and note that a third dimension is not specified for the matrix. Your data is being scaled and translated by imagesc() with the current color map being used. imwrite() would not do that scaling and translation for you.
[Code amended Nov 30 2011, per Matt's remarks]
OutputResolution = 100;
Mmin = min(M(:));
Mmax = max(M(:));
C = colormap();
numcol = size(C,1);
if Mmin == Mmax
Mscaled = repmat(reshape(C(end,:),1,1,3),size(M,1),size(M,2),1);
else
Mscaled = ind2rgb(round((M - Mmin) ./ (Mmax - Mmin) * (numcol-1)), C);
end
imwrite(Mscaled, FILENAME, 'tiff', 'Compression', 'none', 'Resolution', OutputResolution);
  2 commentaires
Matt Fig
Matt Fig le 19 Mai 2011
Walter, if I understand correctly you have misused the COLORMAP function by indexing with end. Unless things have changed since 2007b, it would be better to define a variable at the beginning of your code:
C = colormap;
Then index into and reference C in the rest of the code.
Walter Roberson
Walter Roberson le 19 Mai 2011
Ah yes, you are correct.

Connectez-vous pour commenter.


Corrado
Corrado le 23 Mai 2011
Tank you very much. I delete the "if" part of the code because it makes me some problem and I'll never have Mmin==Mmax! All the rest of the code works very well!! tank you so much!!

Oliver Woodford
Oliver Woodford le 17 Juin 2011
The function sc was written to solve exactly this problem.

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by