Hi I'm creating a GUI for part of an image processing project. To this point I have one push button that reads in an image (and does something with it), and another push button that will then convert that image into a binary image now how to allow

1 次查看(过去 30 天)
Hi I'm creating a GUI for part of an image processing project. To this point I have one push button that reads in an image (and does something with it), and another push button that will then convert that image into a binary image now how to allow the second push button function to access that image : below is the code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'}, 'Pick an Image File');
S = imread([pathname,filename]);
axes(handles.axes1);
imshow(S);
handles.f=[pathname,filename];
guidata(hObject, handles);
figure1.text = 'image uploaded'
% --- Executes on button press in pushbutton2.
function process_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles, 'myImage')
myImage = handles.f;
% convert to binary
binary_image=im2bw(imread('handles.f'));
%Small region is taken to show output clear
binary_image = binary_image(120:400,20:250);
figure;imshow(binary_image);title('Input image');
  1 个评论
Adam
Adam 2017-6-23
Please try to format your question in a readable way.
I corrected it for you this time, but the Code { } block should be used for code rather than for your text!

请先登录,再进行评论。

采纳的回答

Adam
Adam 2017-6-23
This is an important source to read and understand when you are wanting to do anything with GUIs. There are numerous methods. Personally I mostly use the handles struct and guidata.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by