如何将位图转换为可以用C++(ANN)处理的"矩阵"?
How to convert bitmaps to 'matrices' that can be processed in C++ ( ANN )?
我想将提取的字符位图(.bmp文件)输入到某种矩阵中,这些矩阵可以在C++中处理,然后输入到人工神经网络中,例如,该网络将接受72个输入-每个输入都是尺寸为6 x 12的二进制图像的一个像素。
例如:我有一个大小为40 x 80的二进制位图。我想把它做成一个尺寸为6 x 12的结构,它将由我的缩放位图组成。所以我需要一个位图库,它可以让我缩放bmp,然后将它们输入到ANN中
我在这里能用什么?
似乎任何图像处理库都可以满足您的需求。因此,我的建议是使用一个尽可能简单的库来集成到您的构建过程中。在这种情况下,CImg库对我们来说非常容易,因为它是由一个简单的.h文件组成的。
关于您的需求,一种可能的实施方式是
#include "CImg.h"
using namespace cimg_library;
int main(int argc,char **argv)
{
CImg<unsigned char> image("img/logo.bmp");
//Simple resize with nearest neighbour interpolation
//image = image.resize(64, 64);
//If you want to specify the interpolation type
image = image.resize(64, 64, -100, -100, 4);//The last param specifies the interpolation type
//param interpolation_type Method of interpolation :
// -1 = no interpolation : raw memory resizing.
// - 0 = no interpolation : additional space is filled according to p border_condition.
// - 1 = nearest-neighbor interpolation.
// - 2 = moving average interpolation.
// - 3 = linear interpolation.
// - 4 = grid interpolation.
// - 5 = bicubic interpolation.
// - 6 = lanczos interpolation.
CImgDisplay main_disp(image,"Image resized");
//This last part of code is not usfeul for you, it is only used to display the resized image
while (!main_disp.is_closed() )
main_disp.wait();
return 0;
}
位图文件格式(请参阅规范)已经将位图存储为矩阵,或者更准确地说是像素阵列,可以按行(或列)划分为2D阵列,但这无关紧要。
因此,您只需要读取标头并获得图像大小,然后读取压缩struct
数组中的数据(如本文所述,不带填充)。
通过这种方式,您可以获得矩阵,然后将其封装在一个类中以存储宽度和高度属性,甚至可以将数组提供给个人风格矩阵的构造函数。
使用某种bmp库来访问数据(取决于平台)。这通常会使bmp成为一个平面阵列。取这个平面数组,将每个值插入到矩阵结构中,或者直接将其传递到NN代码中。如果没有更多信息,就无法为您提供更多信息。
相关文章:
- 警告处理为错误这里有什么问题
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 使用流处理接收到的数据
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 基于多个条件处理地图中的所有元素
- 如何用数字处理log(0)
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- 错误处理.将系统错误代码映射到泛型
- 从文本文件中读取时钟时间和事件时间并进行处理
- 在运行时处理类型擦除的数据-如何不重新发明轮子
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 用于矢量处理的多个线程
- 对字符串进行排序时,在c++中处理sort()
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- 处理除以零会导致<csignal>意外行为
- 是否可以在c++中处理字符串流中的各个元素
- 如何将位图转换为可以用C++(ANN)处理的"矩阵"?