Dear
Can anyone help me to get the coordinates of my mouse only inside an axes. I want to make an erose function with my mouse.
So when I push my button I got this code:
global hSeg;
global axesWidth; global axesHeight;
axesPositions= get(hSeg,'Outerposition'); % this don't work
axesWidth = axesPositions(1,3); % this don't work
axesHeight = axesPositions(1,4); % this don't work
hFig = get(0,'CurrentFigure');
set(hFig,'WindowButtonMotionFcn',@moviment);
set(hFig,'WindowButtonDownFcn',@moviment_down);
This code I got for my moviment function:
function moviment(hco,eventStruct)
global hSeg;
global axesWidth; global axesHeight;
p = get(hSeg,'CurrentPoint');
x = p(1,1);
y = p(1,2);
if x >= 0 && x <= axesWidth && y >= 0 && y <= axesHeight;
x
y
end
The problem is that I get the wrong results for axesWidth and axesHeight. This means that I can only select in a small part of the axes
Thanks in advance
Jan
|
|
0
|
|
|
|
Reply
|
Jan
|
4/29/2010 12:12:04 PM |
|
See Q#29
http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples
|
|
0
|
|
|
|
Reply
|
Matt
|
4/29/2010 4:18:05 PM
|
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <hrcbft$382$1@fred.mathworks.com>...
> See Q#29
> http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples
Hi!!!!
How could I modify the script so that it works if I have all my figure, buttons, panel... defined in "units normalized"?
The result I want is the x y coordinates over my imagesc.
Thanks!!
Camille.
|
|
0
|
|
|
|
Reply
|
Camille
|
8/18/2010 4:15:24 PM
|
|
"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i4h0us$k0v$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message <hrcbft$382$1@fred.mathworks.com>...
> > See Q#29
> > http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples
>
>
> Hi!!!!
> How could I modify the script so that it works if I have all my figure, buttons, panel... defined in "units normalized"?
> The result I want is the x y coordinates over my imagesc.
> Thanks!!
>
> Camille.
Hi
I used this method:
- I put this code behind a toggle button
set(hFig,'WindowButtonMotionFcn',@moviment);
set(hFig,'WindowButtonDownFcn',@moviment_down);
set(hFig,'WindowButtonUpFcn',@moviment_up);
- Function movement:
p = get(hSeg,'CurrentPoint');
xPixel = p(1,1);
yPixel = p(1,2);
% We need image width and height due to the different measurements and
% fixed size of axes.
if xPixel >= 0 && xPixel <= imWidth && yPixel >= 0 && yPixel <= imHeight;
set(gcf,'Pointer','cross');
if MouseDown == 1
if ySegmented(round(yPixel),round(xPixel)) == 1
ySegmented(round(yPixel),round(xPixel)) = 0;
end
axes(hSeg);
reset(hSeg);
imagesc(ySegmented);
axis image;
axis off;
end
else
set(gcf,'Pointer','arrow');
end
- Function movement_up:
global MouseDown;
% If mousebutton is released, pixels my not be changed
MouseDown = 0;
- Function movement_down
MouseDown = 1;
% For all the togglebuttons there is an if-structure where they will add
% pixels or erase pixels from the segmented image
p = get(hSeg,'CurrentPoint');
xPixel = p(1,1);
yPixel = p(1,2);
if xPixel >= 0 && xPixel <= imWidth && yPixel >= 0 && yPixel <= imHeight;
set(gcf,'Pointer','cross');
if MouseDown == 1
if ySegmented(round(yPixel),round(xPixel)) == 1
ySegmented(round(yPixel),round(xPixel)) = 0;
end
axes(hSeg);
reset(hSeg);
imagesc(ySegmented);
axis image;
axis off;
end
else
set(gcf,'Pointer','arrow');
end
Is this clear to you?
Jan
|
|
0
|
|
|
|
Reply
|
Jan
|
8/23/2010 8:01:07 AM
|
|
|
3 Replies
1178 Views
(page loaded in 0.067 seconds)
|