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!