Using GUI, use one push button as an image browser and another to process the image that was chosen?
1 次查看(过去 30 天)
显示 更早的评论
Hi, this is the very first time I use Matlab & post on a forum so please bare with me. Im working on creating a simple image processing program, I currently have a button that browses a directory for images and loads it. I want the next button to take the loaded image and perform image processing on it. I cannot figure out how to use the same image. This is what I have for the first button.
% --- Executes on button press in Load_Image.
function Load_Image_Callback(hObject, eventdata, handles)
axes(handles.axes1);
path = '[file path]';
filter = '*.jpeg';'*.jpg';'*.png';'*.bmp';
selectedFile = uigetfile(fullfile(path , filter));
imshow(selectedFile);
0 个评论
采纳的回答
Matthew
2017-1-6
编辑:Matthew
2017-1-6
Hi Ramadan,
This question really comes down to where do you want to store the information created by each of your callbacks. For the documentation addressing this look here.
One place to store the selected image information is in your handles structure.
% --- Executes on button press in Load_Image.
function Load_Image_Callback(hObject, eventdata, handles)
axes(handles.axes1);
path = '[file path]';
filter = '*.jpeg';'*.jpg';'*.png';'*.bmp';
selectedFile = uigetfile(fullfile(path , filter));
imshow(selectedFile);
handles.selectedFile = selectedFile;
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in Process_Image.
function Process_Image_Callback(hObject, eventdata, handles)
%Use handles structure to recall the selected file
selectedFile = handles.selectedFile;
%Do Image Processing here
Alternatives are to use the figures 'userdata' or application Data as described here. https://www.mathworks.com/help/matlab/creating_guis/share-data-among-callbacks.html
更多回答(2 个)
Niels
2017-1-6
there are several ways.
if you are using guide, you could just use the handlea structur and save the image within handles:
handles.image=selectedFile;
so if you update handles after each callback, you will be able to use this in every callback as well.
guidata(hObject, handles);
if you dont use guise i propose to save the imagedata within the figure with appdata. Name the figure (=Fig1 in example:)
%setappdata(FigureName,'Name',Variable)
setappdata(Fig1,'ImageSavings',selectedFile)
at the start of your 2nd callback function type
selectedFile=getappdata(Fig1,'ImageSavings');
to get the data you saved back
Image Analyst
2017-1-6
I recommend you start with MAGIC. http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component
It does all the "plumbing" for you - batch processing, listing images in a listbox, click to display then, button to select images folder, writing results to Excel, etc. You just plug your script (image analysis algorithm) into the "AnalyzeSingleImage" function.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!