www.pudn.com > 1_FCM_S.zip > main_fcm_spatial.m, change:2015-12-27,size:943b


%%% 对图像进行分割,采用灰度 
clear 
clc 
%%%%%%%%%%%%%%%%%图像%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
h=imread('11.jpg');  
I=rgb2gray(h); 
I=imnoise(I,'Gaussian',0,0.003); 
% I=imnoise(I,'speckle',deta_2); 
% I=imnoise(I,'salt & pepper',0.02);  
[m,n]=size(I); 
 
k=2; 
r=3; 
m_index=2; 
beta=6; 
% I = I/255; 
I=double(I); 
[I_mean,I_median]=compute_mean_median(I,r); 
% I_median=double(I_median); 
 
 
X = I(:);  %% 将图像灰度按列排列 
X_spatial_mean = I_mean(:); 
% X_spatial_median = I_median(:); 
 
%%------------------------ fcm_spatial_mean------------------------ 
fcm_spatial_mean_label=zeros(m*n,1); 
t=cputime; 
[O2, U2, obj_fcn2] = fcm_spatial_information(X,X_spatial_mean, k, beta,m_index); 
time_fcm_spatial_mean=cputime-t; 
maxU2 = max(U2);     
for j=1:k 
    index = find(U2(j, :) == maxU2); 
    fcm_spatial_mean_label(index) = j;     
end 
labels2=reshape(fcm_spatial_mean_label,[m n]); 
 
figure, imshow(labels2,[]);