I have a program written, and now I need to create a GUI for it. How do I get the GUI to run my program?

This is a continuation of the image processing code that Image_Analyst helped me with earlier this semester. I have the code for the program written, but now my professor wants a GUI created. I have no experience making a GUI, so I'm very lost. I know about the "guide" command, and have a basic design setup. What I need it to do is prompt me for the image file I want to use, ask for a length and width dimension, and then pass those three to the program and run it. Do I need to alter my program to a function and just have the GUI call the function when the Run button is pressed?

 Accepted Answer

You can download this GUI framework: http://www.mathworks.com/matlabcentral/fileexchange/24224. Then paste your script into the function called AnalyzeSingleImage() to do your special processing. It has most of the things you would ever need, but you can adapt the GUI as needed (add buttons, take away radio buttons, etc. - whatever you need).
Description
This GUI will help the novice user get up to speed very quickly on using GUI-based applications. Everything is laid out in a very simple Step 1, Step 2, Step 3, etc. layout. It is a very good starting point for a typical image analysis application. This application uses GUIDE to do the user interface design, and has most of the basic controls such as buttons, listboxes, checkboxes, radio buttons, scrollbars, etc. It allows the user to select a folder of images, select one or more images and display them, to select a series of options, and to individually or batch process one or more images. The user can optionally apply a mask (region of interest) to the image so that only the area within the mask will be analyzed. The results are optionally sent to Excel. In this demo, I do some very basic particle sizing but in use, the user would replace that simple demo code in the function AnalyzeSingleImage() with their own code. Works with Windows or Unix since paths are all forward slashes. Requires the Image Processing Toolbox to do the simple particle sizing demo, but if you delete that demo code before using it, then the IP toolbox would not be required and it would still demonstrate the basic GUI-based file processing functionality.

5 Comments

That program helps, but I can't get my GUI to completely work. I have two "edit text boxes" that I need to retrieve the value from and pass them to another function. My code right now:
function Run_Callback(hObject, eventdata, handles)
% hObject handle to Run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
width = get(handles.Width, 'String');
%width = width{:}; % Convert from cell array to string.
width = str2double(width);
length = get(handles.Length, 'String');
%length = length{:}; % Convert from cell array to string.
length = str2double(length);
ImageRead3(width,length);
Where ImageRead3 is my original program converted to a function. What am I doing wrong?
I don't know what's wrong - can you tell me? Let's start by asking if width and length that you retrieved from the edit fields are correct. If those are okay, then do you actually go into ImageRead3() or not?
It is getting the correct numbers, but here is the error message:
Subscript indices must either be real positive integers or logicals.
Error in ImageRead3 (line 79)
for ii = 1:length(deltaY)
Error in ROFGUI>Run_Callback (line 163)
ImageRead3(width,length);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in ROFGUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)ROFGUI('Run_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Part of the code from ImageRead3 runs, but it errors out at that point.
You redefined the built-in function length() with your variable. Don't do that. Call it imageHeight or something like that instead. Call it something descriptive but not "length" because MATLAB needs that function and you must not overwrite it.
Wow, I can't believe I didn't realize that. That fixed it. I literally spent three days trying to figure that out.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!