資源簡(jiǎn)介
該代碼以matlab為開(kāi)發(fā)平臺(tái),實(shí)現(xiàn)在真實(shí)環(huán)境下,可以穩(wěn)定的檢測(cè)出道路的矩形指示標(biāo)志的功能。在數(shù)據(jù)庫(kù)中做測(cè)試,正確率92%。
代碼片段和文件信息
close?all
clear?all
A=imread(‘1.jpg‘);
figure;
imshow(A);
title(‘原圖‘);
[u?v?w]=size(A);
cform=makecform(‘srgb2lab‘);
lab_A=applycform(Acform);?%?轉(zhuǎn)換到lab空間,對(duì)于顏色分割的吧?lab空間相互分量聯(lián)系性比較小?利于分割
ab?=?double(lab_A(::2:3));
nrows?=?size(ab1);
ncols?=?size(ab2);
ab?=?reshape(abnrows*ncols2);%矩陣轉(zhuǎn)換類型轉(zhuǎn)換為double型
nColors?=4;
%?采用k-means方法實(shí)現(xiàn)聚類,重復(fù)三次
[cluster_idx?cluster_center]?=?kmeans(abnColors‘distance‘‘sqEuclidean‘?‘Replicates‘3);?
%對(duì)不同的類別進(jìn)行標(biāo)志
pixel_labels?=?reshape(cluster_idxnrowsncols);
%?figure;
showImage_color(AnColorscluster_idx);
%?imshow(pixel_labels[])?title(‘聚類后圖片‘);
%分類后的矩陣
segmented_images?=?cell(14);
rgb_label?=?repmat(pixel_labels[1?1?3]);
for?k?=?1:nColors
????color?=?A;
????color(rgb_label?~=?k)?=?0;
????segmented_images{k}?=?color;
end
figure;
subplot(221)imshow(segmented_images{1})title(‘cluster?1‘);
subplot(222)imshow(segmented_images{2})title(‘cluster?2‘);
subplot(223)imshow(segmented_images{3})title(‘cluster?3‘);
subplot(224)imshow(segmented_images{4})title(‘cluster?4‘);
%?imshow(segmented_images{1})?title(‘cluster?1‘);
%
figure;
imshow(segmented_images{2})?title(‘cluster?2‘);
%?f
- 上一篇:機(jī)器人避障的matlab仿真
- 下一篇:AR建模仿真自相關(guān)算法
評(píng)論
共有 條評(píng)論