简体   繁体   English

如何对像素数据使用 CImg 函数?

[英]How to use CImg functions with pixel data?

I am using Visual Studio and looking to find a useful image processing library that will take care of basic image processing functions such as rotation so that I don't have to keep coding them manually.我正在使用 Visual Studio 并希望找到一个有用的图像处理库,它将处理基本的图像处理功能,例如旋转,这样我就不必继续手动编码了。 I came across CImg and it supports this, as well as many other useful functions, along with interpolation.我遇到了 CImg,它支持这一点,以及许多其他有用的功能,以及插值。

However, all the examples I've seen show CImg being used by loading and using full images.但是,我看到的所有示例都显示通过加载和使用完整图像来使用 CImg。 I want to work with pixel data.我想处理像素数据。 So my loops are the typical:所以我的循环是典型的:

for (x=0;x<width; x++)
for (y=0;y<height; y++)

I want to perform bilinear or bicubic rotation in this instance and I see CImg supports this.我想在这种情况下执行双线性或双三次旋转,我看到 CImg 支持这一点。 It provides a rotate() and get_rotate function, among others.它提供了一个 rotate() 和 get_rotate 函数等。

I can't find any examples online that show how to use this with pixel data.我在网上找不到任何示例来说明如何将其与像素数据一起使用。 Ideally, I could simply pass it the pixel color, x, y, and interpolation method, and have it return the result.理想情况下,我可以简单地将像素颜色、x、y 和插值方法传递给它,并让它返回结果。

Could anyone provide any helpful suggestions?任何人都可以提供任何有用的建议吗? If CImg is not the right library for this type of this, could anyone recommend a simple, light-weight, easy-to-use one?如果 CImg 不是这种类型的合适库,有人可以推荐一个简单、轻量级、易于使用的库吗?

Thank you!谢谢!

You can copy pixel data to CImg class using iterators, and copy it back when you are done.您可以使用迭代器将像素数据复制到CImg类,并在完成CImg其复制回来。

std::vector<uint8_t> pixels_src, pixels_dst;
size_t width, height, n_colors;

// Copy from pixel data
cimg_library::CImg<uint8_t> image(width, height, 1, n_colors);
std::copy(pixels_src.begin(), pixels_src.end(), image.begin());

// Do image processing

// Copy to pixel data
pixels_dst.resize(width * height * n_colors);
std::copy(image.begin(), image.end(), pixels_dst.begin());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM