水果识别基于matlab GUI灰度二值化草莓识别含Matlab源码 653期
Posted 紫极神光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了水果识别基于matlab GUI灰度二值化草莓识别含Matlab源码 653期相关的知识,希望对你有一定的参考价值。
一、简介
基于matlab GUI草莓识别
二、源代码
function varargout = untitled(varargin)
% UNTITLED M-file 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 11-Jan-2013 13:05:10
% 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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
global str;
[filename,pathname]=uigetfile_new({\'*.*\'},\'选择训练图片...\');
str=[pathname filename];
im=imread(str);
axes(handles.axes1);
imshow(im);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im1;
global str1;
[filename,pathname]=uigetfile_new({\'*.*\'},\'选择测试图片...\');
str1=[pathname filename];
im1=imread(str1);
axes(handles.axes2);
imshow(im1);
% --- 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 im;
global im1;
global str1;
se1 = strel(\'disk\',5);
se2 = strel(\'square\',16);
thresh1 = 0.2;
thresh2 = 0.01;
imtra = im2double(im);
rt = imtra(:,:,1);
gt = imtra(:,:,2);
bt = imtra(:,:,3);
idxr1 = find(rt>0);
idxg1 = find(gt>0);
idxb1 = find(bt>0);
mr1 = mean(rt(idxr1));
mg1 = mean(gt(idxg1));
mb1 = mean(bt(idxb1));
function n = adjvar(im)
[row,col] = size(im);
x = ones(row+4,col+4);
x = -x;
x(3:row+2,3:col+2) = im;
idx = find(x~=-1);
y(:,1) = x(idx);
y(:,2) = x(idx-1);
y(:,3) = x(idx+1);
y(:,4) = x(idx-row-4);
y(:,5) = x(idx+row+4);
y(:,6) = x(idx-row-5);
y(:,7) = x(idx-row-3);
v = var(y,0,2);
n = imadjust(n);
三、运行结果
四、备注
版本:2014a
完整代码或代写加1564658423
以上是关于水果识别基于matlab GUI灰度二值化草莓识别含Matlab源码 653期的主要内容,如果未能解决你的问题,请参考以下文章
二维码识别基于matlab GUI 灰度+二值化+校正二维码生成与识别含Matlab源码 635期
水果识别基于matlab GUI形态学水果识别含Matlab源码 907期