路标识别与提取采用聚类方法C-meansK-means
路标识别与提取(采用聚类方法)(C-means)(K-means)能对路边进行有效识别和提取,采用MATLAB 语言编写。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-14 13:55 聚类
文件 188309 2018-05-08 20:35 聚类1.jpg
文件 140902 2018-05-08 20:35 聚类2.jpg
文件 131347 2018-05-08 20:35 聚类3.jpg
文件 6192 2018-05-14 16:09 聚类C_mean.asv
文件 9447 2018-05-14 16:36 聚类C_mean.m
文件 150101 2018-05-12 08:40 聚类fizzyC_RGB_3.fig
文件 2085162 2018-05-14 13:54 聚类fuzzyC1.fig
文件 2035652 2018-05-14 13:55 聚类fuzzyC2.fig
%C均值聚类算法
clear
clc
[filenamepathname] = uigetfile(‘*.jpg‘‘读取图片文件‘);%选择图片文件
if isequal(filename0) %判断是否选择
msgbox(‘没有选择任何图片‘);
else
pathfile = fullfile(pathnamefilename); %获得图片路径
RGB = imread(pathfile); %将图片读入矩阵
YUV = rgb2ycbcr(RGB);%转成YUV
figure;
imshow(YUV); %绘制图片
end
size_image = size(YUV(::1));
YUV = double(YUV);
i = 1:1:size_image(1);
j = 1:1:size_image(2);
data = zeros(size_image(1)*size_image(2)2);
for i = 1:size_image(1); %data为n*m矩阵,n为样本点个数,m为么个特征的维数
for j = 1:size_image(2);
data(j+(i-1)*size_image(2)1) = YUV(ij1);
data(j+(i-1)*size_image(2)2) = YUV(ij3);
end
end
[centerUobj_fcn] = fcm(data4); %模糊C聚类算法
figure
plot(data(:1)data(:2)‘o‘);
hold on;
maxU = max(U);
index1 = find(U(1:) == maxU);
index2 = find(U(2:) == maxU);
index3 = find(U(3:) == maxU);
index4 = find(U(4:) == maxU);
plot(data(index11)data(index12)‘og‘);
plot(data(index21)data(index22)‘or‘);
plot(data(index31)data(index32)‘ob‘);
plot(data(index41)data(index42)‘oy‘);
%画聚类中心
plot(center(11)center(12)‘xr‘‘MarkerSize‘15‘LineWidth‘3);
plot(center(21)center(22)‘xb‘‘MarkerSize‘15‘LineWidth‘3);
plot(center(31)center(32)‘xy‘‘MarkerSize‘15‘LineWidth‘3);
plot(center(41)center(42)‘xk‘‘MarkerSize‘15‘LineWidth‘3);
title(‘分类结果‘);
hold off;
figure
result = zeros(size_image(1)size_image(2)3)+255;
a1 = fix(index1/size_image(2));
b1 = rem(index1size_image(2));
sizea1 = size(a1);
sizeb1 = size(b1);
%画第一类点
for i = 1:size_image(1);
temp_a1 = any(a1==i);
if(temp_a1==1)
pos_a1 = find(a1 == i);
size_pos_a1 = size(pos_a1);
b_block = b1(pos_a1(1):(pos_a1(1)+size_pos_a1(2)-1));
for j = 1:size_image(2);
temp_b1 = any(b_block == j);
if(temp_b1 == 1)
result(ij:) = [100];
end
end
end
end
a2 = fix(index2/size_image(2));
b2 = rem(index2size_image(2));
sizea2 = size(a2);
sizeb2 = size(b2);
%画第二类点
for i = 1:size_image(1);
temp_a2 = any(a2==i);
if(temp_a2==1)
pos_a2 = find(a2==i);
size_pos_a2 = size(pos_a2);
b_block = b2(pos_a2(1):(pos_a2(1)+size_pos_a2(2)-1));
for j = 1:size_image(2);
temp_b2 = any(b_block == j);
if(temp_b2 == 1)
result(ij:) = [010];
end
end
end
end
a3 = fix(index3/size_image(2));
b3 = rem(index3size_image(2));
sizea3 = size(a3);
sizeb3 = size(b3);
%画第三类点
for i = 1:size_image(1);
temp_a3 = any(a3==i);
if(temp_a3==1)
pos_a3 = find(a3==i);
size_pos_a3 = size(pos_a3);
b_block = b3(pos_a3(1):(pos_a3(1)+size_pos_a3(2)-1));
for j = 1:size_image(2);
temp_b3 = any(b_block == j);
if(temp_b3 == 1)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-14 13:55 聚类
文件 188309 2018-05-08 20:35 聚类1.jpg
文件 140902 2018-05-08 20:35 聚类2.jpg
文件 131347 2018-05-08 20:35 聚类3.jpg
文件 6192 2018-05-14 16:09 聚类C_mean.asv
文件 9447 2018-05-14 16:36 聚类C_mean.m
文件 150101 2018-05-12 08:40 聚类fizzyC_RGB_3.fig
文件 2085162 2018-05-14 13:54 聚类fuzzyC1.fig
文件 2035652 2018-05-14 13:55 聚类fuzzyC2.fig
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)