国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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代碼的評論 (共 條)

分享到微博請遵守國家法律
石家庄市| 南召县| 鄂尔多斯市| 和田市| 米泉市| 盐源县| 祁连县| 蓬安县| 仙游县| 唐海县| 天津市| 犍为县| 延寿县| 延长县| 南乐县| 盐池县| 新晃| 昌乐县| 乳源| 龙岩市| 涞水县| 嘉鱼县| 彩票| 宁德市| 彝良县| 抚顺县| 新宁县| 阿克| 平和县| 盈江县| 卓资县| 博爱县| 营山县| 义马市| 凌云县| 凤庆县| 卢龙县| 卫辉市| 大荔县| 长汀县| 潍坊市|