function varargout = the4th(varargin)
%========filename:the4th.m============%
%=========水果图像的模式识别== =====%
%==========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领域
- 粉丝: 3w+
- 资源: 3577
最新资源
- (177506440)PHP与Mysql学生成绩管理系统.zip
- 放大电路毕业设计完整版.pdf
- (177506442)php学生管理系统.zip
- 储能系统下垂控制,蓄电池通过双向dc dc变器并联负载,变器输出电流按电阻比例分配,并补偿有下垂系数带来的母线压降 附文献
- (178068804)SpringBoot的拍卖系统.zip
- 二手车数据集文件.zip
- TSSOP的 AD封装库
- (178584614)熵值法stata代码+数据
- 海洋生态监控:毛虾入侵预警系统项目总结报告-含报告
- (180341832)空气悬架建模 软件使用:Matlab Simulink 适用场景:采用模块化建模方法,搭建非线性空气悬架模型 模型包含:路面不
- (1852624)C#记事本完整的源代码供大家学习
- 咖啡评分数据集.zip
- 登录样式优化,后端为node.js
- ECharts仪表盘-得分环.rar
- ECharts仪表盘-带标签数字动画的基础仪表盘.zip
- ECharts仪表盘-GaugeCar.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