【水果识别】基于灰度直方图水果识别matlab源码含 GUI

一、简介

基于matlab GUI 灰度、二值化、腐蚀、直方图处理之水果识别

二、源代码

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

% Last Modified by GUIDE v2.5 15-Jan-2017 01:03:42

% Begin initialization code - DO NOT EDIT guiSingleton = 1; guiState = struct('guiName', mfilename, ... 'guiSingleton', guiSingleton, ... 'guiOpeningFcn', @untitledOpeningFcn, ... 'guiOutputFcn', @untitledOutputFcn, ... 'guiLayoutFcn', [] , ... 'guiCallback', []); if nargin && ischar(varargin{1}) guiState.gui_Callback = str2func(varargin{1}); end

if nargout [varargout{1:nargout}] = guimainfcn(guiState, varargin{:}); else guimainfcn(guiState, varargin{:}); end % End initialization code - DO NOT EDIT

% --- Executes just before untitled is made visible. function untitled_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 untitled (see VARARGIN)

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

% Update handles structure guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line. function varargout = untitled_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 pushbutton3. function pushbutton3_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) global I FilledLabel HSV MeanHue Ecllipseratio Label num Premeter Area for i = 1 : num Premeter(i) = 0; end

[row,col] = size(Label);
for i = 1 : row
    for j = 1 : col
        if(Label(i,j) > 0)
            Premeter(Label(i,j)) = Premeter(Label(i,j)) + 1;    %计算标记后的各块图形边界中像素的个数的总数
        end
    end
end

%计算各个图形单元的面积 FilledLabel=imfill(Label,'holes'); %填充打过标记的边界线中间围成的图形区域 for i = 1 : num Area(i) = 0; end

[row,col] = size(FilledLabel); for i = 1 : row for j = 1 : col if(FilledLabel(i,j) > 0) Area(FilledLabel(i,j)) = Area(FilledLabel(i,j)) + 1; %通过统计像素点个数的方式来求各形状的面积 end end end

%计算各个图形单元的圆度 for i = 1 : num
Ecllipseratio(i) = 4piArea(i)/Premeter(i)^2; end

%计算各个图像的颜色(色度)

HSV=rgb2hsv(I); %转换为HSV,为后面的颜色元素的提取做准备

[row,col] = size(FilledLabel); %统计填充后的图形中各块图形所含像素的个数的多少 MeanHue = zeros(1,num); for i = 1 : num Hue = zeros(Area(i),1); nPoint = 0; for j = 1 : row for k = 1 : col if(FilledLabel(j,k) == i) nPoint = nPoint + 1; Hue(nPoint,1) = HSV(j,k,1); end end end

Hue(:,i) = sort(Hue(:,1));
    for j = floor(nPoint*0.1) : floor(nPoint*0.9)
        MeanHue(i) = MeanHue(i) + Hue(j,1);
    end
    MeanHue(i) = MeanHue(i) / (0.8*nPoint);  %计算出平均的色度值
end

%识别菠胡萝卜

%构建胡萝卜的分类器,在二维特征空间对各个图像进行类别区分 huluobo=1; mazarea=Area(1); for i=1:num if(mazarea

% --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global I Area FilledLabel HSV MeanHue Ecllipseratio Label num Premeter %计算各个图形单元的周长 用连接像素点或数边界像素点个数的方法 numPoints数组表示各个图形边界的像素个数(即用个数来表示周长) %num = max(max(Label));

for i = 1 : num
    Premeter(i) = 0;
end

[row,col] = size(Label);
for i = 1 : row
    for j = 1 : col
        if(Label(i,j) > 0)
            Premeter(Label(i,j)) = Premeter(Label(i,j)) + 1;%计算标记后的各块图形边界中像素的个数的总数
        end
    end
end

%计算各个图形单元的面积 FilledLabel=imfill(Label,'holes'); %填充打过标记的边界线中间围成的图形区域 for i = 1 : num Area(i) = 0; end

[row,col] = size(FilledLabel); for i = 1 : row for j = 1 : col if(FilledLabel(i,j) > 0) Area(FilledLabel(i,j)) = Area(FilledLabel(i,j)) + 1;%通过统计像素点个数的方式来求各形状的面积 end end end ```

三、运行结果

在这里插入图片描述\ 在这里插入图片描述\ 在这里插入图片描述\ 在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab科研辅导帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值