資源簡介
路標識別與提取(采用聚類方法)(C-means)(K-means)能對路邊進行有效識別和提取,采用MATLAB 語言編寫。

代碼片段和文件信息
%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
- 上一篇:MATLAB 常用函數參考
- 下一篇:機器視覺單目測量
評論
共有 條評論