Boost库中有一个非常有用的工具——gil(Generic Image Library),它可以在C++中高效地进行图像处理。其中,boost::gil::view_type_from_pixel
是gil库中的一个重要组件,它可以实现将一种像素类型转化为对应的视图类型,以便于进行图像处理。
下面我们来看一段使用boost::gil::view_type_from_pixel
的测试程序:
#include <iostream>
#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
int main()
{
// 读入图片
std::string file_name = "test.png";
rgb8_image_t img;
boost::gil::png_read_image(file_name, img);
// 设置像素类型
typedef boost::mpl::vector<unsigned char, unsigned char, unsigned char> rgb_t;
// 根据像素类型获取视图类型
typedef boost::gil::