How to upload an image to a GUI frame?

조회 수: 9 (최근 30일)
Kristin Hoeben
Kristin Hoeben 2017년 4월 6일
댓글: Kristin Hoeben 2017년 4월 7일
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
Jan
Jan 2017년 4월 6일
What exactly is a "frame"? Don't you get an error message, because e.g. "uploadm" is undefined?
Kristin Hoeben
Kristin Hoeben 2017년 4월 7일
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

댓글을 달려면 로그인하십시오.

답변 (3개)

Joseph Cheng
Joseph Cheng 2017년 4월 6일
편집: Joseph Cheng 2017년 4월 6일
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).

Jan
Jan 2017년 4월 6일
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.

Image Analyst
Image Analyst 2017년 4월 6일
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.

카테고리

Help CenterFile Exchange에서 Display Image에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by