0% found this document useful (0 votes)
103 views

Sample 2

The document contains MATLAB code for image processing and analysis. It defines functions for a GUI that allows users to open an image, convert it to grayscale, apply thresholding to create a binary image, count the number of objects in the binary image, and display the results. It loads an image, applies preprocessing steps, and displays the output in two axes on the GUI.

Uploaded by

Yi Fan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Sample 2

The document contains MATLAB code for image processing and analysis. It defines functions for a GUI that allows users to open an image, convert it to grayscale, apply thresholding to create a binary image, count the number of objects in the binary image, and display the results. It loads an image, applies preprocessing steps, and displays the output in two axes on the GUI.

Uploaded by

Yi Fan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

handles.

output=hObject;
[a b]=uigetfile({'*.*'});
img=imread([b a]);
grayy=rgb2gray(img);
gr=graythresh(grayy);
handles.bw=im2bw(grayy,gr);
imshow(handles.bw,'Parent',handles.axes1);
guidata(hObject,handles);

handles.output=hObject;
inverse_binary=not(handles.bw);
[handles.L handles.Num_object]=bwlabel(inverse_binary);
set(handles.text2,'string',handles.Num_object);
imshow(handles.L,'Parent',handles.axes2);

function varargout = Sample(varargin)


% SAMPLE MATLAB code for Sample.fig
% SAMPLE, by itself, creates a new SAMPLE or raises the existing
% singleton*.
%
% H = SAMPLE returns the handle to a new SAMPLE or the handle to
% the existing singleton*.
%
% SAMPLE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SAMPLE.M with the given input arguments.
%
% SAMPLE('Property','Value',...) creates a new SAMPLE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Sample_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Sample_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 Sample

% Last Modified by GUIDE v2.5 30-Jul-2017 03:20:36

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Sample_OpeningFcn, ...
'gui_OutputFcn', @Sample_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 Sample is made visible.


function Sample_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Sample (see VARARGIN)

% Choose default command line output for Sample


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Sample wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Sample_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;

% --- 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)
handles.output=hObject;
b=uigetfile({'*.*'});
img=imread(b);
grayy=rgb2gray(img);
handles.bw=grayy;
imshow(handles.bw,'Parent',handles.axes1);
guidata(hObject,handles);

% --- Executes on button press in pushbutton2.


function pushbutton2_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)

handles.output=hObject;
gg=handles.bw;
BW= imbinarize(gg);
BW2 = bwareaopen(BW, 500);
BW3=bwareaopen(BW, 270);
BW4=bwareaopen(BW, 50);
%%set(handles.text2,'string',handles.Num_object);
imshow(BW3,'Parent',handles.axes1);

You might also like