【发布时间】:2021-12-22 22:11:19
【问题描述】:
我有一个包含 200 张图片的文件夹。我将所有这些图像加载到名为training 的图像类型数组列表中。我在将其转换为一维向量时遇到问题。我需要帮助,正在编写基于 PCA 的人脸识别解决方案,谢谢。
List<Image> training = new List<Image>();
//the path to the images
static string path = "C:/Users/User/Documents/visual studio 2015/Projects/PCA/PCA/training";
public Form1()
{
InitializeComponent();
}
//the method below starts the training process
private void button1_Click(object sender, EventArgs e)
{
/*read all the images in the training folder into an array
in this case the images are already in gray scale so we do not need to convert
*/
var files = Directory.GetFiles(path);
foreach(string r in files)
{
if(Regex.IsMatch(r, @"\.jpg$|\.png$|\.gif$"))
{
training.Add(Image.FromFile(r));
}
}
//convert the list of images to a one dimension vector
}
更新
我有一个名为matrix data 的变量,它已初始化为大小[200,92*112],然后我进行了此列表训练,我需要遍历列表中的所有图像并访问pixel 并将其分配给matrix_data。我想现在很清楚,如何实现这一目标?
【问题讨论】:
-
您可以查看这个答案,该答案显示了访问单个图像像素的方法stackoverflow.com/a/190395/234087
-
@Fede,谢谢,我当然需要一个数据类型变量来加载像素,因为我正在循环遍历每个图像,我需要一些帮助
-
图像通常作为带有一些元数据的字节数组进行管理,例如 with/height/stride/pixelformat。或者作为 16 位灰度数据的 ushort 数组。
-
这能回答你的问题吗? stackoverflow.com/questions/3801275/…
-
@JonasH,我很难做到这一点,因为期望一维数组需要单列和多行,而图像有
width列和height行