I have about 400 images. 20 images that belong to 20 different categories. I need to perform automatic image clustering and display the results i.e clusters with images in a tree format.
I am working on MATLAB for the first time and I have managed to perform the following
- Load all the images
- Convert the images to grayscale
- Resize all images to 75*75
- Extract sift features
- K means clustering for 20 clusters
Now, I am not able to figure out how to display images that belong to different clusters in a tree format.
My code is here
for i = 1:length(Names)
im = imread(Names{i});
im = im2single(im2bw(im)) ; %-gray
im=imresize(im, [75 75]);
%-----------%
[f1, descr] = vl_dsift(im2single(im));
Y = datasample(descr,500,2,'Replace',false);
descriptors(:,:,1) = Y;
descriptors=double(descriptors);
end
%kmeans
numClusters = 20 ;
[centers, assignments] = vl_kmeans(descriptors, numClusters);
The output I am getting is centers 128*20
and assignments is 1*500
matrix. Can someone please tell me how do I find out which image belongs to which cluster and display clusters with images separated? I need to display clusters in a tree format with each cluster displaying images that it contains.