Diplay a dialog box when using a wrong callback using images in gui

1 次查看(过去 30 天)
I'm still learning how tu use GUI in matlab. i Have a gui that reads an image and display it. Then i have 3 buttons which converts the image into a grayscale image (R, G or B) then, using a slider, i set the threshold for a binary image. Well, when i use the slider without pressing any buttons (r, g or b) i get an error " Reference to non-existent fiel". And that's fine, i know i have to get an error there, but what i want to do is to display an error using waitfor(msgbox('')); when that error occurs. i'm still traying to do that, but i need a little help please.
Well, i want to use this gui when running a certain part from a code in a .mat file. For example. I run the code, read an image, then call the gui, binarize the same image, save the binarized image, and then use that saved image in the original code and continue the code. Hope it makes sense. How can i do this?
Here is the gui
function prueba_gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.imagen = imread('G:\Memoria\test\Imagen125.jpg');
axes(handles.axes1);
imshow(handles.imagen);
guidata(hObject, handles);
function varargout = prueba_gui_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function binar_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
tempImg = handles.im;
thresholdValue = get(handles.binar, 'value');
binaryImage = tempImg> thresholdValue;
se = strel('square',4);
w = imdilate(binaryImage,se);
imshow(w);
guidata(hObject,handles);
function binar_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function RED_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
handles.im = handles.imagen(:,:,1);
imshow(handles.im);
guidata(hObject,handles);
function GREEN_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
handles.im = handles.imagen(:,:,2);
imshow(handles.im);
guidata(hObject,handles);
function BLUE_Callback(hObject, eventdata, handles)
handles.output = hObject;
axes(handles.axes1);
handles.im = handles.imagen(:,:,3);
imshow(handles.im);
guidata(hObject,handles);
% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
handles.output = hObject;
%nothing here yet

采纳的回答

Image Analyst
Image Analyst 2014-5-25
See the FAQ for how to share variables between different functions in your m-file. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
  9 个评论
Image Analyst
Image Analyst 2014-5-26
You can save it in a mat file. That's one way listed in the FAQ. Though it's slower because you have to write to disk and read from disk. It's mostly used for passing data between two separate GUIs rather than within functions of the same GUI.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by