How to convert current figure to matrix 1:1?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 28 de Ag. de 2020
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?
1 comentario
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!