How can I read a batch of images instead of a single image, cluster them and pick the desired clusters for the segmented images for further analysis?

1 Ansicht (letzte 30 Tage)
I am using the following code for the segmentation of images which has rash on the skin which can segment only a single image. I want to find a way to read a batch of images instead of a single image and pick the desired clusters for further analysis.
I have attached two images for testing.
Help me please!
I = imread(['ColorSpace\ForExperiment\foot.jpg']);
lab_he = rgb2lab(I);
% Extract first channel (L)
ab = lab_he(:, :, 2:3);
% Convert to data type single
ab = im2single(ab);
% Perform clustering using K-Means
nColors = 4;
pixel_labels = imsegkmeans(ab, nColors, "NumAttempts", 5);
imshow(pixel_labels, []);
% Display each cluster with their objects
mask1 = pixel_labels == 1;
cluster1 = I .* uint8(mask1);
imshow(cluster1); title('Objects in cluster1');
% Display second cluster's objects
mask2 = pixel_labels == 2;
cluster2 = I .* uint8(mask2);
imshow(cluster2); title('Objects in cluster2');
% Display third cluster's objects
mask3 = pixel_labels == 3;
cluster3 = I .* uint8(mask3);
imshow(cluster3); title('Objects in cluster3');
% Display fourth cluster's objects
mask4 = pixel_labels == 4;
cluster4 = I .* uint8(mask4);
imshow(cluster4); title('Objects in cluster4');

Antworten (1)

Image Analyst
Image Analyst am 9 Mär. 2020
To process a folder of images, put your code inside a loop over files. See the FAQ for code samples:
  1 Kommentar
Mohammad Farhad Aryan
Mohammad Farhad Aryan am 12 Mär. 2020
Thank you very much for your reply. You helped my alot and as I reviewed many different questions in forum, your asnwers were the most applicable ones.
I am able to read multiple images and give them as input the the code written above but the problem is that how can I get the clusters for multiple images with the KMeans algorithm?, for example if I read 3 images and input them to the KMeans with 4 clusters written above, so how can I display the 1st cluster, the 2nd cluster, the 3rd cluster and the 4th cluster for 3 input images.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by