Problem displaying an image on an axis

조회 수: 3 (최근 30일)
Samah EL QASSAH
Samah EL QASSAH 2016년 12월 1일
댓글: Adam 2016년 12월 1일
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.

답변 (2개)

Adam
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
Samah EL QASSAH
Samah EL QASSAH 2016년 12월 1일
I add the 'handles.axes1' as shown here:
function Disp_image(obj, event, handles)
axes(handles.axes1);
img = imread('image\electronique.png');
image(handles.axes1, img);
axis(handles.axes1, 'image', 'off');
But the image is not displayed
%
Adam
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 )

댓글을 달려면 로그인하십시오.


Samah EL QASSAH
Samah EL QASSAH 2016년 12월 1일
If I change the axis by a button, the result is as follows:
function Disp_image(obj, event, handles)
img = imread('image\electronique.png');
set(handles.affich_image, 'CData', img);
Does the function fail to know the axis?

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by