Problem displaying an image on an axis

1 Ansicht (letzte 30 Tage)
Samah EL QASSAH
Samah EL QASSAH am 1 Dez. 2016
Kommentiert: Adam am 1 Dez. 2016
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.

Antworten (2)

Adam
Adam am 1 Dez. 2016
Bearbeitet: Adam am 1 Dez. 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 Kommentare
Samah EL QASSAH
Samah EL QASSAH am 1 Dez. 2016
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 am 1 Dez. 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 )

Melden Sie sich an, um zu kommentieren.


Samah EL QASSAH
Samah EL QASSAH am 1 Dez. 2016
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?

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by