How to print a matrix as an uncompressed image file.

조회 수: 2 (최근 30일)
Corrado
Corrado 2011년 5월 13일
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.

답변 (4개)

Doug Hull
Doug Hull 2011년 5월 16일
Have you tried IMWRITE?

Walter Roberson
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
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.
Walter Roberson
Walter Roberson 2011년 5월 19일
Ah yes, you are correct.

댓글을 달려면 로그인하십시오.


Corrado
Corrado 2011년 5월 23일
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 2011년 6월 17일
The function sc was written to solve exactly this problem.

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by