Why I can draw lines on the Axes but can't draw lines anymore after imshow a picture on Axes?

3 views (last 30 days)
Hi, I want to build a gui to draw lines on an image. I can draw lines before load a image on Axes. But after I imshow the image, which I want to draw lines on, on Axes, I can't draw lines anymore. And I also tracked the data. The data can be stored before imshow an image. But nothing happened after load the image. Here is part of my code for open a file and draw a line. Moreover, I have already defined all the values at very beginning. Hope it can be solved. Thanks in advance.
function open_ClickedCallback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.img=imread([pathname filename]);
function drawlines_Callback( hObject, eventdata,handles)
% hObject handle to drawlines (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function start_pencil(hObject,eventdata,handles)
coords=get(gca,'CurrentPoint'); %since this is the axes callback, src=gca
r=line(x, y, 'color', 'g', 'LineWidth', 2, 'hittest', 'off'); %turning hittset off allows you to draw new lines that start on top of an existing line.
handles.r = [handles.r r];
function continue_pencil(hObject,eventdata,r,handles)
%Note: src is now the figure handle, not the axes, so we need to use gca.
coords=get(gca,'currentpoint'); %this updates every time i move the mouse
%get the line's existing coordinates and append the new ones.
newx=[lastx x];
newy=[lasty y];
global C;
guidata(hObject, handles);
function done_pencil(hObject,eventdata,handles)
%all this function does is turn the motion function off
guidata(hObject, handles);

Accepted Answer

Image Analyst
Image Analyst on 28 Jan 2014
Why do functions like continue_pencil() not have _Callback after them, like OutputToComputer_Callback() does? Did you have GUIDE create them automatically or did you try to manually create your own callback functions with your own names? Does the function continue_pencil() ever get executed? That's the only function where handles.coord field is attached to handles, so if that function never executes, then handles won't have that field when you get inside OutputToComputer_Callback().

More Answers (1)

AJ von Alt
AJ von Alt on 28 Jan 2014
OutputToComputer_Callback may be called before continue_pencil. You should initialize handles.coord in your opening function.


Find more on Migrate GUIDE Apps 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!