フィルターのクリア

recall a figure in guide

3 ビュー (過去 30 日間)
maria
maria 2016 年 9 月 9 日
回答済み: Geoff Hayes 2016 年 9 月 12 日
Hello! I am building an interface with GUI. By using a pushing bottom I open a figure, and by pushing a second one, I add a filter to the figure in another axes. However, Matlab gives me an error in the second function: the figure does not exits. How can I call the figure in the second function by pushing botoom 2? This is my code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename pathname]=uigetfile({'*.jpg'}, 'File Selector');
fullpathname=strcat(pathname, filename);
image=imread(fullpathname);
figure.handle=imread(image);
set(handles.text2, 'String', pathname);
handles.axes1=imshow(image);
set(handles.axes1, imshow(image));
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
filter=1-image;
axes(handles.axes2);
imshow(filter);
set(handles.axes2, imshow(filter)

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 9 月 12 日
maria - if you want to reference the image that was loaded through the first push button, then save it to the handles object. For example,
function pushbutton1_Callback(hObject, eventdata, handles)
[filename pathname]=uigetfile({'*.jpg'}, 'File Selector');
fullpathname=strcat(pathname, filename);
handles.myImage=imread(fullpathname);
guidata(hObject,handles);
% etc.
Note how the image is saved as
handles.myImage=imread(fullpathname);
and then save the updated handles object with
guidata(hObject,handles);
As an aside, do not create local variables named after built-in MATLAB functions like image. Also, it isn't clear to me what the intent is with
figure.handle=imread(image);
set(handles.text2, 'String', pathname);
handles.axes1=imshow(image);
set(handles.axes1, imshow(image));
What is figure.handle? Why are you overwriting handles.axes1 (which presumably is the axes in your GUI) with the handle returned by imshow?
Anyway, in the second push button callback you reference this image as
function pushbutton2_Callback(hObject, eventdata, handles)
if isfield(handles,'myImage')
filter=1-handles.myImage;
axes(handles.axes2);
imshow(filter);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by