Problem displaying an image on an axis
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi!
I have a GUI that allows to display an image on an axis by clicking on a start button. The code is below:
% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
start(handles.t);
set(handles.showColor, 'backgroundColor', 'green');
% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
stop(handles.t);
% --- Executes on button press in showColor.
function showColor_Callback(hObject, eventdata, handles)
% hObject handle to showColor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function Disp_image(obj, event, handles)
axes(handles.axes1);
img = imread('image\electronique.png');
image(img);
axis(handles.axes1, 'image', 'off');
The image appears on the axis that I have defined but it also displayed on another figure:
Why the image appears on the 2nd figure? I can't understand.
PS: I put the function "Disp_image" because I will need it to add other commands.
0 comentarios
Respuestas (2)
Adam
el 1 de Dic. de 2016
Editada: Adam
el 1 de Dic. de 2016
Always give an explicit axes handle to plotting instructions. Almost all plotting instructions (certainly in base Matlab) allow you to pass an axes handle as the first argument and most of those that don't allow you to specify {'Property', 'Value'} pairs where you can include
'Parent', hAxes
In this case use
image( handles.axes1, img );
2 comentarios
Adam
el 1 de Dic. de 2016
Are you using an old version of Matlab? I don't know in which version support for the axes handle as first argument was added for image, but for imagesc it was very recent, so you may instead need
image( img, 'Parent', handles.axes1 )
Ver también
Categorías
Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!