Thread Subject: How to attached a JPEG picture to a GUI?

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 08:08:13

Message: 1 of 28

Hi,

I'm quite new to matlab, currently using ver6.5. I need to
attached a JPEG picture to a GUI (like a logo), how do I do
that?

I tried the following, but it doesn't works.

axes('position',[0.1 0.85 0.1 0.1]),
imshow('1.jpeg')

need some help here.

Jean

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 08:20:03

Message: 2 of 28

You have to do it that way:
axes(handles.ViewBox1);
imshow(im)

handles.ViewBox1 is a handle to Your axis. so You
just write handles.NameOfYourAxis and after that only
show Your picture by imshow(im) or image(im)

hope this help!

 kind regards,
     misty

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 08:54:01

Message: 3 of 28

"misty m." <donotspam@smth.be> wrote in message
<g1drrj$7pt$1@fred.mathworks.com>...
> You have to do it that way:
> axes(handles.ViewBox1);
> imshow(im)
>
> handles.ViewBox1 is a handle to Your axis. so You
> just write handles.NameOfYourAxis and after that only
> show Your picture by imshow(im) or image(im)
>
> hope this help!
>
> kind regards,
> misty
>
>

I'm sorry, I'm totally new to this. What does "handle to
Your axis" means?

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 09:05:09

Message: 4 of 28

handle, as word suggests, is a handle to some object. using
handles You can for example call in second function to an
object A which is definied in first function.

maybe try at first to read a little about making GUI? there
is quite a lot of examples on google (and in matlab help).
this site is quite nice:

http://www.caspur.it/risorse/softappl/doc/matlab_help/techdo
c/creating_guis/creating_guis.html

kind regards,
 misty

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 09:09:04

Message: 5 of 28

is this the way?

function ViewBox1(hObject, eventdata, handles)
axes(handles.ViewBox1);
imshow('C:\MATLAB6p5\work\1.JPG')

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 09:23:03

Message: 6 of 28

You write it manually or using guide? normally, if You want
the image to be shown the same moment as GUI appears, You
sholud put

axes(handles.ViewBox1);
imshow('C:\MATLAB6p5\work\1.JPG')


into:
function NameOfYourGui_OpeningFcn(hObject, eventdata,
handles, varargin)

so, into an opening function.

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 09:57:02

Message: 7 of 28

"misty m." <donotspam@smth.be> wrote in message
<g1dvhn$p7a$1@fred.mathworks.com>...
> You write it manually or using guide? normally, if You
want
> the image to be shown the same moment as GUI appears, You
> sholud put
>
> axes(handles.ViewBox1);
> imshow('C:\MATLAB6p5\work\1.JPG')
>
>
> into:
> function NameOfYourGui_OpeningFcn(hObject, eventdata,
> handles, varargin)
>
> so, into an opening function.
>
> i'm editing from a guide. Thanks. I'll try it out. Sorry
for the trouble

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 10:09:01

Message: 8 of 28

error message popped up when I typed in these

function GUI_2_OpeningFcn(hObject, eventdata, handles,
varargin)

% Choose default command line output for GUI_2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

axes(handles.ViewBox1);
imshow('C:\MATLAB6p5\work\1.JPG')


Error message as shown

??? Error while evaluating uicontrol CreateFcn.

??? Reference to non-existent field 'ViewBox1'.

Error in ==> C:\MATLAB6p5\work\GUI_2.m (GUI_2_OpeningFcn)
On line 69 ==> axes(handles.ViewBox1);

