Yuita A. Sari

“If you want to be a writer, you must do two things : read a lot and write a lot. There's no way around these two things that I'm aware of, no shortcut.” ― Stephen King

[Matlab] Classifying Image based on Its Label

Leave a comment

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.

Screen Shot 2014-06-27 at 3.19.41 pm

Here the code of function of classifying images. Please save it into Cluster.m.

% 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']);

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))]);

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

close all

folder = 'daun/'; % nama folder
label = [1;1;2;2;1;2]; %nama label


Screen Shot 2014-06-27 at 3.16.16 pm

Well,  this phase may help you to cluster the images well. This code presented for @Evy Kamilah🙂 Good luck Evy🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s