資源簡介
模式識別中圖像識別分類MATLAB源代碼,可直接運行,對圖片中的不同水果進行有效區分

代碼片段和文件信息
%類聚算法的實現
clc
clear?all
close?all
%讀入圖像
ii=imread(‘test_3.jpg‘);
figureimshow(ii);
i=ii;
text(size(i2)size(i1)+15‘image?courtesy?of?‘‘FontSize‘7...
????‘HorizontalAlignment‘‘right‘);
%色彩空間轉換
cform=makecform(‘srgb2lab‘);???%色彩空間轉換
lab_i=applycform(icform);
ab=double(lab_i(::2:3));?%數據類型轉換
nrows=size(ab1);??????%求矩陣尺寸
ncols=size(ab2);??????%求矩陣尺寸
ab=reshape(abnrows*ncols2);
ncolors=10;????????????
[cluster_idx?cluster_center]=kmeans(abncolors‘distance‘‘sqEuclidean‘...
????‘Replicates‘3);%重復類聚三次,避免局部最小值
%用k均值類聚算法對圖像像素標記
pixel_labels=reshape(cluster_idxnrowsncols);%矩形形狀改變
figureimshow(pixel_labels[]);?????
title(‘image_labeled?by?cluster?index‘);
%生成圖像的色彩分割圖
segmented_images=cell(13);??%細胞形數組
rgb_label=repmat(pixel_labels[1?1?3]);??%矩陣平鋪
for?k=1:ncolors
????color=i;
????color(rgb_label~=k)=0;
????segmented_images{k}=color;
????figureimshow(segmented_images{k});?
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1029??2013-01-05?21:04??shangchuan\miao1.m
?????文件????????782??2013-01-05?21:05??shangchuan\miao11.m
?????文件????????899??2013-01-05?20:16??shangchuan\miao2.m
?????目錄??????????0??2014-07-08?11:20??shangchuan
-----------?---------??----------?-----??----
?????????????????2710????????????????????4
- 上一篇:MATLAB直方圖繪制代碼
- 下一篇:SPWM仿真模型
評論
共有 條評論