Figure automatically scales by 2

Hi, I set my figure as below:
figure(1)
set(gcf,'units','pixels','position',[0,0,512,512]);
However, the popped figure window has resolution 1024x1024. When I try to get the result as a matrix:
F = getframe (gcf,[0,0,512,512]);
[img, ~] = frame2im (F);
I would like to get img with resolution 512x512x3, but I get its value as 1024x1024x3.
Is there anyway to solve this problem?

4 Kommentare

xiaojuezi
xiaojuezi am 6 Apr. 2020
It seems to be my screen (retina). When I switched to a different screen, this gives the right plot. But how could I fix the figure size regardless the screen resolution?
Tommy
Tommy am 6 Apr. 2020
Bearbeitet: Tommy am 7 Apr. 2020
I apologize, I misunderstood the issue! MATLAB is 'DPI-aware' so when you plot your figure, it will be scaled according to your display.
Edit: If you are only concerned with keeping the resolution of img at 512x512, might this work?
newImg = img(1:end/512:end, 1:end/512:end, :);
I'd be surprised if this gave the same result as when you create the figure on your other screen (to be honest I'm not sure, I suppose it depends on how exactly MATLAB utilizes the extra space) but with this you could cherry-pick pixels to create a 512x512 image which at least captures the features of img.
Walter Roberson
Walter Roberson am 7 Apr. 2020
For
  • Windows® systems in which the display dots-per-inch (DPI) value is set higher than 96
  • Macintosh systems with Apple Retina displays
When you set the Units property of a graphics or UI object to 'pixels', the size of each pixel is now device-independent on Windows and Macintosh systems:
  • On Windows systems, 1 pixel = 1/96 inch.
  • On Macintosh systems, 1 pixel = 1/72 inch.
(My Mac happens to be one of the last non-Retina models, so I am not affected by this... which also means that I cannot test work-arounds.)
xiaojuezi
xiaojuezi am 11 Apr. 2020
Thank you all ! I think it is a problem of macos, when explicitly setting '-r72' or '-r96' for different os, the problem is solved.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Apr. 2020

Kommentiert:

am 11 Apr. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by