Error in ==> C:\MATLAB6p5
\toolbox\matlab\uitools\gui_mainfcn.m
On line 141 ==> feval(gui_State.gui_OpeningFcn,
gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ==> C:\MATLAB6p5\work\GUI_2.m
On line 42 ==> gui_mainfcn(gui_State, varargin{:});

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 10:20:02

Message: 9 of 28

does Your axis has a name 'ViewBox1'? problably it has
rather 'axis1'. You can check it, by clicking twice on an
element. and is Your ViewBox/axis of the type 'axis' ? or
is it for example panel?

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 10:26:01

Message: 10 of 28

sorry to bother,

if i'm using guide, in the figure window i drag an axes
window, where in the property inspector do i type in this

imshow('C:\MATLAB6p5\work\1.JPG')?

is it in the tag function?

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 10:36:02

Message: 11 of 28

?
nowhere. You must write it in Your file, in the opening
function, as i wrote You before.
try to read this manual i send You.

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 10:46:02

Message: 12 of 28

"misty m." <donotspam@smth.be> wrote in message <g1e3qi$dl7
$1@fred.mathworks.com>...
> ?
> nowhere. You must write it in Your file, in the opening
> function, as i wrote You before.
> try to read this manual i send You.


hi,

i got my code running, thanks

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 11:13:02

Message: 13 of 28

hi,

how to remove the wording above the JPG that is attached to
the GUI?

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 11:20:03

Message: 14 of 28

what do You mean?

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 16:02:02

Message: 15 of 28

"misty m." <donotspam@smth.be> wrote in message <g1e6d3
$1vg$1@fred.mathworks.com>...
> what do You mean?

there's a line of wording "1.jpg" above the jpeg file. how
to remove that?

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 17:50:03

Message: 16 of 28

if it is on an image, then cut?/put smth on it?
it it is on the axis/panel etc You can remove it when You
click twice on the object - there'll find properties of
object and You can delete the name

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 18:35:02

Message: 17 of 28

"misty m." <donotspam@smth.be> wrote in message
<g1et8b$oqm$1@fred.mathworks.com>...
> if it is on an image, then cut?/put smth on it?
> it it is on the axis/panel etc You can remove it when You
> click twice on the object - there'll find properties of
> object and You can delete the name
>

it is on the axis and it can't be remove, cannot find
anything on the property inspector that can remove it.
seems like when attaching the JPG, the name of the file is
automatically shown above the JPG.

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 18:44:02

Message: 18 of 28

it is not, as i also was doing gui showing images few days
ago. probalby You put the name somewhere.

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 26 May, 2008 18:53:01

Message: 19 of 28

"misty m." <donotspam@smth.be> wrote in message
<g1f0di$erd$1@fred.mathworks.com>...
> it is not, as i also was doing gui showing images few
days
> ago. probalby You put the name somewhere.

I tried to change the name in the ' ',

imshow('C:\MATLAB6p5\work\1.jpg');

it print the text within the '', no matter where i attached
the file from, it just print out 'C:\MATLAB6p5\work\1.jpg
in this case,on top of the jpg attached. why is that so?

Subject: How to attached a JPEG picture to a GUI?

From: misty m.

Date: 26 May, 2008 19:02:02

Message: 20 of 28

try copy Your image to Your workspace and then simply:

imshow(name_of_image.jpg)

Subject: How to attached a JPEG picture to a GUI?

From: Jean Lim

Date: 27 May, 2008 11:23:02

Message: 21 of 28

"misty m." <donotspam@smth.be> wrote in message
<g1f1fa$lqn$1@fred.mathworks.com>...
> try copy Your image to Your workspace and then simply:
>
> imshow(name_of_image.jpg)

i used a blank static text box to cover it.

thanks a lot :)

Subject: How to attached a JPEG picture to a GUI?

From: Omur Bas

Date: 27 May, 2008 12:08:01

Message: 22 of 28

"Jean Lim" <inno_pf@yahoo.com.sg> wrote in message
<g1gqum$rf7$1@fred.mathworks.com>...
> "misty m." <donotspam@smth.be> wrote in message
> <g1f1fa$lqn$1@fred.mathworks.com>...
> > try copy Your image to Your workspace and then simply:
> >
> > imshow(name_of_image.jpg)
>
> i used a blank static text box to cover it.
>
> thanks a lot :)
>

Instead of imshow(name_of_image.jpg), assuming it's an RGB
image, try
imshow(imread(name_of_image.jpg))
if it's not an RGB image (i.e., this produces an error :))
then try
[A,map]=imread(name_of_image.jpg)
imshow(A),colormap(map)

