Pulling multiple images into script

6 visualizzazioni (ultimi 30 giorni)
Stefani
Stefani il 13 Ott 2022
Commentato: Stefani il 18 Ott 2022
Hello, I'm trying to create a loop that allows me to pull in a file folder with images, read in those images as their RGB values, and put those values in a struct. My code is below, and I'm having an error in my line that creates the variable f, it only selects one image instead of all of the images in the file. Any suggestions on how I can apply this to all images in the folder?
image_folder= uigetdir();
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
for n = 1:total_images
f= fullfile(image_folder, filenames(n).name) ;
our_images = imread(f);
face_stimuli=(struct);
face_stimuli(total_images).image = our_images;
end
save ('face_Stimuli.mat', 'face_stimuli')

Risposte (1)

Karen Yadira Lliguin León
Spostato: Matt J il 14 Ott 2022
try with this:
image_folder= uigetdir();
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
face_stimuli=struct;
for n = 1:total_images
f= fullfile(image_folder, filenames(n).name) ;
our_images = imread(f);
face_stimuli(n).image=our_images;
%face_stimuli(total_images).image = our_images;
end

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by