Let’s back in MATLAB code. Now, I would like give an example for classifying images based on its label. Below, we have six images and in each has label, i.e 1.JPG ( label 1), 2.JPG (label 1), 3.JPG (label 2), 4.JPG (label 2), 5.JPG (label 1), and 6.JPG (label 2). We’re going to cluster images which has label 1.
Here the code of function of classifying images. Please save it into Cluster.m.
[code language=”matlab”]
% fungsi ini digunkaan untuk menampilkan gambar2 yang berada pada kelas
% yang sama
% folder = nama folder yang berisi gambar-gambar
% label = label dari masing-masing gambar
function Cluster(folder,label,kelas)
a=find(label==kelas); % membaca indeks klasifikasi sesuai dengan kelas yang diinputkan
files = dir([folder,’*.JPG’]);
m=struct2cell(files);
figure
for k=1:size(a,1) % looping sesuai banyaknya anggota dalam kelas yang diinputkan
file = [folder m{1,a(k)}]; % file yang dikelompokkan sesuai dengan kelasnya
readfile =imread(file); % membaca file
subplot(2,2,k), imshow(readfile), title ([‘kelas’,num2str(kelas),’-‘,num2str(a(k))]);
end
[/code]
And you may run this code below as Main. We would like to show all images which is placed in label 1 and the output of this Main is shown in Figure 1
[code language=”matlab”]
clear
clc
close all
folder = ‘daun/’; % nama folder
label = [1;1;2;2;1;2]; %nama label
Cluster(folder,label,1);
[/code]
Well, this phase may help you to cluster the images well. This code presented for @Evy Kamilah 🙂 Good luck Evy 🙂