This should disassociate the image from the file.

Also try
axis off (it should be off already with imshow, but just in
case)
and/or
set(axis_handle,'title','')

Hope this helps,
Omur
www.promodsoftware.com.tr

Subject: How to attached a JPEG picture to a GUI?

From: Steven Lord

Date: 26 May, 2008 23:27:34

Message: 23 of 28


"Jean Lim" <inno_pf@yahoo.com.sg> wrote in message
news:g1f0ud$i6u$1@fred.mathworks.com...
> "misty m." <donotspam@smth.be> wrote in message
> <g1f0di$erd$1@fred.mathworks.com>...
>> it is not, as i also was doing gui showing images few
> days
>> ago. probalby You put the name somewhere.
>
> I tried to change the name in the ' ',
>
> imshow('C:\MATLAB6p5\work\1.jpg');
>
> it print the text within the '', no matter where i attached
> the file from, it just print out 'C:\MATLAB6p5\work\1.jpg
> in this case,on top of the jpg attached. why is that so?

Try using the TITLE function to set the title of your axes to ''.
Alternately, since you're using the most basic form of IMSHOW, I think you
could just replace that with a call to IMAGE, which I believe will not set
the title.

--
Steve Lord
slord@mathworks.com

Subject: How to attached a JPEG picture to a GUI?

From: Scott

Date: 31 May, 2008 21:16:01

Message: 24 of 28

"Jean Lim" <inno_pf@yahoo.com.sg> wrote in message
<g1dr5d$22k$1@fred.mathworks.com>...
> Hi,
>
> I'm quite new to matlab, currently using ver6.5. I need
to
> attached a JPEG picture to a GUI (like a logo), how do I
do
> that?
>
> I tried the following, but it doesn't works.
>
> axes('position',[0.1 0.85 0.1 0.1]),
> imshow('1.jpeg')
>
> need some help here.
>
> Jean

Jean,

I generally do one thing to put an image on an axes and
something different to put the image on a button:

% Read in Image Data
[filename, pathname] = uigetfile('*.jpg','Pick a JPEG');
info=imfinfo([pathname filename])
img = imread([pathname filename]);

% Display the image on a figure
szi = size(img)
screensize = get(0,'ScreenSize');
xposi = (screensize(3)/2)-szi(2)-10;
yposi = ceil((screensize(4)-szi(1))/2);
hi = figure('position',[xposi, yposi, szi(2), szi(1)],...
            'units', 'pixels',...
            'renderer', 'painters',...
            'MenuBar', 'none',...
            'Name','Axes Image');
set(gcf,'PaperPositionMode','auto');
imagesc(img);
set(gca,'Position',[0, 0, 1, 1]);
axis image off;

% Display the image in a button
L = uint8(img);
xposb = xposi+szi(2)+10;
yposb = ceil((screensize(4)-szi(1))/2);
hb = figure('position', [xposb, yposb, szi(2), szi(1)],...
            'units','pixels',...
            'renderer', 'zbuffer',...
            'MenuBar', 'none',...
            'Name','Button Image');
b = uicontrol('pos', [1, 1, szi(2), szi(1)],...
              'cdata',L,...
              'SelectionHighlight','off');
          
% cleanup workspace
clear L b hb hi img screensize szb szi xposb
clear xposi yposb yposi filename info pathname
% end of code

You can simulate image data with something like:
img = uint8(ceil(rand(250,350,3)*200));

hth,
Scott

Subject: An useful example: displaying a PNG image in a parent figure

From: Mihail Petrov

Date: 6 Jun, 2008 11:02:01

Message: 25 of 28

Alternatively, try the following:

Image = imread('H2BlockDiagram.png', 'BackgroundColor',get
(FH,'Color'));
ImSize = size(Image);
axes('Parent',FH, 'Units','pixels', 'Position',[10 10 ImSize
(2) ImSize(1)]);
image(Image); axis off;

FH is the handle to the parent figure. The image is
displayed at coordinates [10 10].

A very nice feature of using PNG files is that you can
define a background color, which you can then replace with
your figure background. The result looks great for drawings.

