1

I'm trying to perform content-based image retrieval (CBIR) using k-means clustering. I use the PCA function princomp() with a feature vector length of 190.

I have 500 test images in color taken from here. There's 5 categories in total. When I run my code I only get 3 clusters and the images look very different. What am I doing wrong?

Here is my code:

% 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');
fenceop
  • 1,439
  • 3
  • 18
  • 29
zero one
  • 19
  • 2
  • It's hard to say. It could be the fact that the combination of your features that constitute the clustering (first line of code) may be improper. Did you try just clustering on one feature?... maybe just colour? I can't really suggest anything because you didn't describe your feature vector. All we have is the first line of code and I don't really know what those features are. – rayryeng Jun 06 '15 at 19:13
  • i have 6 features hsvhistogram , autocorrelogram, gaborwavelet, color moment,waveletTransform, lowpassfilter – zero one Jun 06 '15 at 21:06
  • Those all describe very different things. You can't just blindly combine all of them into a single feature vector and hope you get good results! – rayryeng Jun 06 '15 at 21:09
  • but i get a good result without kmeans implementation , when i add this acp and kmeans i get bad result – zero one Jun 06 '15 at 21:19
  • Then why are you using kmeans? – rayryeng Jun 06 '15 at 21:47
  • because i think that the kmeans give us a better results ....but in this case i'm surprised and i think that i makes mistakes in my code – zero one Jun 06 '15 at 21:57
  • I can't really comment because I don't know what your code is doing before you call `kmeans`. If you could perhaps edit your post and talk about what those calculations are doing, that may help... but if you're not getting good results with `kmeans`, don't assume that you did it wrong... it may just be the fact that your features in conjunction with `kmeans` simply doesn't work. – rayryeng Jun 07 '15 at 05:24
  • can u give me ur mail to contact u privately and to show u my project – zero one Jun 07 '15 at 16:16

0 Answers0