Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

How do I add a background image to my GUI or figure window?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-19J7T
Product:   MATLAB
Reported in Release:   R11
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I add a background image to my GUI or figure window?

Problem Description:

The MATLAB demo window has a background image in it, and I would like to put a background image in my figure.

Solution:

The following code will let you create a background image in your figure. To do this, you need to create an axes object that spans the size of the figure, and then place the image inside this axes.
% This creates the 'background' axes
ha = axes('units','normalized', ...
'position',[0 0 1 1]);

% Move the background axes to the bottom
uistack(ha,'bottom');

% Load in a background image and display it using the correct colors
% The image used below, is in the Image Processing Toolbox. If you do not have %access to this toolbox, you can use another image file instead.
I=imread('eight.tif');
hi = imagesc(I)
colormap gray

% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(ha,'handlevisibility','off', ...
'visible','off')

% Now we can use the figure, as required.
% For example, we can put a plot in an axes
axes('position',[0.3,0.35,0.4,0.4])
plot(rand(10))
In a GUI .m file created by GUIDE, the easiest place to put this code is in the "CreateFcn" for the figure window. This will cause it to be executed when the GUI is created.

One problem which may arise is due to the handle visibility of the GUI. If a new figure window appears when you execute this code in your GUI, please change the HandleVisibility property of the GUI figure as described in the solution attached at the bottom of this page.

If you want to change the transparency of this image, you can set the "AlphaData" property of the image. An example of how to do this is shown in the example code below:
set(hi,'alphadata',.5)

 

Related Solutions:

Please provide feedback to help us improve this Solution
Contact support