A list,

Fruit recognition based on MATLAB GUI gray scale, binarization, corrosion, histogram processing

Ii. Source code

The function varargout = the4th (varargin) % = = = = = = = = filename: the4th. M = = = = = = = = = = = = % % = = = = = = = = = = = fruit image pattern recognition12120389= = Cao Jia % % = = = = = = = = = = = = = = = the include files: the4th. M = = = = = = = = = = = = = = = = = = = % % = = = = = = = = = = = = = = = = = = = = = = = = exam. M = = = = = = = = = = = = = = = = = = = % %========================exam1.m==================% %========================do.m=====================%
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @the4th_OpeningFcn, ...
                   'gui_OutputFcn',  @the4th_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 the4th is made visible.
function the4th_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 the4th (see VARARGIN)

% Choose default command line output for the4th
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes the4th wait for user response (see UIRESUME)
% uiwait(handles.figure1);
clc
clear


% --- Outputs from this function are returned to the command line.
function varargout = the4th_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; % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --function menu_1_Callback(hObject, eventdata, handles)
% hObject    handle to menu_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global fea testimg mask; % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --function menu_2_Callback(hObject, eventdata, handles)
% hObject    handle to menu_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function menu_3_Callback(hObject, eventdata, handles)
% hObject    handle to menu_3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function menu_4_Callback(hObject, eventdata, handles)
% hObject    handle to menu_4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function menu_5_Callback(hObject, eventdata, handles)
% hObject    handle to menu_5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function menu_6_Callback(hObject, eventdata, handles)
% hObject    handle to menu_6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.


% --------------------------------------------------------------------
function menu_61_Callback(hObject, eventdata, handles)
% hObject    handle to menu_61 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)Clear % reads the sample image img1= imread('pears. JPG');
bwpic = RGB2bw(img1);
samfea(1,:) = get_features(img1, bwpic);
img2 = imread('green peppers. JPG');
bwpic = RGB2bw(img2);
samfea(2,:) = get_features(img2, bwpic);
img3 = imread('Tomato.jpg');
bwpic = RGB2bw(img3);
samfea(3,:) = get_features(img3, bwpic);
img4 = imread('bananas. JPG');
bwpic = RGB2bw(img4);
samfea(4,:) = get_features(img4, bwpic); % tESTIMg = imread('test.jpg'); % test image binarization BWPIC = RGB2bw(tESTIMG); L = bwlabel(bWpic,4);
mask = zeros(size(bwpic,1),size(bwpic,2), 4);

for i=1:4
	Tmask = zeros(size(bwpic,1),size(bwpic,2));
    [r, c] = find(L==i);
    for j=1:length(r)
        Tmask(r(j), c(j)) = 1; end %figure, image(Tmask) mask(:,:,i) = Tmask; End % feature extractionfor i=1:4
    testfea(i,:) = get_features(testimg, mask(:,:,i));
end
name = {'pear'.'green pepper'.'Tomato'.'banana'}; % index = recognition(testfea, samfea); % Displays the result %figure
imshow(testimg)

hold on
for i=1:4
    R = regionprops(mask(:,:,i),'boundingbox' );
    Rect = R.BoundingBox;
    if i==3 
    text(Rect(1)+Rect(3),Rect(2), name(index(i)- 1))
    else
    text(Rect(1)+Rect(3),Rect(2), name(index(i)))
    end
end
Copy the code

3. Operation results

Fourth, note

Version: 2014 a