MATLAB: Display an image in Its Original Size

MATLAB: Display an image in Its Original Size

Ask Question

10 years, 6 months ago

1 year, 11 months ago

9k times




Can we show an image in its original size in MATLAB?

Right now when we are showing, it is exactly fitted to the image window size. However, I want to show the image in its original size. When the image is of larger size, a scroll bar should appear in the image window. This would allow the user to view the image in its original size.

Any ideas on how to achieve this? Is this possible?

image matlab

share|improve this question

edited Apr 14 ’18 at 7:47


3,76544 gold badges3333 silver badges5050 bronze badges

asked Sep 15 ’09 at 14:39


add a comment

6 Answers





I believe what you’re looking for is the IMTOOL utility (which is a part of the Image Processing Toolbox). It’s a MATLAB GUI that allows you to view images in their original size (100% magnification) with horizontal and vertical sliders.


The above solution will display your image in a new figure window (the IMTOOL GUI). If you don’t want the image appearing in a new window, but instead want to adjust its size in a window of your own, it will be more difficult. To adjust the size of the image, which I assume you’ve displayed on a set of axes using the IMAGE command, you will have to adjust a number of axes properties for the axes containing the image. The following are the properties you will likely end up modifying:

‘Units’: This can be set to ‘inches’, ‘centimeters’, or ‘pixels’, for example.
‘Position’: This controls where the axes are placed in the figure window, in units governed by the ‘Units’ property.
‘DataAspectRatio””PlotBoxAspectRatio’: These control the relative scaling of the axes and the surrounding plot box.
‘XLim””YLim’: The minimum and maximum values of the axes.

After getting the size and scaling of the image to display the way you want, parts of the image could be outside the figure window area. Unfortunately, horizontal and vertical sliders will not be automatically added. You will have to create these slider controls yourself using the UICONTROL function. You will have to write the callback functions for the slider controls such that they move the axes around in the window.

If you choose to venture down the above path, here are a few links to GUI design tutorials that may help you: a slider tutorial on blinkdagger, a blog post by Doug Hull, and a video from Doug on GUIDE basics.

share|improve this answer

edited Sep 15 ’09 at 16:05

answered Sep 15 ’09 at 15:06


122k1313 gold badges242242 silver badges344344 bronze badges


It should maybe be pointed out that imtool is in the Image Processing Toolbox.

– Richie Cotton
Sep 15 ’09 at 16:03

add a comment


Matlab slider has a problem that it fires callback only on MouseUp and not on MouseMove, so pure matlab implementation would always feels strange.

Better way – go for Java in Matlab. So you do not have to re-implement whole scroll logics. You can put Java Swing GUI component inside Matlab window, it is not difficult at all.

Specifically you have to use Swing JScrollPane Class. With Matlab javacomponent() function you can put it inside matlab window.

There are tons of examples on the web on how to get image into scroll pane, just browse for JScrollPane image. You can use Java classes inside matlab with usual Matlab syntax (no need for new keyword, ecc.)

share|improve this answer

edited Sep 15 ’09 at 17:38

answered Sep 15 ’09 at 17:32


5,51333 gold badges3535 silver badges5050 bronze badges


FYI, there is a way to have a MATLAB slider execute a callback when being dragged, addressed here: In MATLAB, how can you have a callback execute while a slider is being dragged?

– gnovice
Sep 26 ’13 at 15:53

add a comment


figure,imshow(your_image), axis image
This changes the image axis to the original size

share|improve this answer

answered Feb 18 ’12 at 23:27


27022 silver badges1010 bronze badges

add a comment


This code from MATLAB’s Answers forum creates a window where the image is shown at native resolution (100%), and also gives a “navigation” window showing where your viewed section of the image (in the main window) fits into the whole image.

% Create a scroll panel with a Magnification Box and an Overview tool.
hFig = figure(‘Toolbar’,’none’,…
hIm = imshow(‘saturn.png’);
hSP = imscrollpanel(hFig,hIm); % Handle to scroll panel.
‘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)])

(Forum post link)

share|improve this answer

answered Apr 14 ’18 at 6:55


28711 silver badge99 bronze badges

add a comment


Funny, nobody here has mentioned truesize yet:

truesize(fig) adjusts the display size such that each image pixel covers one screen pixel. If you do not specify a figure, truesize adjusts the display size of the current figure.

share|improve this answer

