Filter löschen
Filter löschen

Using GUI, use one push button as an image browser and another to process the image that was chosen?

9 Ansichten (letzte 30 Tage)
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);

Akzeptierte Antwort

Matthew
Matthew am 6 Jan. 2017
Bearbeitet: Matthew am 6 Jan. 2017
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

Weitere Antworten (2)

Niels
Niels am 6 Jan. 2017
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
Image Analyst am 6 Jan. 2017
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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by