Creating a mouse down event specific to an axes1 component only
Show older comments
I am using the following to allow the user to use the mouse press to draw a marker on an image loaded to an axes component (axes1). There are other axes also on my GUI, and I want to be able to constrain this mouse action only if the mouse is over axes 1. Currently it also draws a marker when over other axes.
I put this in the opening function.
set(gcf, 'WindowButtonDownFcn', @getMousePositionOnImage);
And then use this function for the mouse click.
function getMousePositionOnImage(src, event)
handles = guidata(src);
cursorPoint = get(handles.axes1, 'CurrentPoint');
curX = cursorPoint(1,1);
curY = cursorPoint(1,2);
%check if mouse clicked outside of axes component
xLimits = get(handles.axes1, 'xlim');
yLimits = get(handles.axes1, 'ylim');
if (curX<min(xLimits)) (curX==min(xLimits))
end
if (curX>max(xLimits)) (curX==max(xLimits))
end
if (curY<min(yLimits)) (curY==min(yLimits))
end
if (curY>max(yLimits)) (curY==max(yLimits))
end
x=round(curX)
y=round(curY)
setappdata(0,'curX',x);
setappdata(0,'curY',y);
%Remove previous marker if present
delete( findobj(gca, 'type', 'line') );
hold on
plot(x,y,'ro','MarkerSize',10,'LineWidth',2)
hold off;
IMG = getimage(handles.axes1);
delta=50;
if (x<delta+1)|| (y<delta+1)
ROI = IMG(1:delta, 1:delta,:); % This is the ROI (indexing is (ymin:ymax, xmin:xmax)
else
ROI = IMG(y-delta:y+delta, x-delta:x+delta,:); % This is the ROI (indexing is (ymin:ymax, xmin:xmax)
end
%Now take a ROI around the marker position (i.e. where mouse is clicked)
%and draw in axes 3
axes(handles.axes3)
cla
[high,low]=Autoscaleimage(handles,ROI,3);
imshow(ROI,[low,high]);
hold on
plot(delta+1,delta+1,'ro','MarkerSize',10,'LineWidth',2);
hold off
1 Comment
Jason
on 12 Oct 2015
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!