How to determine the number screen pixels being used to display an image?
15 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Image Analyst
2017 年 1 月 11 日
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 件のコメント
Image Analyst
2017 年 1 月 11 日
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.
その他の回答 (1 件)
Jan
2017 年 1 月 11 日
編集済み: Jan
2017 年 1 月 11 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!