How to determine the number screen pixels being used to display an image?
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Justin Solomon
el 11 de En. de 2017
Comentada: Justin Solomon
el 11 de En. de 2017
I need to figure out the screen real-estate (in pixels) being used to display an image within a figure. If the image's parent axes has the same aspect ratio as the image, then the solution simple... the axes' position property (in pixel units) tells you the number of screen pixels.
However, if the aspect ratio of the axes is not the same as the image, then you have some blank area either on the side or top depending on the image aspect ratio and the axes aspect ratio. In this scenario, the position property of the axes (in pixel units) includes that extra screen space even though the image being displayed doesn't cover that space. See attached image to see what I'm talking about.
Any ideas on how to always get the number of screen pixels being used to display an image, independent of the image and axes' respective aspect ratios? Thanks in advance for any help!
Justin
0 comentarios
Respuesta aceptada
Image Analyst
el 11 de En. de 2017
Try getframe(). See this little demo:
grayImage = imread('cameraman.tif');
[rows, columns, numberOfColorChannels] = size(grayImage)
imshow(grayImage);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Try getframe() - it will give the displayed size on screen.
displayedImage1 = getframe();
[rows, columns, numberOfColorChannels] = size(displayedImage1.cdata)
% Try getimage - it will give the same size as the original
displayedImage2 = getimage();
[rows, columns, numberOfColorChannels] = size(displayedImage2)
3 comentarios
Image Analyst
el 11 de En. de 2017
Why do you incorrectly think that? Just call
imshow(displayedImage1.cdata);
and you'll see it's just the contents of the axes, not the whole figure itself.
Más respuestas (1)
Jan
el 11 de En. de 2017
Editada: Jan
el 11 de En. de 2017
This is not trivial. I do not know a documentation of the behavior for subpixels or when the operating system scales the output. The only really really trustworthy test is displaying a mono-chromatic image with a defined color and taking a screenshot. Then you can search for the rectangle of the defined color.
How is "pixel" exactly defined? Monitor pixels might be interpolated alread for high-resolution screens.
[EDITED] I had set the screen scaling in Windows 7 to 125% to improve the readability of icons and fonts on the desktop. To my surprise afterwards setting the figure 'Position' to an integer pixels position lead to an 'OuterPosition' with a fractional pixel position and vice versa. I expect this is not consistent over different operating systems and Matlab versions.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!