Using GUI, use one push button as an image browser and another to process the image that was chosen?
2 ビュー (過去 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!