[英]Creating a csv file by loading multiple images in matlab
I am working on a machine learning problem of classifying different types of leaves using the flavia dataset. 我正在研究使用黄花数据集对不同类型的叶子进行分类的机器学习问题。 I have a dataset folder that has 32 sub folders each containing some images of the respective class. 我有一个数据集文件夹,其中包含32个子文件夹,每个子文件夹包含相应类的一些图像。 The images are grayscale of dimension 4096x1. 图像是尺寸为4096x1的灰度。 How can i load all these images from all the subfolders at once and then create a csv file from the stored pixel values ? 我如何一次从所有子文件夹加载所有这些图像,然后从存储的像素值创建一个csv文件?
Create a cell array with all the filenames, eg 用所有文件名创建一个单元格数组,例如
C{1} = '/path/to/file1.png';
C{2} = '/path/to/file2.png';
etc. (there are several ways to do this automatically, but given I have no information on your file structure and there aren't that many files, let's skip this step. ) 等等。(有几种方法可以自动执行此操作,但是鉴于我对您的文件结构没有任何了解,而且文件数量也不多,因此我们跳过此步骤。)
Then have a for loop 然后有一个for循环
for n = 1 : 32
I = imread(C{n});
csvwrite('my_csv_file.csv', I(:).', '-append');
end
PS. PS。 The (:).'
(:).'
syntax ensures each image becomes a row. 语法可确保每个图像变成一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.