I am making a project named content based image retrieval using color. I have implemented my algorithm. Now I have to make a GUI.
How can I call my algorithm function in the callback function of a push button?
By pushing the button my query and database images should display on GUI.
function pushbutton1_Callback(hObject, eventdata, handles)
[FileName, folderName] = uigetfile('.','specify an image file');
fullimageFilename=fullfile(folderName,FileName); im=imread(fullimageFilename); query(im);
image(im,'parent',handles.axes2);
Related
I have written a GUI program in Matlab using Matlab GUIDE.
Created a tool on the toolbar and wrote a right click call back function as shown below, but when I do a right click on that tool on the GUI, there is no response.
function MyTool_ButtonDownFcn(hObject, eventdata, handles)
waitfor(msgbox('Hello button down function','Hello button down'));
disp('Hello disp');
From property inspector, value of ButtonDownFcn is:
#(hObject,eventdata)main('MyTool_ButtonDownFcn',hObject,eventdata,guidata(hObject))
I tried to debug using another button with Callback function to execute 'keyboard'.
function bugfindbutton_ClickedCallback(hObject, eventdata, handles)
keyboard
This confirmed the existance of function MyTool_ButtonDownFcn(hObject, eventdata, handles) associated with ButtonDownFcn of the tool and is not deleted by any other functions. But a right click on the tool gives neither msgbox nor command window output.
I want right click of mouse on 'MyTool' toggle button (a custom tool on the toolbar) to execute MyTool_ButtonDownFcn function. How can I do it?
The ButtonDownFcn is ignored for uitoggletool and uipushtool objects. You should instead use the ClickedCallback property to set a callback. That callback, however, will only execute on a left mouse click and will not be triggered on a right mouse click.
If you really need to bind a callback to a right mouse click, you can use the findjobj utility from the file exchange to access the underlying Java object and assign a custom callback
h = uitoggletool( ...
'CData', rand(16, 16, 3), ...
'OnCallback', #(s,e)disp('on'), ...
'OffCallback', #(s,e)disp('off'));
% Get the underlying java object using findobj
jtoggle = findjobj(h);
% Specify a callback to be triggered on any mouse release event
set(jtoggle, 'MouseReleasedCallback', #(s,e)callback(h,e))
function callback(src, evnt)
if evnt.getButton() == 3
disp('Right Click!')
end
% Get the handles struct
handles = guidata(src);
% Modify the handles
handles.value = 2;
% Save the handles
guidata(src, handles);
end
I am working on a project related to image processing. I want to create a level-2 S-block in simulink for reading Dicom Images (.dcm). There should be a browse button and edit text section in the Dialog box. Whenever i click on the browse button image can be selected and the path of that image should be displayed on the edit parameter. Any idea what should be the mask callback functions for these parameters. Here is a sample callback for mask parameters. See Sample Image
function DicomReader_callback(action,block)
feval(action,block)
function pushbutton_callback(block)
[fn pn] = uigetfile('*.dcm','select dicom file');
complete = strcat(pn,fn);
get_param(gcb, 'UserData');
set_param(gcb, 'UserData', complete);
function edit_callback(block)
Thanks !
Here is my code for the callback function.
function Next_Callback(hObject, eventdata, handles)
display('Click Next');
handles.imgLNum = strcat('I1_',num2str(handles.imageNumber),'.png');
handles.imgRNum = strcat('I2_',num2str(handles.imageNumber),'.png');
handles.imageLeft = strcat(handles.directory,handles.imgLNum);
handles.imageRight = strcat(handles.directory,handles.imgRNum);
axes(handles.img1);
imshow(handles.imageLeft);
axes(handles.img2);
imshow(handles.imageRight);
handles.imageNumber = handles.imageNumber+1;
I have a button called "Next" on my GUI and I want to load the next image into the axes when it is clicked. handles.imageLeft and handles.imageRight have the path for the images. When the hit the button the first time, the axes gets updated with the images. But subsequent clicks on the button do not update the axes. But the 'Click Next' text is displayed in console, so I know the callback function is being called.
Thank you #Adiel for the help. I find the problem following your suggestions. I updated the handles.imageLeft and handles.imageRight and I added the code guidata(hObject, handles); I think this function updates the handles (This is my first MATLAB GUI, so I am not very sure). Now the problem is fixed.
I am asked by my professor to add a GUI for my Matlab code. My program receives an image as an input and returns a string.
The GUI should enable me to browse the image and then display it. Then I need to use that image in the Matlab code.
To browse and display the image, I created a pushbutton control and wrote the following in its callback
[baseFileName, folder] = uigetfile('*.jpg');
fullFileName = [folder baseFileName];
rgbImage = imread(fullFileName,'jpg');
imshow(rgbImage);
I added a second pushbutton and the Matlab code (which has a file name main.m) inside its callback. This function needs the image displayed above as an input, and its output (which is a string) needs to be displayed in the GUI.
I am facing a few problems:
I want the image to be displayed in a specific position.
How can I call the function in the push button?
How can I access and use the image in the first push button to the second push button?
Some hints on how you can get started with your problems:
You could create an axes object in your figure, whose position can be defined. then just plot the image on that axes. Do all that in the callback
Calling a function from a callback should not be a problem
Save the image in structure, then you can use for example setappdata and getappdata to pass it between callbacks, i.e. when your figure handle is h.fig and your structure called d:
setappdata(h.fig,'d',d)
in the first callback, and to retrieve it, in the second:
d = getappdata(h.fig,'d');
I am making a GUI in which there is a multi-line edit box.
the user will have to input the 3 x-y coordinates in this edit box at a time:
[345.567 123.123]
[390.567 178.098]
[378.000 125.987]
by clicking the push button I want these coordinates to be "saved" in the Matlab GUI workspace in the form of a matrix and by clicking another push button "reloaded" from the workspace so that they can be available for future use.
How can I do that?
Can anyone guide me with this? Help would be appreciated!
There are a number of ways to manage data in GUIDE-generated GUIs. The easiest IMO is to use guidata.
For example inside the "Save" push button callback, you would access the edit box string contents, parse as matrix of numbers as save it inside the handles structure.
function pushbuttonSave_Callback(hObject, eventdata, handles)
handles.M = str2num(get(handles.edit1, 'String'));
guidata(hObject, handles);
end
Next in the "load" button, we do the opposite, by loading the matrix from the handles structure, converting it to string, and set the edit box content:
function pushbuttonLoad_Callback(hObject, eventdata, handles)
s = num2str(handles.M, '%.3f %.3f\n');
set(handles.edit1, 'String',s)
end
If you want to export/import the data to/from the "workspace", you can use the ASSIGNIN/EVALIN function:
assignin('base','M',handles.M);
and
handles.M = evalin('base','M');
to save data:
setappdata(h,'name',value)
to load data:
value = getappdata(h,'name')
values = getappdata(h)
where h is the handle you store the data in, name is the variable of the data, value is the actual data.