Thread Subject: GUI Current pointer location on displayed image

Subject: GUI Current pointer location on displayed image

From: Richard

Date: 5 Nov, 2009 20:35:03

Message: 1 of 3

Ran into a little problem with my GUI program today. I would like eventually to create lines and boxes on top of a displayed image. Any help or reference to websites or functions would be much appreciated.

Here's what I did if you are trying to recreate the problem. Using guide create an axes tagged as Picture. Then in the m-editor under the function that executes before figure is made visible, display a jpeg on the axes...

axes(handles.Picture)
image(imread('Picture.jpg')) %loads and displays Picture.jpg

Now I want to set up a click-able box using ButtonDownFcn or WindowButtonDownFcn(preferably the previous ButtonDownFcn) , WindowMotionFcn and WindowButtonUpFcn.

I run into a problem with getting my mouse position on the image,
"There is no 'CurrentPoint' property in the 'image' class"
Seems like there should be a way of getting mouse location without ginput for an image because you can do it for a normal plot...
I'm using 2007b btw

Subject: GUI Current pointer location on displayed image

From: Richard

Date: 7 Nov, 2009 00:34:02

Message: 2 of 3

"Richard " <rjtennant@greeneridge.com> wrote in message <hcvctn$4qa$1@fred.mathworks.com>...
> Ran into a little problem with my GUI program today. I would like eventually to create lines and boxes on top of a displayed image. Any help or reference to websites or functions would be much appreciated.
>
> Here's what I did if you are trying to recreate the problem. Using guide create an axes tagged as Picture. Then in the m-editor under the function that executes before figure is made visible, display a jpeg on the axes...
>
> axes(handles.Picture)
> image(imread('Picture.jpg')) %loads and displays Picture.jpg
>
> Now I want to set up a click-able box using ButtonDownFcn or WindowButtonDownFcn(preferably the previous ButtonDownFcn) , WindowMotionFcn and WindowButtonUpFcn.
>
> I run into a problem with getting my mouse position on the image,
> "There is no 'CurrentPoint' property in the 'image' class"
> Seems like there should be a way of getting mouse location without ginput for an image because you can do it for a normal plot...
> I'm using 2007b btw

I am pretty new to OOP and GUI programming and after a day more of research, I found a workable solution. The point was realizing that the image was a child of the figure and the only child in this case, so get(get(gcf,'Children'),'CurrentPoint') gave me the current mouse position. Hope this helps someone!

Subject: GUI Current pointer location on displayed image

From: Richard

Date: 7 Nov, 2009 01:31:21

Message: 3 of 3

"Richard " <rjtennant@greeneridge.DOTCOM> wrote in message <hd2f9q$p6q$1@fred.mathworks.com>...
> "Richard " <rjtennant@greeneridge.com> wrote in message <hcvctn$4qa$1@fred.mathworks.com>...
> > Ran into a little problem with my GUI program today. I would like eventually to create lines and boxes on top of a displayed image. Any help or reference to websites or functions would be much appreciated.
> >
> > Here's what I did if you are trying to recreate the problem. Using guide create an axes tagged as Picture. Then in the m-editor under the function that executes before figure is made visible, display a jpeg on the axes...
> >
> > axes(handles.Picture)
> > image(imread('Picture.jpg')) %loads and displays Picture.jpg
> >
> > Now I want to set up a click-able box using ButtonDownFcn or WindowButtonDownFcn(preferably the previous ButtonDownFcn) , WindowMotionFcn and WindowButtonUpFcn.
> >
> > I run into a problem with getting my mouse position on the image,
> > "There is no 'CurrentPoint' property in the 'image' class"
> > Seems like there should be a way of getting mouse location without ginput for an image because you can do it for a normal plot...
> > I'm using 2007b btw
>
> I am pretty new to OOP and GUI programming and after a day more of research, I found a workable solution. The point was realizing that the image was a child of the figure and the only child in this case, so get(get(gcf,'Children'),'CurrentPoint') gave me the current mouse position. Hope this helps someone!

oooh my goodness i just solved my problem!
Well I was trying to draw a box on an image, and was almost gonna give up but... discovered waitforbuttonpress, because I was having problems with WindowButtonMotionFcn trumping every other callback in the queue.
So anyways, kinda a weak solution but here it is.

my start box function is what is executed on ButtonDownFcn
function StartBox(obj,evnt)
pt=get(get(gcf,'Children'),'CurrentPoint')
h=line('Xdata', pt(1,1),'Ydata',pt(1,2))
set(f,'WindowButtonMotion', {@DrawBox,h,pt})
waitforbuttonpress
set(f,'WindowButtonMotion', '')

Where the DrawBox function just gets the current points in the same way and sets the x & y data.

So when button is pressed, it draws initial point, then DrawBox takes over which is constantly refreshed and does the fancy stuff, but next time a button is pressed, in my case when I want to close the box, the StartBox finishes executing and stops any motion function. Cool Beans

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
mouse Richard 5 Nov, 2009 15:39:04
image Richard 5 Nov, 2009 15:39:04
gui Richard 5 Nov, 2009 15:39:03
rssFeed for this Thread

Contact us at files@mathworks.com