I'm looking to create another push button which will convert browse image to binary of the image I read in, I'm not sure how to define the image under the new function as the image that was chosen previously, could any one help,
1 次查看(过去 30 天)
显示 更早的评论
function process_Callback(hObject, eventdata, handles)
% hObject handle to process (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%convert binary Image
binary_image = binary_image(120:400,20:250);
figure;imshow(binary_image);title('binary image');
%Small region is taken to show output clear
binary_image = binary_image(120:400,20:250);
figure;imshow(binary_image);title('binary_image');
0 个评论
采纳的回答
Geoff Hayes
2017-6-22
indrani - it sounds like you 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. If the problem is how to allow the second push button function to access that image, then what you can do is to save the image to the handles structure so that all callbacks have access to this image. For example,
function readimage_Callback(hObject, eventdata, handles)
[filename,pathname,filterindex] = uigetfile();
handles.myImage = imread(fullfile(pathname, filename));
guidata(hObject, handles);
% do other stuff if needed
Then, in your other callback, you would access this image as
function process_Callback(hObject, eventdata, handles)
if isfield(handles, 'myImage')
myImage = handles.myImage;
% convert to binary, etc.
end
In the first callback, we load the image (I'm not sure how you are doing this so the code presented here will be different). We call guidata to update the handles structure with the myImage field. In the second callback, we check for existence of the image field and then use it as needed.
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!