【水果识别】基于灰度直方图水果识别matlab源码含 GUI
发布日期:2021-05-04 12:56:11
浏览次数:33
分类:技术文章
本文共 4990 字,大约阅读时间需要 16 分钟。
一、简介
基于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 untitled_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to untitled_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 untitled% Last Modified by GUIDE v2.5 15-Jan-2017 01:03:42% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 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 untitledhandles.output = hObject;% Update handles structureguidata(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 structurevarargout{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 endend%计算各个图形单元的圆度for i = 1 : num Ecllipseratio(i) = 4*pi*Area(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 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 endend
三、运行结果
四、备注
完整代码或者代写添加QQ 1575304183
转载地址:https://blog.csdn.net/qq_34763204/article/details/116379153 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月16日 00时44分41秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
HTTP协议中的Tranfer-Encoding:chunked编码解析
2019-04-27
JavaScript面向对象编程
2019-04-27
在Javascript中使用面向对象的编程
2019-04-27
PHP Webservice的发布与调用
2019-04-27
php反射类 ReflectionClass
2019-04-27
为 PHP 应用提速、提速、再提速
2019-04-27
Linux下gedit显示行号
2019-04-27
《Advanced PHP Programming》读书笔记
2019-04-27
让我们谈谈RAID
2019-04-27
jQuery日期选择器插件date-input
2019-04-27
PHP使用curl_multi_add_handle并行处理
2019-04-27
NP问题
2019-04-27
AT&T与Intel汇编语言的比较
2019-04-27
javascript解析json
2019-04-27
WinDbg安装与使用
2019-04-27
推荐阅读的多核编程技术书籍
2019-04-27
维基百科上的算法和数据结构链接很强大
2019-04-27
选择排序
2019-04-27
PHP session回收机制
2019-04-27
最新的全球编程语言,操作系统,web服务器等使用率分析报告
2019-04-27