资源简介

基于聚类的路标检测(K-means)(MATLAB)(RGB)通过采用RGB的颜色特征空间,如果和YUV结合使用,识别效果更佳。

资源截图

代码片段和文件信息

function varargout = K_means(varargin)
% K_MEANS M-file for K_means.fig
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name‘       mfilename ...
                   ‘gui_Singleton‘  gui_Singleton ...
                   ‘gui_OpeningFcn‘ @K_means_OpeningFcn ...
                   ‘gui_OutputFcn‘  @K_means_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 K_means is made visible.
function K_means_OpeningFcn(hobject eventdata handles varargin)
handles.output = hobject;
guidata(hobject handles);

% --- Outputs from this function are returned to the command line.
function varargout = K_means_OutputFcn(hobject eventdata handles) 
varargout{1} = handles.output;

% --- Executes on button press in Pushbutton_Imread.
function Pushbutton_Imread_Callback(hobject eventdata handles)
global Fig;
global Length;
global Width;
global Dim;
global Num;
global PopUp;
global xPos;
global yPos;
global R;
global G;
global B;
global R_GB;
global angle_x;
angle_x=0;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% : Initilize var
Length=0;
Width=0;
Num=0;
PopUp=0;
xPos=0;
yPos=0;
Fig=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%显示图像和尺寸
[filenamepathname]=uigetfile({‘*.jpg‘:‘*.bmp‘:‘*.gif‘}‘选择图片‘);    
str=[pathname filename];
Fig=imread(str);
[LengthWidthDim]=size(Fig);
str1=num2str(Length);
str2=‘*‘;
str3=num2str(Width);
str=strcat(str3str2str1);
set(handles.Edit_Imread‘string‘str);
axes(handles.Axes_ResultPho);
hold off
Fig_white=Fig;
Fig_white=255*ones(LengthWidthDim);
imshow(Fig_white);
axes(handles.Axes_InitPho);
hold off;
h=imshow(Fig);
set(handles.Axes_InitPho‘visible‘‘on‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取样本点数量
Str=get(handles.edit_Num‘string‘);
Num=str2num(Str);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取产生样本点
Fig=double(Fig);
Val=get(handles.pop_example‘Value‘);
Str=get(handles.pop_example‘String‘);
switch Str{Val}
    case ‘Rand‘
        PopUp=1;
        for i=1:Num
            xPos(i)=floor(rand*Length)+1;
            yPos(i)=floor(rand*Width)+1;
            R(i)=Fig(xPos(i)yPos(i)1);
            G(i)=Fig(xPos(i)yPos(i)2);
            B(i)=Fig(xPos(i)yPos(i)3);  
            R_GB(i)=R(i)/(G(i)+B(i));
%           GB_R(i)=(G(i)+B(i))/R(i);
        end            
    case ‘Rules‘
        PopUp=2;
        temp=round(sqrt((Num*Length)/Width));
        if temp%             temp=temp+1;
        temp=temp;
        end
        LenNum=temp;
        WidNum=round(temp*Width/Length);
        if LenNum*WidNum            WidNum=WidNum+1;
        end
        deta_Len=floo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-05-18 18:08  2\
     文件       64512  2015-05-17 23:55  2\Kmeans.vsd
     文件       22006  2010-05-11 18:23  2\K_means.fig
     文件       11241  2010-05-12 19:03  2\K_means.m
     文件      233120  1998-04-12 16:09  2\S3a.bmp
     文件       18355  2010-04-25 19:28  2\图片1.jpg
     文件       47104  2010-05-13 19:24  2\模式识别homework2.ppt
     文件      140902  2010-04-21 19:59  2\照片 064.jpg
     文件      188309  2010-04-21 20:03  2\照片 085.jpg
     文件      131347  2010-04-21 20:03  2\照片 088.jpg

评论

共有 条评论