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 EDIT
gui_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});
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 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) = 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<Area(i))%分类器识别桃的准则:判断各个图形中面积最大的为胡萝卜
mazarea=Area(i);
huluobo=i;
end
end
%对分出来的类别分别构建相应的图像掩膜,并用对原图的亮度图像进行掩膜操作
huluoboHSV=HSV;
for j = 1 : row
for k = 1 : col
if(FilledLabel(j,k) ~=huluobo)
%huluoboHSV(j,k,2)=0;
huluoboHSV(j,k,3)=0;
end
end
end
%变换生成最终的结果图像,图像中显示的结果即对应分类器中指定的类别
huluobomatrix = hsv2rgb(huluoboHSV);%转换为RGB彩图,彩图中已经滤去了其余水果,只剩下胡萝卜
subplot(2,2,4),imshow(huluobomatrix);
% --- 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
%计算各个图形单元的圆度
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
%识别黄瓜
%构建黄瓜的分类器,在二维特征空间对各个图像进行类别区分
huanggua=0;
for i=1:num
if((Ecllipseratio(i)<0.7))%分类器识别黄瓜的准则:判断各个图形中平均圆率值小于0.7的为黄瓜
huanggua=i;
end
end
%对分出来的类别分别构建相应的图像掩膜,并用对原图的亮度图像进行掩膜操作
huangguaHSV=HSV;
for j = 1 : row
for k = 1 : col
if(FilledLabel(j,k) ~=huanggua)
%huangguaHSV(j,k,2)=0;
huangguaHSV(j,k,3)=0;
end
end
end
%变换�
没有合适的资源?快使用搜索试试~ 我知道了~
【水果蔬菜识别】基于matlab GUI灰度+二值化+腐蚀+直方图处理水果蔬菜识别【含Matlab源码 1052期】.zip
共7个文件
jpg:4个
m:1个
fig:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 79 浏览量
2024-06-20
17:07:15
上传
评论
收藏 627KB ZIP 举报
温馨提示
Matlab领域上传的代码均可运行,亲测可用,直接替换数据即可,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描博客文章底部QQ名片; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作 图像识别:表盘识别、车道线识别、车牌识别、答题卡识别、电器识别、跌倒检测、动物识别、发票识别、服装识别、汉字识别、红绿灯识别、火灾检测、疾病分类、交通标志牌识别、口罩识别、裂缝识别、目标跟踪、疲劳检测、身份证识别、人民币识别、数字字母识别、手势识别、树叶识别、水果分级、条形码识别、瑕疵检测、芯片识别、指纹识别
资源推荐
资源详情
资源评论
收起资源包目录
【水果蔬菜识别】基于matlab GUI灰度+二值化+腐蚀+直方图处理水果蔬菜识别【含Matlab源码 1052期】.zip (7个子文件)
【水果蔬菜识别】基于matlab GUI灰度+二值化+腐蚀+直方图处理水果蔬菜识别【含Matlab源码 1052期】
运行结果2.JPG 44KB
运行结果3.JPG 43KB
运行结果1.JPG 42KB
水果图.bmp 900KB
untitled.fig 24KB
运行结果4.JPG 41KB
untitled.m 29KB
共 7 条
- 1
资源评论
Matlab领域
- 粉丝: 3w+
- 资源: 3183
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功