五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【聚類分割】基于 K-means 聚類算法實現(xiàn)圖像區(qū)域分割附matlab代碼

2022-09-10 11:01 作者:Matlab工程師  | 我要投稿

1 簡介

對圖像進(jìn)行顏色區(qū)域分割.將圖像轉(zhuǎn)換到CIE Lab顏色空間,用K均值聚類分析算法對描述顏色的a和b通道進(jìn)行聚類分析;通過提取各個顏色區(qū)域獨立成為單色的新圖像,對圖像進(jìn)行分割處理.實驗結(jié)果表明,在CIE Lab空間使用K—means聚類算法可以有效地分割彩色紡織品圖像的顏色區(qū)域.

2 完整代碼

clear all; close all; clc;A = double(imread('bird_small.tiff'));% 載入圖片dim = size(A,1); % 圖片行數(shù)k = 16; % 顏色分類的層數(shù)means = zeros(k, 3); % Initialize means to randomly-selected colors in the original photo.rand_x = ceil(dim*rand(k, 1));%初始means是k行k列隨機數(shù)作為聚類中心rand_y = ceil(dim*rand(k, 1));for i = 1:k ? ?means(i,:) = A(rand_x(i), rand_y(i), :);%在圖像中找到初始聚類中心endfor itr=1:100 ? ?s_x=zeros(k,3); ? ?s_ind=zeros(k,1); ? ?for i=1:dim ? ? ? ?for j=1:dim ? ? ? ? ? ?r=A(i,j,1);g=A(i,j,2);b=A(i,j,3); ? ? ? ? ? ?[val ind]=min(sum((repmat([r,g,b],k,1)-means).^2,2)); ? ? ? ? ? ?%repmat(A,k,1)對A矩陣進(jìn)行k行的復(fù)制 ? ? ? ? ? ?s_x(ind,:)=s_x(ind,:)+[r,g,b]; ? ? ? ? ? ?s_ind(ind)=s_ind(ind)+1; ? ? ? ?end ? ?end ? ?for ii=1:k ? ? ? ?if s_ind(ii)>0 ? ? ? ? ? ?s_x(ii,:)=s_x(ii,:)./s_ind(ii); ? ? ? ?end ? ?end ? ?d=sum(sqrt(sum((s_x-means).^2,2)));%計算距離 ? ?if d<1e-5 ? ? ? ?break ? ?end ? ?means=s_x; ? endmeans = round(means);itrfigure; hold onfor i=1:k ? col = (1/255).*means(i,:); ? rectangle('Position', [i, 0, 1, 1], 'FaceColor', col, 'EdgeColor', col);endaxis offlarge_image = double(imread('bird_large.tiff'));figure;subplot(121);imshow(A,[]);title('原圖')large_dim = size(large_image, 1);for i = 1:large_dim ? ?for j = 1:large_dim ? ? ? ?r = large_image(i,j,1); g = large_image(i,j,2); b = large_image(i,j,3); ? ? ? ?[val ind]=min(sum((repmat([r,g,b],k,1)-means).^2,2)); ? ? ? ?large_image(i,j,:) = means(ind,:); ? ?end endsubplot(122);imshow(uint8(round(large_image)));title('Kmean分割圖')imwrite(uint8(round(large_image)), 'bird_kmeans.jpg');% Save image

3 仿真結(jié)果

4 參考文獻(xiàn)


博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測、信號處理、元胞自動機、圖像處理、路徑規(guī)劃、無人機等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。

部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。



【聚類分割】基于 K-means 聚類算法實現(xiàn)圖像區(qū)域分割附matlab代碼的評論 (共 條)

分享到微博請遵守國家法律
双桥区| 称多县| 古田县| 双城市| 定安县| 大足县| 密山市| 兰西县| 建昌县| 白玉县| 怀化市| 利津县| 屏南县| 永胜县| 五华县| 晋江市| 满洲里市| 巴彦淖尔市| 萨迦县| 绥阳县| 民权县| 辽阳县| 灵台县| 平远县| 察雅县| 正阳县| 崇礼县| 晋宁县| 体育| 蓝山县| 锡林浩特市| 舒城县| 安多县| 鲁山县| 玛沁县| 龙井市| 柳州市| 清河县| 南阳市| 屏山县| 塔城市|