?
Solved

Please advise on my code to do the following in Matlab Guide

Posted on 2009-04-20
5
Medium Priority
?
433 Views
Last Modified: 2016-02-10
The following advise works perfect on their own
http://www.experts-exchange.com/Programming/Languages/MatLab/Q_24335598.html
http://www.experts-exchange.com/Programming/Languages/MatLab/Q_24335622.html
But what if I want to open the picture then put that photo in the axis or generally use that picture throughout the program.
My attempt at this was as per the codebox below;
but this does not work.
Can someone please explain what I am doing wrong?
thanks in advance.
[FileName,PathName] = uigetfile('*.jpg','Select an image');
//
//
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
imshow(handles.axes1,FileName)

Open in new window

0
Comment
Question by:jtiernan2008
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:yuk99
ID: 24189859
You already had the same problem when coding hyperbola rotation. You put script (uigetfile part) and function together in one file. Or is uigetfile actually part of another function? If it is, show the function declaration here.
0
 
LVL 1

Author Comment

by:jtiernan2008
ID: 24189894
uigetfile is part of another function

This is what I have done so far.
The menu callback is called under the following function
function Untitled_2_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.jpg','Select an image');

and I am trying to display this image under
function pushbutton10_Callback(hObject, eventdata, handles)
imshow(FileName,'Parent',handles.axes1)
function varargout = project(varargin)
% PROJECT M-file for project.fig
%      PROJECT, by itself, creates a new PROJECT or raises the existing
%      singleton*.
%
%      H = PROJECT returns the handle to a new PROJECT or the handle to
%      the existing singleton*.
%
%      PROJECT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PROJECT.M with the given input arguments.
%
%      PROJECT('Property','Value',...) creates a new PROJECT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before project_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to project_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 project
 
% Last Modified by GUIDE v2.5 21-Apr-2009 01:28:19
 
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @project_OpeningFcn, ...
                   'gui_OutputFcn',  @project_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 project is made visible.
function project_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 project (see VARARGIN)
 
% Choose default command line output for project
handles.output = hObject;
 
% Update handles structure
guidata(hObject, handles);
 
% UIWAIT makes project wait for user response (see UIRESUME)
% uiwait(handles.figure1);
 
 
% --- Outputs from this function are returned to the command line.
function varargout = project_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
I=imread('lena512.bmp');
imshow(I,'Parent',handles.axes1)
% 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)
 
 
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
function pushbutton1_ButtonDownFcn(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)
 
 
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (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 pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
I1=imread('lena512.bmp');
I2=imread('lena5122.bmp');
I3=imsubtract(I1,I2);
imshow(I3,'Parent',handles.axes4);
 
 
 
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.jpg','Select an image');
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
 
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1
 
 
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: listbox 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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
val = get(hObject,'Value');
switch val
case 1
case 2
I=imread('lightbulb.jpg');
imshow(I,'Parent',handles.axes2)
case 3
I=imread('lightbulb.jpg');
I2=rgb2gray(I);
imshow(I2,'Parent',handles.axes2)
case 4
I=imread('lightbulb.jpg');
I3=rgb2gray(I);
background=imopen(I3,strel('disk',15));
I4=imsubtract(I3,background);
I5=imadjust(I4);
level=graythresh(I4);
bw=im2bw(I3,level);
imshow(bw,'Parent',handles.axes2)
end
% User selected the second item
% Proceed with callback...
 
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
 
 
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: popupmenu 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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
I=imread('lena512.bmp');
PSF = fspecial('gaussian',11,5);
Blurred = imfilter(I,PSF,'conv');
imshow(Blurred,'Parent',handles.axes4)
% hObject    handle to pushbutton5 (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 pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (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 pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
I=imread('lena512.bmp');
imshow(I,'Parent',handles.axes1)
% hObject    handle to pushbutton7 (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 pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
I=imread('lena5122.bmp');
imshow(I,'Parent',handles.axes3)
% hObject    handle to pushbutton8 (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 pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
imshow(FileName,'Parent',handles.axes1)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Open in new window

0
 
LVL 15

Accepted Solution

by:
yuk99 earned 2000 total points
ID: 24190233
You need to use a mechanism to exchange data between your callback functions.
For example, you can use handles to hold the data.

function Untitled_2_Callback(hObject, eventdata, handles)
[handles.FileName,handles.PathName] = uigetfile('*.jpg','Select an image');
guidata(hObject,handles) % saves the handles structure into hObject
 
...
function pushbutton10_Callback(hObject, eventdata, handles)
imshow(fullfile(handles.PathName,handles.FileName),'Parent',handles.axes1)

Open in new window

0
 
LVL 15

Assisted Solution

by:yuk99
yuk99 earned 2000 total points
ID: 24190240
You can have a look on a demo how to build GUI with GUIDE:
http://www.mathworks.com/products/demos/shipping/matlab/CreatingaGUIwithGUIDE_viewlet_swf.html
It might help you to understand it better.
0
 
LVL 1

Author Closing Comment

by:jtiernan2008
ID: 31572507
thanks a million
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question