• 大小: 45KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签:

资源简介

快速K-均值(kmeans)聚类图像分割算法源代码

资源截图

代码片段和文件信息

function [mumask]=kmeans(imak)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   kmeans image segmentation
%
%   Input:
%          ima: grey color image
%          k: Number of classes
%   Output:
%          mu: vector of class means 
%          mask: clasification image mask
%
%   Author: Jose Vicente Manjon Herrera
%    Email: jmanjon@fis.upv.es
%     Date: 27-08-2005
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% check image
ima=double(ima);
copy=ima;         % make a copy
ima=ima(:);       % vectorize ima
mi=min(ima);      % deal with negative 
ima=ima-mi+1;     % and zero values

s=length(ima);

% create image histogram

m=max(ima)+1;
h=zeros(1m);
hc=zeros(1m);

for i=1:s
  if(ima(i)>0) h(ima(i))=h(ima(i))+1;end;
end
ind=find(h);
hl=length(ind);

% initiate centroids

mu=(1:k)*m/(k+1);

% start process

while(true)
  
  oldmu=mu;
  % current classification  
 
  for i=1:hl
      c=abs(ind(i)-mu);
      cc=find(c==min(c));
      hc(ind(i))=cc(1);
  end
  
  %recalculation of means  
  
  for i=1:k 
      a=find(hc==i);
      mu(i)=sum(a.*h(a))/sum(h(a));
  end
  
  if(mu==oldmu) break;end;
  
end

% calculate mask
s=size(copy);
mask=zeros(s);
for i=1:s(1)
for j=1:s(2)
  c=abs(copy(ij)-mu);
  a=find(c==min(c));  
  mask(ij)=a(1);
end
end

mu=mu+mi-1;   % recover real range


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

     文件       1425  2008-05-18 10:09  kmeans.m

     文件        102  2008-05-18 10:16  loadFile.do_files\00th.png

     文件        103  2008-05-18 10:16  loadFile.do_files\30th.png

     文件        105  2008-05-18 10:16  loadFile.do_files\40th.png

     文件        105  2008-05-18 10:16  loadFile.do_files\50th.png

     文件         96  2008-05-18 10:16  loadFile.do_files\90th.png

     文件        646  2008-05-18 10:16  loadFile.do_files\blue_band_536x5.gif

     文件         57  2008-05-18 10:16  loadFile.do_files\bullet.gif

     文件       6815  2008-05-18 10:16  loadFile.do_files\Captcha.htm

     文件      10462  2008-05-18 10:16  loadFile.do_files\cmnty1.css

     文件         70  2008-05-18 10:16  loadFile.do_files\doc.gif

     文件         97  2008-05-18 10:16  loadFile.do_files\dots_rnav.gif

     文件        152  2008-05-18 10:16  loadFile.do_files\dots_rnav_top.gif

     文件         64  2008-05-18 10:16  loadFile.do_files\exclamation.gif

     文件        145  2008-05-18 10:16  loadFile.do_files\fullstar.gif

     文件        145  2008-05-18 10:16  loadFile.do_files\fullstar_grey.gif

     文件        117  2008-05-18 10:16  loadFile.do_files\ltblue_top_nav_trans.gif

     文件        155  2008-05-18 10:16  loadFile.do_files\mail_brdr.gif

     文件       2569  2008-05-18 10:16  loadFile.do_files\mlc_logo.gif

     文件       9387  2008-05-18 10:16  loadFile.do_files\preview.jpg

     文件         64  2008-05-18 10:16  loadFile.do_files\question.gif

     文件         43  2008-05-18 10:16  loadFile.do_files\s65302541014456.gif

     文件       3296  2008-05-18 10:16  loadFile.do_files\site3.css

     文件         43  2008-05-18 10:16  loadFile.do_files\spacer.gif

     文件         66  2008-05-18 10:16  loadFile.do_files\submitfile.gif

     文件      39363  2008-05-18 10:16  loadFile.do_files\s_code.js

     文件        260  2008-05-18 10:16  loadFile.do_files\xmlicon_30x12.gif

     目录          0  2008-05-18 10:16  loadFile.do_files

     文件      42557  2008-05-18 10:16  loadFile.do.htm

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

............此处省略2个文件信息

评论

共有 条评论

相关资源