plot line in image via GUI?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HI,
If i use this code, i'm able to draw line on my image. However when i transfer the code into GUI the line do not appears in the same axes as the image.
imshow(A);
hold on;
c=rand(1,3);
for n=1:10
plot([1 20+n*100],[30 10+n*100],'-','Color',c);
end
Code in GUI:
% --- Executes on button press in advance.
function advance_Callback(hObject, eventdata, handles)
% hObject handle to advance (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
imshow(a,'parent',handles.im2);
hold on;
c=rand(1,3);
for n=1:10
plot([1 20+n*100],[30 10+n*100],'-','Color',c,'parent',handles.im2);
end
if i were to use
plot([1 20+n*100],[30 10+n*100],'-','Color',c);
i could see the line appear on the picture of other axes.
Edit:
My code for the 2 axes and 1 button: (axes im2 is empty)
%>>>>>im1 axes
--- Executes on mouse press over axes background.
function im1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to im1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
[FileName,PathName]= uigetfile(...
{'*.bmp;*.jpg;*.jpeg;*.tif;*.tiff;*.png','All Image Files(*.bmp,*.jpg,*.jpeg,*.tif,*.tiff,*.png)';...
'*bmp','bitmap Files (*.bmp)';...
'*.jpg;*.jpeg','JPEG Files(*.jpg,*.jpeg)';...
'*.tif;*.tiff','Tiff Files(*.tif,*.tiff)';...
'*png','PNG Files (*.png)';...
'*.*','All Files (*.*)'}, ...
'Pick an image file');
cb1=get(gca,'ButtonDownFcn');
fullpath = sprintf('%s%s',PathName, FileName);
a=imread(fullpath);
imshow(a,'parent',handles.im1);
set(gca,'ButtonDownFcn',cb1);
set(get(gca,'Children'),'ButtonDownFcn',cb1);
%>>>>>Button
function advance_Callback(hObject, eventdata, handles)
% hObject handle to advance (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
imshow(a,'parent',handles.im2);
hold on;
c=rand(1,3);
for n=1:10
plot ( handles.im2, [1 20+n*100],[30 10+n*100], '-', 'color', c )
end
0 commentaires
Réponses (3)
Robert Cumming
le 10 Juil 2011
in the gui you should force the axes that the plot command should be acting on by giving the plot command the axes handle, i.e.
plot ( handles.im2, [1 20+n*100],[30 10+n*100], '-', 'color', c )
Paulo Silva
le 10 Juil 2011
Just for fun I created one blank GUI with GUIDE and inserted this code in the OpeningFcn, all works fine, next I put the code on the callback of a button, now each time I press the button the lines changes color.
imshow('trees.tif');
c=rand(1,3);
arrayfun(@(x)line([1 20+x*100],[30 10+x*100],'Color',c),1:10);
Notice also that if you just want to draw lines you should use the line function instead of plot function and you can do it all without the loop using the arrayfun.
9 commentaires
Image Analyst
le 10 Juil 2011
How about just adapting your own code:
set(get(gca,'Children'),'HitTest','off');
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!