display output images from m-files in axes of gui

1 view (last 30 days)
i have a gui for my m-files , now i have to display my multiple output images in axes of that gui now the thing is even after giving proper handles in m-files ,icant seem to display image in axes after display i want to move from one image to next since i cant my output in my axes im stuck for now
my gui code
function varargout = new5(varargin)
% NEW5 M-file for new5.fig
% NEW5, by itself, creates a new NEW5 or raises the existing
% singleton*.
%
% H = NEW5 returns the handle to a new NEW5 or the handle to
% the existing singleton*.
%
% NEW5('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NEW5.M with the given input arguments.
%
% NEW5('Property','Value',...) creates a new NEW5 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before new5_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to new5_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help new5
% Last Modified by GUIDE v2.5 17-Apr-2014 21:49:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @new5_OpeningFcn, ...
'gui_OutputFcn', @new5_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before new5 is made visible.
function new5_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to new5 (see VARARGIN)
% Choose default command line output for new5
handles.output = hObject;
axes(im,'parent',handles.axes1)
imshow(im)
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes new5 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = new5_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in backbut.
function backbut_Callback(hObject, eventdata, handles)
% hObject handle to backbut (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in nextbut.
function nextbut_Callback(hObject, eventdata, handles)
% hObject handle to nextbut (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in radiobutton8.
function radiobutton8_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton8
% --- Executes on button press in calpushbutton4.
%function calpushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to calpushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function varargout = calpushbutton4_Callback(h, eventdata, handles,varargin)
hbuttons = [handles.radiobutton8 ];
data = find(get(hbuttons,'Value') == 1);
switch data
case 1
surfacearea
end
% --- Executes on button press in soil.
%function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to soil (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function varargout = soil_Callback(h, eventdata, handles,varargin)
if get(handles.red, 'Value')
% Run function #1
matredhsv;
elseif get(handles.yellow, 'Value')
% Run function #2
matyellowhsv;
else
% Run function #3
matblackhsv;
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,FilePath ]= uigetfile('*jpg');
ExPath = fullfile(FilePath, FileName);
set(handles.edit1,'string',ExPath)
% --- Executes on button press in black.
% --- Executes on button press in red.
function red_Callback(hObject, eventdata, handles)
% hObject handle to red (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of red
% --------------------------------------------------------------------

Answers (1)

Image Analyst
Image Analyst on 17 Apr 2014
It doesn't look like a very user friendly GUI to me. You should not ask the user to browse for an image URL, then have different buttons for next and back. What a painful way to select images. I mean, you don't even know what the filenames are or where they're located when you click next or back. A much, much better way is to have a button that specifies the folder where all your images live. Then load up a listbox with the images. Then the user can click on any image in any order to display it. See this GUI framework: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component for a better way.
And you also didn't name your buttons in a good style. I have no idea from your code whether the next button is pushbutton1 or pushbutton2 or calpushbutton4. You should name them something like btnNext and btnBack, and radRed and radYellow so people know what they control.
But the main problems is you're not calling imshow in any callback to display the image. You call it only in the new5_OpenFcn function, which will probably error out because it has this:
axes(im,'parent',handles.axes1)
imshow(im)
firs of all, im was not defined anywhere in the function so it's not going to know what it is. Secondly you don't use axes like that. The parent option goes into imshow(), not axes(). This is the way it should be done, both there and in any pushbutton callback:
im = ..... however you get it.
axes(handles.axes1);
imshow(im);
  5 Comments
Image Analyst
Image Analyst on 19 Apr 2014
If they're stored to disk, just re-read in the directory and load it into the listbox again. Sometimes I have images that are just "temporary" or "intermediate" and I do not want to save permanently to disk, and for that situation, I use a popup (drop down list) to let the use select which temporary image to display.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by