如何在CIBR系统中实现k-means聚类?

时间:2015-06-06 15:37:36

标签: matlab k-means cbir

我正在尝试使用k-means聚类执行基于内容的图像检索(CBIR)。我使用PCA函数princomp(),其特征向量长度为​​190。

我有500张彩色taken from here的测试图像。共有5个类别。当我运行我的代码时,我只得到3个集群,图像看起来非常不同。我做错了什么?

这是我的代码:

% construction of feature vector
set = [hsvHist autoCorrelogram Moments_Couleur meanAmplitude msEnergy OndelettesMoments];
% add name of image
dataset(k, :) = [set str2double(name)];

handlse.CaracVt = dataset.';
dlmwrite('f:/hellonewday', handlse.CaracVt);

% ACP function
[COEFF, SCORE, latent] = princomp(handlse.CaracVt());

laten = cumsum(latent)./sum(latent)
list = []; o = 1; c = 0;
for kn = 1:length(laten)
  if (isempty(list))
    list(o, :) = laten(kn);
    o = o + 1;
  else
    for i = 1:length(list)
      kki = abs(laten(kn) - list(i));
      if (kki > 0.006)
        c = c + 1;
      end;
    end;
    if (c == length(list))
      list(o, :) = laten(kn);
      o = o + 1;
    end;
  end;
  c = 0;
end;

handlse.NmbreCluster = length(list);
disp('The amount of clusters is: ');
disp(handlse.NmbreCluster);

handlse.CaracVt = handlse.CaracVt.';
mat = handlse.CaracVt;
mat(:, end) = [];

[kMeansClusters, c] = kmeans(mat, handlse.NmbreCluster);
dlmwrite('f:/clusters', kMeansClusters);
dlmwrite('f:/centres', c);
disp('kMeansClusters for each image: ');
disp(kMeansClusters);

c = c.';
ko = 1;
for i = 1:handlse.NmbreCluster
  array = zeros(1, 191);
  c(i, 191) = 0;
  array(:, 1) = c(i);
  for kp = 1:length(kMeansClusters)
    if (i == kMeansClusters(kp))
      ko = ko + 1;
      array(ko, :) = handlse.CaracVt(kp, :);
    end
  end;
  myArray{i} = array;
  ko = 1;
end;
disp(myArray);
uisave('myArray', 'dataset');

0 个答案:

没有答案