answered Apr 14 ’18 at 7:29

Cris LuengoCris Luengo

33.7k66 gold badges2929 silver badges6868 bronze badges

Truesize sounds exactly what people want, except in practice I found it didn’t work. That’s what this forum thread is all about, and why I posted the solution that worked for me.

– MechtEngineer
Apr 14 ’18 at 7:36

add a comment


There are 3 things to take care of in order to display image in its original size (1:1):

The figure size and units.
The axes size and units.
The axes data aspect ratio.

Once all of that are set according to the image size even using MATLAB’s image() function one could generate 1:1 display of an image.

Here is the sample code:

%% Load Data

mI = imread(‘7572939538_04e373d8f4_z.jpg’);

numRows = size(mI, 1);
numCols = size(mI, 2);

%% Setings

horMargin = 30;
verMargin = 60; %<! Title requires more

%% Display Image

vFigPos = [100, 100, numCols + (2 * horMargin), numRows + (2 * verMargin)]; %<! [Left, Bottom, Width, Height]
vAxesPos = [horMargin, verMargin, numCols, numRows];

hFigure = figure(‘Position’, vFigPos, ‘Units’, ‘pixels’);
hAxes = axes(‘Units’, ‘pixels’, ‘Position’, vAxesPos);
hImageObj = image(hAxes, mI);
set(hAxes, ‘DataAspectRatio’, [1, 1, 1]);
set(get(hAxes, ‘Title’), ‘String’, {[‘Landscape by Roman Vanur’]}, …
‘Fontsize’, fontSizeTitle);
set(hAxes, ‘XTick’, []);
set(hAxes, ‘YTick’, []);

The result (Based on the image – Landscape by Roman Vanur):

The full code in my Stack Overflow Q1427602 Github Repository.

share|improve this answer

answered Apr 14 ’18 at 8:22


3,76544 gold badges3333 silver badges5050 bronze badges

add a comment

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password


Post as a guest


Required, but never shown

Post Your Answer


By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

The Overflow Blog

Podcast Episode 220: Fully Remote

Tracking down performance pitfalls in Vue.js

Featured on Meta

Planned maintenance scheduled for Saturday, March 28, 2020 at 13:00 UTC (9AM…

An Update On Creative Commons Licensing

Community and Moderator guidelines for escalating issues via new response…

How does the Triage queue work?

Triage needs to be fixed urgently, and users need to be notified upon…



In MATLAB, how can you have a callback execute while a slider is being dragged?


image is too big to fit in the screen (MATLAB)


Show image in matlab axis in its original scale


Displaying small images with their original size in matlab


339How to add an image to a JPanel?1270Strange out of memory issue while loading an image to a Bitmap object1911How to lazy load images in ListView in Android1455How do I auto-resize an image to fit a ‘div’ container?1421How to vertically align an image inside a div562How to display Base64 images in HTML?2Lock image size on Matlab GUI870Changing image size in Markdown1Image size after resizing is greater than original image

Hot Network Questions

When we press a piano key, why does a high pitch note not run for as long as a low pitch note?

Any Implementation in C++

How to calculate the probability of a quantum system in superposition to be in the “up” state?

How does linear phase shift of bessel filter avoid distortion of nonsinusoidal inputs?

Create an ISO of an AWS EC2 Server

Cat Keeps Drinking Unattended Drinks

Is the so called kTC noise, that is inherent in an RC filter, dependent on bandwidth?

I was up a piece but could not win. What went wrong?

How do “tip jet” helicopters cancel the torque effect of the main rotor?

What allows a pull-back toy car to drive further than it was pushed?

Is there a tool that will make a rounded cut in flat metal wire?

Does the Buddha deny genetic differences?

Confusion about the definition of the uncertainty principle

Was the de Havilland Mosquito ever deployed on an aircraft carrier?

When I burn isopropyl alcohol (IPA), it burns orange. But when I burn ethyl alcohol, it burns totally blue. Why is this?

What are the available D&D 5e backgrounds, and where can I find them?

Pendulum Encoding

Does liquid temperature matter when making bread in a bread maker?

Are Putin’s constitution amendments legal?

Identifying the subject of a sentence

How much project management is a software developer supposed to do?

How could a person correct their vision with limited technology?

Four distinct 8-bit integers

How can I avoid losing or missing a SIM ejector tool?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Leave a Reply

Your email address will not be published. Required fields are marked *