MATLAB Answers

0

How to upload an image to a GUI frame?

Asked by Kristin Hoeben on 6 Apr 2017
Latest activity Commented on by Kristin Hoeben on 7 Apr 2017
I'm creating a GUI that needs to upload an image and put it into a frame axis. When I upload it, it's not going to the frame, its just being placed in the center of my figure screen. How can I fix this? Ideally I want to have 2 frames in one figure screen... At the end I want one frame to have the input image and the second frame to have the output image (After its ran through processesing).
function uploadsCB(hObject,eventdata,handles)
set(uploadm,'Visible','off');set(uploads,'Visible','off');
set(imagedisplay,'Visible','on');set(multipleimage,'Visible','off');
set(singleimage,'Visible','off');set(inputr,'Visible','off');
set(inputt,'Visible','off');set(togglef2,'Visible','off');
set(imagedisplayout,'Visible','on');
[filename pathname] = uigetfile({'*.jpg'},'File Selector');
gca = imagedisplay;
image = strcat(pathname, filename);
imshow(image)
end
There's a lot more code to this so if you need anymore information, please let me know.
Thank you for your time.

  2 Comments

Jan
on 6 Apr 2017
What exactly is a "frame"? Don't you get an error message, because e.g. "uploadm" is undefined?
I posted the full code below so there's not confusion, and it shows uploadm being defined. also, frame is how I define the UI control for the axes. This is what a professor told me to do... that may be entirely wrong

Sign in to comment.

Tags

3 Answers

Answer by Joseph Cheng
on 6 Apr 2017
Edited by Joseph Cheng
on 6 Apr 2017

so i take it you have an axes frame that you've tagged as imagedisplay. i'm curious why with said function you don't get warnings or errors as all your uicontrols aren't passed into the function, or that you didn't put handles.______ in all the set() lines. but that's an issue for another time
either way your gca=imagedisplay doesn't set the current axis to imagedisplay. i just copies the imagedisplay to the variable gca.
you'll need to use axes(imagedisplay) or what i think should be axes(handles.imagedisplay).

  0 Comments

Sign in to comment.


Answer by Jan
on 6 Apr 2017

gca is a command. After
gca = imagedisplay;
the term "gca" is redefined as variable which contains a handle now. Most likely you meant:
axes(imagedisplay);
But this is prone to bugs: If the current axes object is set the user has a short period of time to activate another axes by clicking in it, before the obejct is drawn. Better define the 'Parent':
imageFile = fullfile(pathname, filename);
imshow(imageFile, 'Parent', imagedisplay);
I've replaced "image" by "imageFile", because "image" is again an important Matlab command and redfining it as variable causes troubles frequently. fullfile is smarter than strcat, because it cares about the file separators.

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 6 Apr 2017

Your terminology is different (non-standard). The main window is called a "figure" and the images on the figure are in containers called "axes". There is no "frame". There is a "panel" though.
I'd advise you to only put one set() per line to make it more readable. I'd also advise you to use the more modern OOP way instead of using set() function.
Just place your two axes using GUIDE. When you call imshow() it will auto-size the image to fit in the outer limits of the axes you have placed on the figure so it will not necessarily be exactly the same size as the axes you placed in GUIDE. In face, most times it will not be unless your image is exactly the same aspect ratio as the axes you drew in GUIDE.
Finally, don't call your image "image" since image() is the name of a built-in function and defining a variable with the same name as a built-in function is ALWAYS a bad idea.

  0 Comments

Sign in to comment.