How to print a matrix as an uncompressed image file.
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(4 个)
Walter Roberson
2011-5-16
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 个评论
Matt Fig
2011-5-19
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!