imageFiles = dir('*.jpg');
numImages = length(imageFiles);
images = cell(1, numImages);
currentFilename = fullfile(imageFiles(i).folder, imageFiles(i).name);
images{i} = imread(currentFilename);
numPixels = size(images{1}, 1) * size(images{1}, 2);
featureMatrix = zeros(numImages, numPixels, 3);
featureMatrix(i, :, :) = reshape(images{i}, numPixels, 3);
[idx, centroids] = kmeans(reshape(featureMatrix, [], 3), numClusters);
cluster1Indices = find(idx == 1);
cluster2Indices = find(idx == 2);
for i = 1:length(cluster1Indices)
subplot(2, length(cluster1Indices), i);
imshow(images{cluster1Indices(i)});
title(['Cluster 1 - Image ', num2str(i)]);
for i = 1:length(cluster2Indices)
subplot(2, length(cluster2Indices), length(cluster1Indices) + i);
imshow(images{cluster2Indices(i)});
title(['Cluster 2 - Image ', num2str(i)]);