Problem displaying an image on an axis
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Adam
2016-12-1
编辑:Adam
2016-12-1
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 个评论
Adam
2016-12-1
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 )
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Read, Write, and Modify Image 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!