필터 지우기
필터 지우기

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,

조회 수: 2 (최근 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');

채택된 답변

Geoff Hayes
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
indrani dalui
indrani dalui 2017년 6월 23일
thank you for giving me suggestion sir but this code is not running .i don't know why.again i am sending the full code to you .please do need full.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

indrani dalui
indrani dalui 2017년 6월 23일
function varargout = ui(varargin)
% UI MATLAB code for ui.fig
% UI, by itself, creates a new UI or raises the existing
% singleton*.
%
% H = UI returns the handle to a new UI or the handle to
% the existing singleton*.
%
% UI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UI.M with the given input arguments.
%
% UI('Property','Value',...) creates a new UI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ui
% Last Modified by GUIDE v2.5 20-Jun-2017 16:16:26
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @ui_OpeningFcn, ... 'gui_OutputFcn', @ui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ui is made visible. function ui_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles);
% UIWAIT makes ui wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = ui_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
figure1.text = 'upload image'
% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) [filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'}, 'Pick an Image File'); S = imread([pathname,filename]); axes(handles.axes1); imshow(S); handles.myimage=[pathname,filename]; guidata(hObject, handles); figure1.text = 'image uploaded'
% --- Executes during object creation, after setting all properties. function axes1_CreateFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in pushbutton3. function readimage_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
[filename,pathname,filterindex] = uigetfile(); handles.myImage = imread(fullfile(pathname, filename)); guidata(hObject, handles); a = uigetfile(); filename = a; setappdata(0,'filename',filename);
if filename == -1 error('Failed to open file.') msgbox('Failed to open file.'); end
a = imread(a); % if isequal(filename,0) isequal(pathname,0) % disp('User pressed cancel') % else % disp(['User selected ', fullfile(pathname, filename)])
% end
axes(handles.axesimg); imshow(a); setappdata(0,'a',a); setappdata(0,'filename',a); assignin('base','a',a); plot(handles.axesimg,'a') %handles.f = [filename]; %guidata(object_handle,handles); disp('Reading the image into variable X'); [X,map] = imread(filename); assignin('base','X',X); assignin('base','map',map);
assignin('base','width',200); assignin('base','height',200);
edittimes.Visible = 'off';
function process_Callback(hObject, eventdata, handles) if isfield(handles, 'myImage') myImage = handles.myImage; % 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 input image to binary binary_image=im2bw(imread('s'));
%Small region is taken to show output clear binary_image = binary_image(120:400,20:250); figure;imshow(binary_image);title('Input image') end

카테고리

Help CenterFile Exchange에서 Code Generation, GPU, and Third-Party Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by