[Matlab] Read Multiple Images in a Folder

Hello guys,  in this occasion I would like to share about how to read multiple images in a folder, and save the information into array. This code is conducted by Matlab, that really approachable for graduate students (subjective opinion 😀 ) . I’ll present this code for my lovely friend Ratih, and perhaps is also helpful for you all, because this case is often happened when we talk about classification, clustering, information retrieval in image processing or computer vision.

Well, for instances I have a folder named “capturedImage” as shown in a figure below. In a folder contains 24 images (let’s say 24 different colors below are 24 images hehe..).

Screen Shot 2014-02-21 at 5.42.55 pm

Let’s read the information inside image into code that is described in a brief code below. In every line has its own narrative and may help you to understand what is the code indicate. I’ll take a case about how to get mean among intensities in every image, so I used data_mean to define collected information of all images in a folder through an array. Check this code out.

% Cara ini digunakan untuk membaca gambar-gambar dalam satu folder
% dan kemudian meletakkkan nilai fitur gambar tersebut ke dalam sebuah
% array
% =====================================================================


gambar = 'capturedImage/'; % nama folder "campturedImage"
% mengindetifikasi isi folder dalam file yang berekstensi .JPG
files = dir([gambar,'*.JPG']);

m=struct2cell(files); % menentukan informasi gambar yang ada dalam folder
data_mean=[]; % inisialisasi awal array

for k=1:size(m,2)
    file = [gambar m{1,k}]; % identifikasi nama file beserta path-nya
    dataMean = mean(mean((file))) % menghitung mean dari masing-masing gambar
    data_mean=[data_mean;dataMean]; % memasukkan data mean ke dalam array

Ok, that’s all 🙂 As usual the open question to share is free welcome. Thank you and happy coding 🙂


8 thoughts on “[Matlab] Read Multiple Images in a Folder

  1. kaka klo misalnya nilai mean diganti sama ambil nilai histogram bisa gak kak…
    bales ya kaka.. 🙂

  2. @Marwiyansyah : dicoba diganti aja…
    kalau dalam kasus ini jika niali histogramnya bentuknya vektor gak bisa..

  3. contoh nilai histogramnya sendiri bagaimana yang dimaksud?
    Output nilai histogram kira-kira ingin seperti apa?

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s