Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Images in GUI

Subject: Images in GUI

From: Vaibhav Bedia

Date: 15 Jan, 2008 05:25:03

Message: 1 of 7

I am making a GUI in which i want to display two images at
the sides.I saw the video on Matlabcental about setting
background images using imshow() in the CreateFn of the axes
created and tried it out.

The problem i am facing is that when i close Matlab and run
the GUI again or run it on a different PC the axes 'tag'
field becomes empty and the visibility is hence 'off'. Every
time i have to rename the axes and go to the CreateFn of the
axes.

I am using R2007b.

How can i solve this isssue?

Subject: Images in GUI

From: Vihang Patil

Date: 15 Jan, 2008 05:39:01

Message: 2 of 7

"Vaibhav Bedia" <vaibhav.bedia@gmail.com> wrote in message
<fmhg3f$e5q$1@fred.mathworks.com>...
> I am making a GUI in which i want to display two images at
> the sides.I saw the video on Matlabcental about setting
> background images using imshow() in the CreateFn of the axes
> created and tried it out.
>
> The problem i am facing is that when i close Matlab and run
> the GUI again or run it on a different PC the axes 'tag'
> field becomes empty and the visibility is hence 'off'. Every
> time i have to rename the axes and go to the CreateFn of the
> axes.
>
> I am using R2007b.
>
> How can i solve this isssue?

Hello
If you have two images displayed separatly then you will
require to define 2 axes on the gui window. Drop down the
axes from the toolbox using guide into your fig.
Assuming, axes1 and axes2 are the variables.
You can then issues

axes(handles.axes1); % this is used to set focus on the axes
 %currently in use
imshow('firstimage');

axes(handles.axes2);
imshow('secondimage');

HTH
Vihang

Subject: Images in GUI

From: Szymon Lipiec

Date: 15 Jan, 2008 12:36:01

Message: 3 of 7

oi!
i have similar problem ->
i have 2 axes (axes1, axes2) on my figure in gui, when i
set axes1 active [axes(handles.axes1)] and i check for tag
property i get apropriate tag -> 'axes1' in next line i'm
showing pic with [imshow(pic)] 3rd line is chcecking again
for the tag property and BAM -> '' EMPTY
i even tried to name it again after imshowing but it
appears that somehow axes1 duplicates becouse finding all
axes types results in showing 3 axes instead of 2:

axes =
'axes1'
''
'axes2'

if u have any ideas how to overcome it - please help

Subject: Images in GUI

From: Anh Huy Phan

Date: 15 Jan, 2008 14:05:02

Message: 4 of 7

"Szymon Lipiec" <szymon.lipiec@gmail.com> wrote in message
<fmi9bh$s3j$1@fred.mathworks.com>...
> oi!
> i have similar problem ->
> i have 2 axes (axes1, axes2) on my figure in gui, when i
> set axes1 active [axes(handles.axes1)] and i check for
tag
> property i get apropriate tag -> 'axes1' in next line i'm
> showing pic with [imshow(pic)] 3rd line is chcecking
again
> for the tag property and BAM -> '' EMPTY
> i even tried to name it again after imshowing but it
> appears that somehow axes1 duplicates becouse finding all
> axes types results in showing 3 axes instead of 2:
>
> axes =
> 'axes1'
> ''
> 'axes2'
>
> if u have any ideas how to overcome it - please help

When you create the axes, the NextPlot property of this
axes to "add" value

figure

set(gca,'NextPlot','add')
set(gca,'Tag','myaxes')
...
...

Anh Huy Phan
RIKEN - BSI

Subject: Images in GUI

From: Vaibhav Bedia

Date: 15 Jan, 2008 16:16:01

Message: 5 of 7

I tried putting what Anh said in the CreateFn of the axes
but it didnt work.Was that where i was supposed to put it?

But i got it working in a diff way.Added the following in
the OpeningFn of the GUI.

%load the background image into Matlab
%if image is not in the same directory as the GUI files,
you must use the
%full path name of the image file
Image1 = importdata('image1.jpg');
Image2 = importdata('image2.jpg');
%select the axes
axes(handles.axes13);
%place image onto the axes
image(Image1);
%remove the axis tick marks
axis off

%select the axes
axes(handles.axes12);
%place image onto the axes
image(Image2);
%remove the axis tick marks
axis off

% Update handles structure
guidata(hObject, handles);

Maybe this will solve Szymon's problem also.

"Anh Huy Phan" <phananhhuy@mathworks.com> wrote in message
<fmieie$fbq$1@fred.mathworks.com>...
> "Szymon Lipiec" <szymon.lipiec@gmail.com> wrote in
message
> <fmi9bh$s3j$1@fred.mathworks.com>...
> > oi!
> > i have similar problem ->
> > i have 2 axes (axes1, axes2) on my figure in gui, when
i
> > set axes1 active [axes(handles.axes1)] and i check for
> tag
> > property i get apropriate tag -> 'axes1' in next line
i'm
> > showing pic with [imshow(pic)] 3rd line is chcecking
> again
> > for the tag property and BAM -> '' EMPTY
> > i even tried to name it again after imshowing but it
> > appears that somehow axes1 duplicates becouse finding
all
> > axes types results in showing 3 axes instead of 2:
> >
> > axes =
> > 'axes1'
> > ''
> > 'axes2'
> >
> > if u have any ideas how to overcome it - please help
>
> When you create the axes, the NextPlot property of this
> axes to "add" value
>
> figure
>
> set(gca,'NextPlot','add')
> set(gca,'Tag','myaxes')
> ...
> ...
>
> Anh Huy Phan
> RIKEN - BSI

Subject: Images in GUI

From: Anh Huy Phan

Date: 15 Jan, 2008 17:03:01

Message: 6 of 7

"Vaibhav Bedia" <vaibhav.bedia@gmail.com> wrote in message
<fmim81$d4r$1@fred.mathworks.com>...
> I tried putting what Anh said in the CreateFn of the axes
> but it didnt work.Was that where i was supposed to put it?
>
> But i got it working in a diff way.Added the following in
> the OpeningFn of the GUI.
>
> %load the background image into Matlab
> %if image is not in the same directory as the GUI files,
> you must use the
> %full path name of the image file
> Image1 = importdata('image1.jpg');
> Image2 = importdata('image2.jpg');
> %select the axes
> axes(handles.axes13);
> %place image onto the axes
> image(Image1);
> %remove the axis tick marks
> axis off
>
> %select the axes
> axes(handles.axes12);
> %place image onto the axes
> image(Image2);
> %remove the axis tick marks
> axis off
>
> % Update handles structure
> guidata(hObject, handles);
>
> Maybe this will solve Szymon's problem also.
>
> "Anh Huy Phan" <phananhhuy@mathworks.com> wrote in
message
> <fmieie$fbq$1@fred.mathworks.com>...
> > "Szymon Lipiec" <szymon.lipiec@gmail.com> wrote in
> message
> > <fmi9bh$s3j$1@fred.mathworks.com>...
> > > oi!
> > > i have similar problem ->
> > > i have 2 axes (axes1, axes2) on my figure in gui,
when
> i
> > > set axes1 active [axes(handles.axes1)] and i check
for
> > tag
> > > property i get apropriate tag -> 'axes1' in next line
> i'm
> > > showing pic with [imshow(pic)] 3rd line is chcecking
> > again
> > > for the tag property and BAM -> '' EMPTY
> > > i even tried to name it again after imshowing but it
> > > appears that somehow axes1 duplicates becouse finding
> all
> > > axes types results in showing 3 axes instead of 2:
> > >
> > > axes =
> > > 'axes1'
> > > ''
> > > 'axes2'
> > >
> > > if u have any ideas how to overcome it - please help
> >
> > When you create the axes, the NextPlot property of this
> > axes to "add" value
> >
> > figure
> >
> > set(gca,'NextPlot','add')
> > set(gca,'Tag','myaxes')
> > ...
> > ...
> >
> > Anh Huy Phan
> > RIKEN - BSI
>

I think this link is helpful for you

http://www.mathworks.com/support/solutions/data/1-
5BO0I4.html?solution=1-5BO0I4


There are two ways to set the "Nextplot" property

   - Double-click on the axes in the GUIDE tool to open its
Inspector.
   - Find "Nextplot" and choose the value "add"

or

   - in the CreateFcn of the axes, add this line

     set(hObject,'Nextplot','add');

HTH
Anh Huy Phan
RIKEN - BSI

Subject: Images in GUI

From: barba pere

Date: 10 Jul, 2008 10:20:07

Message: 7 of 7

Ok, I'm new one here. Hello everyone

So, I have much similar problem as you do

I am using GUI from matlab 2008a. In my program I have much
axes, and a specific one. On that specific axes I need to
draw a horizontal line on the place where user clicks (I'm
using imshow function). The size of the image that I need to
draw is modified so that it can fit in the axes perfectly
(axes and image are the same size).

Besides that (besides drawing a horizontal line on the place
where user clicks), I need to update handles structure with
info about mouse pozition. So I figured the best way to do
this is if I use ButtonDownFcn from the axes.


I already turned image's HitTest to off. and that works.

Then I heard that axes replaces all properties when you draw
new image. So I set NextPlot to add.

And ButtonDownFcn worked. Now when I click on the picture,
axesTrenutniFrame_ButtonDownFcn is called. But one new
problem occured.

Now, Image that I'm drawing won't fit to the axes perfectly.
My axes is (15x800), and the imagethat I need to draw is
(15x800x3), but now image is rescaled.

Here is part of my code. It is from GUI opening function. It
is a picture with 9 horizontal lines and one red line at
101.-103. pixel


slika = ones (15, 800, 3) * 255;
a = floor(linspace(1, 800, 9));

slika (:, a, :) = 0;
slika (:, 101:103, 2:3) = 0;

slika = uint8(slika);

axes(handles.axesTrenutniFrame);
g = imshow(slika);
set(g,'HitTest','off');

I also tried to set NextPlot to other values. Everithing but
'Replace' rescales my image. Can you help me so that I can
get image that perfectly fits to the axes, and that I get
axesTrenutniFrame_ButtonDownFcn called when I click on the image

Thanx.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us