-
大小: 1KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-24
- 語言: 其他
- 標簽:
資源簡介
用FCM算法實現圖像分割(圖像源可以是灰度、索引和RGB圖像

代碼片段和文件信息
function?fcmapp(file?cluster_n)
%?FCMAPP
%?fcmapp(file?cluter_n)?segments?a?image?named?file?using?the?algorithm
%?FCM.
%?[in]
%???file:?the?path?of?the?image?to?be?clustered.
%???cluster_n:?the?number?of?cluster?for?FCM.
eval([‘info=imfinfo(‘‘‘file?‘‘‘);‘]);
switch?info.ColorType
????case?‘truecolor‘
????????eval([‘RGB=imread(‘‘‘file?‘‘‘);‘]);
%???????[X?map]?=?rgb2ind(RGB?256);
????????I?=?rgb2gray(RGB);
????????clear?RGB;
????case?‘indexed‘
????????eval([‘[X?map]=imread(‘‘‘file?‘‘‘);‘]);
????????I?=?ind2gray(X?map);
????????clear?X;
????case?‘grayscale‘
????????eval([‘I=imread(‘‘‘file?‘‘‘);‘]);
end;
I?=?im2double(I);
filename?=?file(1?:?find(file==‘.‘)-1);
data?=?reshape(I?numel(I)?1);
tic
[center?U?obj_fcn]=fcm(data?cluster_n);
elapsedtime?=?toc;
%eval([‘save(‘?filename?int2str(cluster_n)‘.mat‘‘?‘‘center‘‘?‘‘U‘‘?‘‘obj_fcn‘‘?‘‘elapsedtime‘‘);‘]);
fprintf(‘elapsedtime?=?%d‘?elapsedtime);
maxU=max(U);
temp?=?sort(center?‘ascend‘);
for?n?=?1:cluster_n;
????eval([‘cluster‘int2str(n)?‘_index?=?find(U(‘?int2str(n)?‘:)?==?maxU);‘]);
????index?=?find(temp?==?center(n));
????switch?index
????????case?1
????????????color_class?=?0;
????????case?cluster_n
????????????color_class?=?255;
????????otherwise
????????????color_class?=?fix(255*(index-1)/(cluster_n-1));
????end
????eval([‘I(cluster‘int2str(n)?‘_index(:))=‘?int2str(color_class)‘;‘]);
end;
filename?=?file(1:find(file==‘.‘)-1);
I?=?mat2gray(I);
%eval([‘imwrite(I‘?filename‘_seg‘?int2str(cluster_n)?‘.bmp‘‘);‘]);
imwrite(I?‘temp\tu2_4.bmp‘);
imview(I);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1625??2005-09-20?17:22??fcmapp.m
-----------?---------??----------?-----??----
?????????????????1843????????????????????2
- 上一篇:軍事仿真虛擬現實系統制作方案
- 下一篇:UML飛機訂票系統課設
評論
共有 條評論