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:
GUI to load image and draw on it???

Subject: GUI to load image and draw on it???

From: Becca Davidson

Date: 3 Nov, 2008 15:59:02

Message: 1 of 9

Hi Everyone,

I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.

Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.

I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?

Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?

Thank You,
Becca

Subject: GUI to load image and draw on it???

From: Dave Brackett

Date: 3 Nov, 2008 16:44:02

Message: 2 of 9

"Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> Hi Everyone,
>
> I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
>
> Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
>
> I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
>
> Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
>
> Thank You,
> Becca

What do you mean exactly by 'draw on top of the image'. Draw what?

It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.

Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').

Then run the .m file.

Subject: GUI to load image and draw on it???

From: Becca Davidson

Date: 3 Nov, 2008 16:54:02

Message: 3 of 9

Thank you very much for your guidance Dave.

The user should be able to open an image, then freedraw on top of the image. If that is not possible or too complicated, then a straight line should suffice.

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <gen9oi$dqo$1@fred.mathworks.com>...
> "Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> > Hi Everyone,
> >
> > I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
> >
> > Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
> >
> > I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
> >
> > Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
> >
> > Thank You,
> > Becca
>
> What do you mean exactly by 'draw on top of the image'. Draw what?
>
> It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.
>
> Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').
>
> Then run the .m file.

Subject: GUI to load image and draw on it???

From: Dave Brackett

Date: 3 Nov, 2008 17:20:17

Message: 4 of 9

Ok. Once you have created your GUI layout, go to the callbacks .m file and near the top of the file should be a section titled:
"% --- Executes just before test is made visible."

Within this function type the following:

axes(handles.axes1) % this gives focus to the axes object you created (the number may be different)
imshow('your_image_filename_here.jpg') % this shows the image specified within the apostrophes in the axes

Go to this submission on the matlab file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/7347
and download the .m file. Place it in the same directory as your GUI and associated .m file.

Beneath the imshow statement in your code type this line:
[myobj,xs,ys] = freehanddraw(gca,'color','r','linewidth',3); % this calls the function you downloaded from the file exchange.

Read the comments in freehanddraw.m to get an understanding of what it does and how you can use it for your application.

Hope that helps,
Dave


"Becca Davidson" <becca.davidson@gmail.com> wrote in message <genaba$m0s$1@fred.mathworks.com>...
> Thank you very much for your guidance Dave.
>
> The user should be able to open an image, then freedraw on top of the image. If that is not possible or too complicated, then a straight line should suffice.
>
> "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gen9oi$dqo$1@fred.mathworks.com>...
> > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> > > Hi Everyone,
> > >
> > > I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
> > >
> > > Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
> > >
> > > I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
> > >
> > > Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
> > >
> > > Thank You,
> > > Becca
> >
> > What do you mean exactly by 'draw on top of the image'. Draw what?
> >
> > It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.
> >
> > Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').
> >
> > Then run the .m file.

Subject: GUI to load image and draw on it???

From: Becca Davidson

Date: 3 Nov, 2008 18:42:02

Message: 5 of 9

Thank you Dave - your explanation was perfect and I have it all working.

The function returns an array of x's and y's. The next step is for me to draw a line on the original image.

Can anyone explain how to accomplish this or point me in the direction of a good resource?

Thanks again Dave. That was great.

"Becca Davidson" <becca.davidson@gmail.com> wrote in message <genaba$m0s$1@fred.mathworks.com>...
> Thank you very much for your guidance Dave.
>
> The user should be able to open an image, then freedraw on top of the image. If that is not possible or too complicated, then a straight line should suffice.
>
> "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gen9oi$dqo$1@fred.mathworks.com>...
> > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> > > Hi Everyone,
> > >
> > > I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
> > >
> > > Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
> > >
> > > I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
> > >
> > > Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
> > >
> > > Thank You,
> > > Becca
> >
> > What do you mean exactly by 'draw on top of the image'. Draw what?
> >
> > It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.
> >
> > Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').
> >
> > Then run the .m file.

Subject: GUI to load image and draw on it???

From: Dave Brackett

Date: 3 Nov, 2008 19:26:03

Message: 6 of 9

The 'line' function will do what you want. Type 'help line' in the command window.



"Becca Davidson" <becca.davidson@gmail.com> wrote in message <genglp$eu5$1@fred.mathworks.com>...
> Thank you Dave - your explanation was perfect and I have it all working.
>
> The function returns an array of x's and y's. The next step is for me to draw a line on the original image.
>
> Can anyone explain how to accomplish this or point me in the direction of a good resource?
>
> Thanks again Dave. That was great.
>
> "Becca Davidson" <becca.davidson@gmail.com> wrote in message <genaba$m0s$1@fred.mathworks.com>...
> > Thank you very much for your guidance Dave.
> >
> > The user should be able to open an image, then freedraw on top of the image. If that is not possible or too complicated, then a straight line should suffice.
> >
> > "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gen9oi$dqo$1@fred.mathworks.com>...
> > > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> > > > Hi Everyone,
> > > >
> > > > I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
> > > >
> > > > Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
> > > >
> > > > I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
> > > >
> > > > Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
> > > >
> > > > Thank You,
> > > > Becca
> > >
> > > What do you mean exactly by 'draw on top of the image'. Draw what?
> > >
> > > It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.
> > >
> > > Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').
> > >
> > > Then run the .m file.

