How to convert current figure to matrix 1:1?
조회 수: 2 (최근 30일)
이전 댓글 표시
The following code firstly saves the figure to an image, then converts the same figure into a matrix which however has not the same resolution (in pixels) of the image, that is the matrix has a different number of rows and columns, why does this happen?
figure('visible','off')
fplot(@(x) sin(x),[0 2*pi])
saveas(gcf, 'test_saveas.png') % 656x875
im = frame2im(getframe(gcf));
imwrite(im, 'test_frame2in.png') % 420x560
[size(im) ; size(imread('test_saveas.png'))]
ans =
420 560 3
656 875 3
Is it possibile to convert the figure into a matrix preserving the resolution?
댓글 수: 0
답변 (1개)
Walter Roberson
2020년 8월 28일
saveas() uses print()
print() uses the figure PaperSize and PaperPosition, and a default resolution that appears to be 100 pixels per inch. It does not just capture the screen: it internally redraws the figure at the resolution implied by PaperSize, and saves that.
getframe() on the other hand, uses whatever the screen resolution and figure size is.
"Is it possibile to convert the figure into a matrix preserving the resolution?"
Preserving which resolution? The figure with the toolbar cropped out? The axes OuterPosition ?
If you are using a high resolution screen and MATLAB has silently rescaled for you, which resolution do you want to use?
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!