How to set pushbutton to select image files , and have axes display the image chosen?
2 次查看(过去 30 天)
显示 更早的评论
I am creating a GUI for a project. For the GUI, I want the Load File button to be able to open up the dekstop, so that an image can be selected, and then have that image displayed on the axes. the sliders will then be used to manipulate the image. Attached is the current code as well as the Figure File for this GUI. (So far, I am able to click on the load file and select an image - the problem is, the image is not being displayed on the axes).
0 个评论
采纳的回答
Walter Roberson
2017-8-14
1) You probably should not have any occurrences of
handles.output = hObject;
and certainly not one for every createFcn or callback.
2) You have
complete = strcat(pn,fn);
You should learn to use fullfile()
3) You have
set(handles.axes1,'string',complete);
handles.axes1 appears to be an axes. axes have no 'string' property. This line would have caused your callback to fail, causing it to not display the image.
4) you have
imshow(I,[]);
That is not necessarily going to display to the axes you want. You should use
imshow(I, [], 'Parent', handles.axes1);
5) In function get_ready you have
global k
You do not assign to k or use k anywhere in any of your code. This line is useless.
6) In function viewtype_SelectionChangeFcn you have
global view_type
global kp
The function does assign to each of those variables (at least under some conditions). However, you never use the value of those variables anywhere, and do not "global" them in any other function. These assignments appear to not have any purpose with your current code.
7) In function startstop_Callback you have
global ss
ss=~ss;
and you do read the current value and use it to make decisions. However, you do not "global" the variable in any other routine, and you do not initialize the variable. When you do not initialize a global variable, it is automatically assigned the value [] (the empty numeric array). You do ss = ~ss, but ~[] is also [], so the value of ss will continue to be []. Your code has
if ss
but "if []" is false. Your code continues to
elseif ~ss
but "elseif ~[]" is false. Therefore you will not execute the code to start and you will not execute the code to stop.
You do not use ss in any other routine. If you are attempting to keep track of state entirely within one routine, then instead of using "global" you should use "persistent".
8) Avoid using "global": it is the slowest way to access variables.
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
9) You have
function handles = get_ready(handles, filename)
However, you have no calls to this function, and it is not called on your behalf by any callback you have configured. You would have to call it specially as it has the wrong parameters to be called directly as a callback.
更多回答(1 个)
Image Analyst
2017-8-14
It's already done in a nice framework here: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component
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..........
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!