Why isn't truesize working properly?

6 views (last 30 days)
Anna
Anna on 18 Aug 2014
Answered: Image Analyst on 26 Aug 2014
I have created an image of a 300 by 300 matrix, and then used the command truesize(gcf, [300 300]); to make the array 300 pixels by 300 pixels, so that each element appears as a single pixel. However, the resolution of my screen is 1600 by 900, but the width (and height) of the square array is more than 1/3 times the shorter side of the screen - it is almost exactly half this length. This means that each "pixel" is actually 1.5 pixels on my screen (which would explain why using the get(0,'screensize') gives values that are 2/3 of the actual screen resolution. I've accepted that MATLAB uses 1.5 pixels instead of 1, but I would like to know exactly what it is doing. Supposing I wanted to create an image of this matrix
V = [ 0 0 0; 0 1 0; 0 0 0] and used a color map so that the 1 appears white and the 0s black. I'm expecting the image of V to be 4.5 real pixels wide, with a 1.5 pixels wide white square in the centre. Obviously you can't half of a pixel white and the other half black, so how does matlab draw the image of V? Would it color one real pixel white and some pixels around it grey, and the rest black (for the zeros of matrix V)?
Please help!
p.s.Could this have anything to do with which renderer I'm using?

Answers (1)

Image Analyst
Image Analyst on 26 Aug 2014
I've never had much luck with truesize(). When I mentioned zooming trouble to a lead developer on the Imaging team she sent me some code that they recommend. I've made some slight changes to it, but it's below. Run the demo. It walks you through some different zoom and pan/scroll locations. I know it's more complicated than ideal, but I just haven't had a chance to talk with her more about simplifying it.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
% IMSHOW has historically had this behavior all the way back to 1993, that is, it shows the whole image.
% If it can show the whole image at “truesize” or more recently called 100, it does,
% but if not, it shows the whole image.
% When we introduced IMTOOL and IMSCROLLPANEL, there’s more flexibility with the display
% because the scroll panel shows you that there is more image there beyond what you can see.
% Have you tried using IMSCROLLPANEL in combination with IMSHOW? See example below or in:
% doc imscrollpanel
%
% It allows you to directly set the magnification, programmatically or through a magnification box.
% When we created IMSCROLLPANEL and the associated magnification controls in IPT5, we hoped that they would satisfy exactly this GUI use case.
%
% Let me know what you think if you try it or if you've tried it in the past, why it doesn't meet your needs.
% We're open to discussing this further with you to see if we can fix the issue or make the better solution easier to discover if it's indeed adequate.
% Here's the example from the documentation:
% Create a scroll panel with a Magnification Box and an Overview tool.
hFig = figure('Toolbar','none',...
'Menubar','none');
hIm = imshow('saturn.png');
hSP = imscrollpanel(hFig,hIm); % Handle to scroll panel.
set(hSP,'Units','normalized',...
'Position',[0 .1 1 .9])
% Add a Magnification Box and an Overview tool.
hMagBox = immagbox(hFig,hIm);
pos = get(hMagBox,'Position');
set(hMagBox,'Position',[0 0 pos(3) pos(4)])
imoverview(hIm)
% Get the scroll panel API to programmatically control the view.
api = iptgetapi(hSP);
% Get the current magnification and position.
mag = api.getMagnification();
r = api.getVisibleImageRect();
% View the top left corner of the image.
message = sprintf('Click OK to view the top left corner of the image');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setVisibleLocation(0.5,0.5)
% Change the magnification to the value that just fits.
message = sprintf('Click OK to change the magnification to the value that just fits');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnification(api.findFitMag())
% Zoom in to 1600% on the dark spot.
message = sprintf('Click OK to zoom in to 1600%%on the dark spot.');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnificationAndCenter(16,306,800)
% Zoom in to 100% with upper left showing.
message = sprintf('Click OK to zoom in to exactly 100%%.');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnificationAndCenter(1,1,100)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!