Placing and Editing an Image within a GUI using GUIDE.

How do you place an image within a pre-defined border on a GUI?
I set an axes down hoping to put the image inside, but that didn't work.
I'm hoping to put three images side-by-side, the first being the original grayscale image, the second being the image as we apply certain processing techniques to it, and the third showing the iteration within each step so that we can optimize the result of each step (i.e. varying the size of structuring elements, filters, etc.)

 Accepted Answer

You can use GUIDE to place three axes on the figure, then (option 1) use axes() to switch between them and use imshow() to display in the current axes, or else (option 2) use the 'Parent' option of imshow() to specify the axes in which to display your image. You can look at my thresholding example in my File Exchange which has 3 images: the original, the binary (thresholded) version, and the masked version. Or look at any of my demos - they all use multiple images. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

11 Comments

I prefer defining the Parent property explicitly in the image() command.
Also, how do you call your GUI from a separate m-file after doing all of the pre-processing that you would like to do? And then how do you switch control back to that m-file when you're done with the GUI?
Just call gui2 from the main gui by it's name and pass it all the arguments it needs. I don't know how to switch focus to another app (the main gui) after gui2 exits/closes, but it will switch when the user clicks somewhere on the main gui.
I'm not doing two different GUIs. I'm doing cropping and converting to grayscale in the pre-processing in a separate script and I want to pass that pre-processed image into the GUI as the image that I am manipulating. Then I allow the user to do all sorts of processing within the GUI; then after they are happy with what they have, they exit and the output image from that GUI is passed back to the original script where the post-processing is done.
Then just replace "gui2" by GUI, and "main gui" in my answer by "main script" - everything else remains the same. Basically your script does stuff, calls the gui (passing it input arguments and accepting aoutput arguments), and then continues on with the script. You might need a uiwait and uiresume in there.
I'm just not very familiar with object-oriented programming, so I'm having to learn that before I can even go into making GUIs. Thank you for your help.
It's not object oriented programming. It's just regular plain old programming. Look, in your script, let's say you've saved it as myscript.m, you have this
% some code
clc;
workspace;
format compact;
% whatever.
% Now you call your gui, let's say it's called caleb_gui
[output1 output2] = caleb_gui(input1, input2, input3); % or whatever.
% Now we're back in the main script again
% when we return from caleb_gui()
% Do more stuff that involves output1 and output2.
Now, in your caleb_gui is the code where you "allow the user to do all sorts of processing within the GUI" If you used GUIDE, you'll have am m-file and a .fig file.
That's about it, and no OOP involved. If you still need help understanding that, see the Getting Started section of the help, particularly where it describes calling functions.
I know I can do all of what I need to do by creating a figure, an axes and using the image() command to place an image inside a particular axes. I'm just having a hard time understanding how to use GUIDE to do callbacks and working with UI controls, etc. I know that you are a more-than-competent image processor. Does it sound reasonably easy to make an interface where someone can interactively see what they're doing as they apply image processing techniques to an image?
I suggest you use this nice framework as a starting point for your image analysis applications. http://www.mathworks.com/matlabcentral/fileexchange/24224 It has practically every control on it and you can modify any of them or remove any you don't want.
Looks like a great template. Is there any way to change the 'ImageList' ListBox on the left side of the screen to show folders on the MATLAB path? I'd rather the user have to click through a few folders then have to guess where they are going to place their image files.
You'd have to get the path
matlabPath = path;
then go through each folder on the path adding the files from that folder to the listbox. I don't see any other way since the path can include totally separate and unrelated folders - they're not all subfolders of one master folder.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!