| 4 | 1/1 | 返回列表 |
| 查看: 674 | 回復(fù): 3 | |||
jgj030106銀蟲 (正式寫手)
|
[求助]
matlab中實(shí)現(xiàn)c-means聚合分類算法 已有2人參與
|
|
如何在matlab中實(shí)現(xiàn)c-means聚合分類算法,最好給個(gè)源代碼,必有重謝 發(fā)自小木蟲Android客戶端 |
程序 |

銀蟲 (小有名氣)
| CodeForge的這個(gè)代碼或許可以解答你的問題:http://www.codeforge.cn/article/289338 |
新蟲 (初入文壇)
|
%%%%%%%%%%%%%%% FCM算法分割圖像 %%%%%%%%%%%%%% %matlab function clusterResult = FCM(imagePath, C, V, M, iter, epsm) % 模糊C均值(FCM)聚類算法分割圖像 % clusterResult = FCM(imagePath, C, V, M, iter, epsm) % Example: clusterResult = FCM('E:\Image\lena.bmp') % clusterResult = FCM('E:\Image\lena.bmp',3,[0 127 255]) % Input: % imagePath: 圖像路徑 % C: 類別數(shù),缺省值為2 % V: 初始化聚類中心,缺省值為[0 255] % M: 加權(quán)指數(shù),缺省值為2 % iter: 迭代次數(shù),缺省值為100 % epsm: 迭代停止閾值,缺省值為1.0e-2 % Output: % clusterResult: 聚類中心結(jié)果 % Note: % C的值要與V的初始化聚類中心個(gè)數(shù)相同 % 設(shè)定缺省值 I= imread('1024.bmp'); if nargin < 6 epsm = 1.0e-2; end if nargin < 5 iter = 100; end if nargin < 4 M = 2; end if nargin < 3 [x,y,z]=impixel(I); V(1)=z(1); V(2)=z(2); V(3)=z(3); end if nargin < 2 C = 3; end % 讀入圖像及其信息 figure, imshow(I); title('原圖像'); [row col] = size(I); grayHist = imhist(I); % figure, imhist(I); % title('直方圖'); histProb = grayHist / (row * col); len = length(histProb); % tic % FCM迭代過程 cnt = 0; while(cnt < iter) % 計(jì)算隸屬度函數(shù)(注意要特殊考慮某個(gè)像素點(diǎn)和聚類中心一樣的情況) for i = 1 : len flag = 0; for j = 1 : C if i == V(j) U(j, i) = 1.0; if j == 1 U(j + 1 : C, i) = 0.0; elseif j == 3 U(1 : C - 1, i) = 0.0; elseif j == 2 U(1 : j - 1, i) = 0.0; U(j + 1 : C, i) = 0.0; end flag = 1; break; end end if flag == 0 u = (1.0 ./ ((i - V) .^ 2)) .^ (1.0 / (M - 1)); uSum = sum(u); U(1 : C, i) = u' / uSum; end end % 計(jì)算更新各類聚類中心 for j = 1 : C i = linspace(1, len, len); v = sum(histProb' .* i .* (U(j, .^ M));vSum = sum(histProb' .* (U(j, .^ M));if vSum == 0 clusterResult(j) = 0; else clusterResult(j) = v / vSum; end end % 計(jì)算誤差并判斷算法迭代是否停止 diff = sum((clusterResult - V) .^ 2); if diff <= epsm break; else V = clusterResult; end cnt = cnt + 1; end % toc % 分割圖像 for i = 1 : row for j = 1 : col temp = (double(I(i, j)) - clusterResult) .^ 2; [fmin pos] = min(temp); I(i, j) = pos * 255 / C; end end figure, imshow(uint8(I)); title('分類后的圖像'); imshow(uint8(I),'Colormap',hsv(255)); %disp('迭代次數(shù):iterTimes = '); disp(cnt); % end of FCM.m |
新蟲 (初入文壇)
| 4 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 311(085601)求調(diào)劑 +3 | liziyeyeye 2026-03-28 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 一志愿北化085600材料專碩275|有文章專利|求調(diào)劑 +5 | Micky11223 2026-03-25 | 5/250 |
|
|
[考研] 學(xué)碩274求調(diào)劑 +7 | Li李魚 2026-03-26 | 7/350 |
|
|
[考研] 349求調(diào)劑 +6 | 杰斯塔里斯 2026-03-21 | 6/300 |
|
|
[考研] 0703一志愿9,初試成績:338,四六級(jí)已過,有科研經(jīng)歷,求調(diào)劑! +4 | Zuhui0306 2026-03-25 | 4/200 |
|
|
[考研] 311求調(diào)劑 +9 | lin0039 2026-03-26 | 9/450 |
|
|
[考研] 085405 考的11408求各位老師帶走 +3 | Qiu學(xué)ing 2026-03-28 | 3/150 |
|
|
[考研]
|
孅華 2026-03-22 | 17/850 |
|
|
[材料工程] 一志愿C9材料與化工專業(yè)總分300求調(diào)劑 +8 | 曼111 2026-03-24 | 9/450 |
|
|
[考研] 求調(diào)劑推薦 材料 304 +15 | 荷包蛋hyj 2026-03-26 | 15/750 |
|
|
[考研] 272求調(diào)劑 +7 | 腳滑的守法公民 2026-03-27 | 7/350 |
|
|
[考研]
|
18419759900 2026-03-25 | 8/400 |
|
|
[考研] 269專碩求調(diào)劑 +10 | 金恩貝 2026-03-21 | 10/500 |
|
|
[考研] 316求調(diào)劑 +5 | Pigcasso 2026-03-24 | 5/250 |
|
|
[考研] 0703化學(xué)一志愿南京師范大學(xué)303求調(diào)劑 +3 | zzffylgg 2026-03-24 | 3/150 |
|
|
[考研] 085601求調(diào)劑總分293英一數(shù)二 +4 | 鋼鐵大炮 2026-03-24 | 4/200 |
|
|
[考研] 299求調(diào)劑 +4 | 15188958825 2026-03-25 | 4/200 |
|
|
[考研] 材料與化工304求B區(qū)調(diào)劑 +3 | 邱gl 2026-03-25 | 3/150 |
|
|
[考研] 070300,一志愿北航320求調(diào)劑 +3 | Jerry0216 2026-03-22 | 5/250 |
|
|
[考研] 308求調(diào)劑 +3 | 墨墨漠 2026-03-21 | 3/150 |
|