Subject: GUI to load image and draw on it???

From: Becca Davidson

Date: 3 Nov, 2008 21:27:01

Message: 7 of 9

Thanks again Dave.

I'm not convinced the line() method is doing it. It seems like it is drawing the line on the plot rather than changing the colros of the pixels on the image.

Is there an easy way to save the image, with the changes?

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <genj8b$s60$1@fred.mathworks.com>...
> The 'line' function will do what you want. Type 'help line' in the command window.
>
>
>
> "Becca Davidson" <becca.davidson@gmail.com> wrote in message <genglp$eu5$1@fred.mathworks.com>...
> > Thank you Dave - your explanation was perfect and I have it all working.
> >
> > The function returns an array of x's and y's. The next step is for me to draw a line on the original image.
> >
> > Can anyone explain how to accomplish this or point me in the direction of a good resource?
> >
> > Thanks again Dave. That was great.
> >
> > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <genaba$m0s$1@fred.mathworks.com>...
> > > Thank you very much for your guidance Dave.
> > >
> > > The user should be able to open an image, then freedraw on top of the image. If that is not possible or too complicated, then a straight line should suffice.
> > >
> > > "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gen9oi$dqo$1@fred.mathworks.com>...
> > > > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> > > > > Hi Everyone,
> > > > >
> > > > > I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
> > > > >
> > > > > Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
> > > > >
> > > > > I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
> > > > >
> > > > > Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
> > > > >
> > > > > Thank You,
> > > > > Becca
> > > >
> > > > What do you mean exactly by 'draw on top of the image'. Draw what?
> > > >
> > > > It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.
> > > >
> > > > Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').
> > > >
> > > > Then run the .m file.

Subject: GUI to load image and draw on it???

From: Dave Brackett

Date: 3 Nov, 2008 22:20:04

Message: 8 of 9

You can 'merge' the original image and the overlayed line using the 'getframe' command like this:

n=2; % no points to create line
[x,y] = ginput(n); % allows user to pick points with mouse to create line
line(x,y) % creates line
image_with_line=getframe(gcf); % creates a merged image
image_with_line=image_with_line.cdata; % extracts the image from the structure created by getframe
figure
imshow(image_with_line)


Use this idea for your GUI axes.

Dave


"Becca Davidson" <becca.davidson@gmail.com> wrote in message <genqb5$59p$1@fred.mathworks.com>...
> Thanks again Dave.
>
> I'm not convinced the line() method is doing it. It seems like it is drawing the line on the plot rather than changing the colros of the pixels on the image.
>
> Is there an easy way to save the image, with the changes?
>
> "Dave Brackett" <davebrackett@hotmail.com> wrote in message <genj8b$s60$1@fred.mathworks.com>...
> > The 'line' function will do what you want. Type 'help line' in the command window.
> >
> >
> >
> > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <genglp$eu5$1@fred.mathworks.com>...
> > > Thank you Dave - your explanation was perfect and I have it all working.
> > >
> > > The function returns an array of x's and y's. The next step is for me to draw a line on the original image.
> > >
> > > Can anyone explain how to accomplish this or point me in the direction of a good resource?
> > >
> > > Thanks again Dave. That was great.
> > >
> > > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <genaba$m0s$1@fred.mathworks.com>...
> > > > Thank you very much for your guidance Dave.
> > > >
> > > > The user should be able to open an image, then freedraw on top of the image. If that is not possible or too complicated, then a straight line should suffice.
> > > >
> > > > "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gen9oi$dqo$1@fred.mathworks.com>...
> > > > > "Becca Davidson" <becca.davidson@gmail.com> wrote in message <gen746$jkd$1@fred.mathworks.com>...
> > > > > > Hi Everyone,
> > > > > >
> > > > > > I am relatively new to Matlab, and I have been given a task to be integrated into a research project in my Lab. I would appreciate some help if you have a moment.
> > > > > >
> > > > > > Basically, I need to load an image in Matlab using a Gui. Then the user should be able to draw on top of the image.
> > > > > >
> > > > > > I am not sure where to start with this task and have limited familiarity with Matlab. Where should I start?
> > > > > >
> > > > > > Also, can this be done in matlab. Would it be better to do parts of the GUI in java and integrate it with Matlab?
> > > > > >
> > > > > > Thank You,
> > > > > > Becca
> > > > >
> > > > > What do you mean exactly by 'draw on top of the image'. Draw what?
> > > > >
> > > > > It is easy to display an image in a GUI but if you can clarify what you want with regards to the drawing aspect we can provide further help.
> > > > >
> > > > > Type 'guide' into the command window and this will bring up the GUI tool. Click on the axes control on the left toolbar and drag it onto the grid. Resize how you want. Now right click on that axes object and go to callbacks. This will create the .m file associated with the GUI figure. In that space you can then type simple code to load the image, e.g. axes(handles.axes1), then imshow('your picture filename here').
> > > > >
> > > > > Then run the .m file.

Subject: GUI to load image and draw on it???

From: DS

Date: 10 Nov, 2008 16:42:02

Message: 9 of 9

Becca -

This code (mpaint) by Joaquim Luis on the File Exchange might be helpful:

http://www.mathworks.com/matlabcentral/fileexchange/14418

-DS

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