Pulling multiple images into script
6 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
回答(1 个)
Karen Yadira Lliguin León
2022-10-14
移动: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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!