Pulling multiple images into script

6 次查看(过去 30 天)
Stefani
Stefani 2022-10-13
评论: Stefani 2022-10-18
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')

回答(1 个)

Karen Yadira Lliguin León
移动:Matt J 2022-10-14
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by