资源简介

基于FuzzyMeansCluster算法的高光谱遥感图像聚类(matlab实现)

资源截图

代码片段和文件信息

%function [clusters] = Fuzzy_K(patterns_incplot_on)
clear all
clc
%read an image file 92av3c9.lan  from Multispec

fid1=fopen(‘c:\image\92av3c9.lan‘‘rb‘); 
status=fseek(fid1128‘bof‘);
bandnum=9;
row=145;
column=145;
X1=uint16(fread(fid1[row*bandnum column]‘uint16‘));
fclose(fid1);


% change the multispect picture 92av3c9.lan to 3D
for n=1:bandnum
     Y1(1:row1:columnn)=X1(1+(n-1)*row:n*row1:column)‘;
  
end

%read ground truth from the file ‘92av3gt.gis‘
fid=fopen(‘C:\image\92AV3GT.GIS‘‘rb‘);
status=fseek(fid128‘bof‘);
row=145;
column=145;
X=uint8(fread(fid[column row]‘uint8‘));
fclose(fid);

X=X‘;
X_ESSS=X;
max=0;
for i=1:row
    for j=1:column
        if max            max=X_ESSS(ij);
        end
    end
end
count=zeros(161);
for i=1:1:16
    for j=1:row
        for k=1:column
            if X_ESSS(jk)==i
                count(i)=count(i)+1;
            end
        end
    end
end  
count        

% define the patterns that  needs to be classified

for n=1:bandnum

pattern=Y1(::n);
pattern=pattern‘;

X=X‘;
X111=X;
pattern1=pattern(find(X(::)==2));

pattern2=pattern(find(X(::)==5));

pattern3=pattern(find(X(::)==6));

pattern4=pattern(find(X(::)==8));

pattern5=pattern(find(X(::)==11));

pattern6=pattern(find(X(::)==14));

patterns_in(n:)=[pattern1‘pattern2‘pattern3‘pattern4‘pattern5‘pattern6‘];

end

patterns_in=double(patterns_in);

X=X‘;
% define the matrix for the coordinates of the patterns that are to be classified
[R1C1]=find(X(::)==2); 
co1=[R1C1]‘;
[R2C2]=find(X(::)==5);
co2=[R2C2]‘;
[R3C3]=find(X(::)==6);
co3=[R3C3]‘;
[R4C4]=find(X(::)==8);
co4=[R4C4]‘;
[R5C5]=find(X(::)==11);
co5=[R5C5]‘;
[R6C6]=find(X(::)==14);
co6=[R6C6]‘;

coordinates=[co1co2co3co4co5co6];



% fuzzy K-means

%Reduce the number of data points using the fuzzy k-means algorithm
%Inputs:
% patterns_in     - Input patterns
% c - Number of output data points
%   plot_on         - Plot stages of the algorithm
%
%Outputs
% patterns - New patterns
% clusters     - New clusters

m = 2;
N = size(patterns_in2);
c       = 6;%c--the number of clusters designated   
dist = zeros(cN);       
Dim     = size(patterns_in1);%t = size(Xdim) returns the size of the dimension of X specified by scalar dim.

%Initialize the V‘s
%V--the clustering centroids
V   = randn(Dimc);
V = sqrtm(cov(patterns_in‘1))*V + mean(patterns_in‘)‘*ones(1c);

old_V = zeros(Dimc);

%Initialize the U‘s
%U--the membership matrix

for i = 1:c
      dist(i:) = sum((patterns_in(::) - V(:i)*ones(1N)).^2);
      %the sum of the square of the distance from one pattern to eac clustering centroid 
   end
   
  %Compute U‘s 
   U = (1./dist).^(1/(m-1));
   U = U ./ (ones(c1) * sum(U)); 
   %If A is a matrix sum(A) treats the columns of A as vectors returning a row vector of the sums of 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4714  2007-06-04 19:25  Fuzzy_K.m

----------- ---------  ---------- -----  ----

                 4714                    1


评论

共有 条评论