Load bunch of image from folder s

1 visualizzazione (ultimi 30 giorni)
Krishna Subiyanto
Krishna Subiyanto il 4 Nov 2018
Risposto: Vidhi Agarwal il 18 Set 2024
hi,
i have a bunch of people face image. each image have 32*32 pixel. each people face have 10 images (its name 1.bmp - 10 bmp) and i have 40 different people face sample. every image of a person's face is placed in one folder so I have 40 folders (also name the folder with number "1" - "40". all of these folders are placed in 1 main folder with the name "orlface".
and i want to change every image to matrix of [1024*1] for 1 image and [1024*200] for all image.
is it possible?
thanks

Risposte (1)

Vidhi Agarwal
Vidhi Agarwal il 18 Set 2024
You can achieve this using MATLAB. Below is a step-by-step guide and sample code to help you accomplish this task:
  • Read each image from the folders and convert the image to a grayscale matrix if it isn't already.
% Loop through each person's folder and Loop through each image in the person's folder
% Read the image
img = imread(imgFileName);
% Convert to grayscale if necessary using
img = rgb2gray(img);
  • Flatten each image matrix (32x32) into a vector (1024x1).
% Flatten the image matrix to a vector
imgVector = reshape(img, [1024, 1]);
  • Store each vector in a larger matrix (1024x200) where each column represents a flattened image.
% Store the vector in the appropriate column
allImagesMatrix(:, imageCounter) = imgVector;
  • Loop through each folder and image to process them.
% allImagesMatrix now contains all images as column vectors
disp(size(allImagesMatrix)); % Should display [1024, 200]
For in depth understanding of Flattening, refer to the following documentation:
Hope that helps!

Community Treasure Hunt

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

Start Hunting!

Translated by