How can I convert multiple images (all the same size) into one matrix?

조회 수: 7 (최근 30일)
Lauren Pitts
Lauren Pitts 2019년 7월 31일
댓글: Lauren Pitts 2019년 8월 1일
I have a folder of 100 images all 32x32. When I use M = imread(0001.png) a matrix populates but that's only for that one image in the folder. I need help to create a matrix with all of the images. This is the first step for me to be able to create a dataset for my neural network training. Thanks in advance!
M = imread(0001.png)

채택된 답변

awezmm
awezmm 2019년 7월 31일
You can create a cell array that holds all the image matrices. Use a for loop to imread each image and then store it in a cell array, in each iteration:
%cell array of your image filepaths
allFilenames = {"0001.png", "0002.png", "0003.png"};
%empty cell that will store all the images
allImages = cell(length(allFilenames),1);
%for loop to imread each image from the the allFilenames cell array and store it in allImages cell array
for i = 1:length(allFilenames);
allImages{i} = imread(allFilenames{i});
end
  댓글 수: 1
Akira Agata
Akira Agata 2019년 8월 1일
Hi awezmm-san,
To get all the *.png file path, I would recommend using dir function, rather than writing them manually.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Akira Agata
Akira Agata 2019년 8월 1일
To create image dataset for training a neural network, imageDatastore should be an easy and promissing way. So I would recommend trying this function!
  댓글 수: 1
Lauren Pitts
Lauren Pitts 2019년 8월 1일
Thank you, Akira. When I use this I get a error saying it "can't find the folder location. How can I direct the fullfile to my Matlab folder on my desktop? When I inserted the C:// path I get an error.
imds = imageDatastore(fullfile(Matlab,'test'),...
'IncludeSubfolders',true,'chair','cup','.png')
Annotation 2019-08-01 105248.png

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by