Subject: How to attached a JPEG picture to a GUI?

From: Vids Bhosale

Date: 10 Jan, 2011 15:28:05

Message: 26 of 28

"Omur Bas" <omur.bas@promodxxxxxx.com.tr> wrote in message <g1gtj1$i35$1@fred.mathworks.com>...
> "Jean Lim" <inno_pf@yahoo.com.sg> wrote in message
> <g1gqum$rf7$1@fred.mathworks.com>...
> > "misty m." <donotspam@smth.be> wrote in message
> > <g1f1fa$lqn$1@fred.mathworks.com>...
> > > try copy Your image to Your workspace and then simply:
> > >
> > > imshow(name_of_image.jpg)
> >
> > i used a blank static text box to cover it.
> >
> > thanks a lot :)
> >
>
> Instead of imshow(name_of_image.jpg), assuming it's an RGB
> image, try
> imshow(imread(name_of_image.jpg))
> if it's not an RGB image (i.e., this produces an error :))
> then try
> [A,map]=imread(name_of_image.jpg)
> imshow(A),colormap(map)
>
> This should disassociate the image from the file.
>
> Also try
> axis off (it should be off already with imshow, but just in
> case)
> and/or
> set(axis_handle,'title','')
>
> Hope this helps,
> Omur
> www.promodsoftware.com.tr
>
>
>
hey thanxxx a lot.I had same doubt while working with it & I got it working by including imshow(imread(name_of_file.jpg)).thanx again.

Subject: How to attached a JPEG picture to a GUI?

From: Vids Bhosale

Date: 10 Jan, 2011 15:29:04

Message: 27 of 28

"Omur Bas" <omur.bas@promodxxxxxx.com.tr> wrote in message <g1gtj1$i35$1@fred.mathworks.com>...
> "Jean Lim" <inno_pf@yahoo.com.sg> wrote in message
> <g1gqum$rf7$1@fred.mathworks.com>...
> > "misty m." <donotspam@smth.be> wrote in message
> > <g1f1fa$lqn$1@fred.mathworks.com>...
> > > try copy Your image to Your workspace and then simply:
> > >
> > > imshow(name_of_image.jpg)
> >
> > i used a blank static text box to cover it.
> >
> > thanks a lot :)
> >
>
> Instead of imshow(name_of_image.jpg), assuming it's an RGB
> image, try
> imshow(imread(name_of_image.jpg))
> if it's not an RGB image (i.e., this produces an error :))
> then try
> [A,map]=imread(name_of_image.jpg)
> imshow(A),colormap(map)
>
> This should disassociate the image from the file.
>
> Also try
> axis off (it should be off already with imshow, but just in
> case)
> and/or
> set(axis_handle,'title','')
>
> Hope this helps,
> Omur
> www.promodsoftware.com.tr
>
>
>
hey thanxxx a lot.I had same doubt while working with it & I got it working by including imshow(imread(name_of_file.jpg)).thanx again.

Subject: How to attached a JPEG picture to a GUI?

From: Vids Bhosale

Date: 10 Jan, 2011 15:36:04

Message: 28 of 28


> Instead of imshow(name_of_image.jpg), assuming it's an RGB
> image, try
> imshow(imread(name_of_image.jpg))
> if it's not an RGB image (i.e., this produces an error :))
> then try
> [A,map]=imread(name_of_image.jpg)
> imshow(A),colormap(map)
>
> This should disassociate the image from the file.
>
> Also try
> axis off (it should be off already with imshow, but just in
> case)
> and/or
> set(axis_handle,'title','')
>
> Hope this helps,
> Omur
> www.promodsoftware.com.tr
>
>
>
Hey thanxxx I had same doubt & I solved it.your first line of code works fine.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
picture Jean Lim 26 May, 2008 07:15:07
jpg Jean Lim 26 May, 2008 06:30:08
gui Jean Lim 26 May, 2008 04:10:06
jpeg Jean Lim 26 May, 2008 04:10:06
rssFeed for this Thread

Contact us at files@mathworks.com