function varargout = the4th(varargin)
%========filename:the4th.m============%
%=========水果图像的模式识别==12120389==曹嘉=====%
%==========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
% 读入样本图像
img1 = imread('梨.jpg');
bwpic = RGB2bw(img1);
samfea(1,:) = get_features(img1, bwpic);
img2 = imread('青椒.jpg');
bwpic = RGB2bw(img2);
samfea(2,:) = get_features(img2, bwpic);
img3 = imread('西红柿.jpg');
bwpic = RGB2bw(img3);
samfea(3,:) = get_features(img3, bwpic);
img4 = imread('香蕉.jpg');
bwpic = RGB2bw(img4);
samfea(4,:) = get_features(img4, bwpic);
%读入测试图像
testimg = imread('test.jpg');
% 测试图像二值化
bwpic = RGB2bw(testimg);
%figure, imshow(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
% 特征提取
for i=1:4
testfea(i,:) = get_features(testimg, mask(:,:,i));
end
name = {'梨', '青椒', '西红柿', '香蕉'};
% 识别
index = recognition(testfea, samfea);
% 显示结果
%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
% --------------------------------------------------------------------
function menu_62_Callback(hObject, eventdata, handles)
% hObject handle to menu_62 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
% --------------------------------------------------------------------
function menu_51_Callback(hObject, eventdata, handles)
% hObject handle to menu_51 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global samfea
img1 = imread('梨.jpg');
bwimg = RGB2bw(img1);
samfea(1,:) = get_features(img1, bwimg);
img2 = imread('青椒.jpg');
bwimg = RGB2bw(img2);
samfea(2,:) = get_features(img2, bwimg);
img3 = imread('西红柿.jpg');
bwimg = RGB2bw(img3);
samfea(3,:) = get_features(img3, bwimg);
img4 = imread('香蕉.jpg');
bwimg = RGB2bw(img4);
samfea(4,:) = get_features(img4, bwimg);
samfea
% --------------------------------------------------------------------
function menu_52_Callback(hObject, eventdata, handles)
% hObject handle to menu_52 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global testimg mask testfea
for i=1:4
testfea(i,:) = get_features(testimg, mask(:,:,i));
end
testfea
% --------------------------------------------------------------------
function menu_41_Callback(hObject, eventdata, handles)
% hObject handle to menu_41 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I2
figure
subplot(1,2,1)
imshow(I2)
subplot(1,2,2)
imhist(I2)
% --------------------------------------------------------------------
function menu_42_Callback(hObject, eventdata, handles)
% hObject handle to menu_42 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I2
K=histeq(I2);
figure
subplot(1,2,1)
imshow(K)
subplot(1,2,2)
imhist(K)
% --------------------------------------------------------------------
function menu_31_Callback(hObject, eventdata, handles)
% hObject handle to menu_31 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
bwpic = imread('梨.jpg');
%handles.testimg = testimg;
bwpic = RGB2bw(bwpic);
imshow(bwpic);
% --------------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
【水果识别】基于matlab GUI灰度+二值化+腐蚀+膨胀算法水果识别【含Matlab源码 671期】.zip
共11个文件
jpg:6个
m:4个
fig:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 142 浏览量
2024-06-20
17:07:12
上传
评论
收藏 113KB 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源码 671期】.zip (11个子文件)
【水果识别】基于matlab GUI灰度+二值化+腐蚀+膨胀算法水果识别【含Matlab源码 671期】
test.jpg 5KB
the4th.m 12KB
RGB2bw.m 299B
the4th.fig 7KB
梨.jpg 7KB
西红柿.jpg 5KB
recognition.m 413B
青椒.jpg 41KB
get_features.m 564B
香蕉.jpg 35KB
运行结果.JPG 47KB
共 11 条
- 1
资源评论
Matlab领域
- 粉丝: 3w+
- 资源: 3222
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Kotlin语言的Android开发工具类集合源码
- 零延迟 DirectX 11 扩展实用程序.zip
- 基于Java的语音识别系统设计源码
- 基于Java和HTML的yang_home766个人主页设计源码
- 基于Java与前端技术的全国实时疫情信息网站设计源码
- 基于鸿蒙系统的HarmonyHttpClient设计源码,纯Java实现类似OkHttp的HttpNet框架与优雅的Retrofit注解解析
- 基于HTML和JavaScript的廖振宇图书馆前端设计源码
- 基于Java的Android开发工具集合源码
- 通过 DirectX 12 Hook (kiero) 实现通用 ImGui.zip
- 基于Java开发的YY网盘个人网盘设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功