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] Read Multiple Images in a Folder

8 Comments

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
% =====================================================================

clc
clear

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
end

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. Makasih banyak Sar, that’s really usefull (y)

  2. sama-sama Ratih..
    Thanks ya udah berkunjung ke blog ane jadinya.. ^^

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

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

  5. kaka boleh contohin gak ka, ????

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

  7. nilai histogram bentuknya vektor ka..

  8. coba gunakan fungsi “reshape” untuk menampung nilai histogramnya

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