c++ - 使用 cimg C++ 进行图像处理

标签 c++ windows cimg

我正在使用 C++,我有一个正在处理的项目需要我们删除编码或解码命令以及“image.jpg”、“新图像名称”和“ASCII_file.txt” "包含 ascii 字符。我们需要做的是删除一个像素的最低有效位,并用 ASCII 值替换它,直到没有更多的 ASCII 字符。我需要知道的是如何使用 cimg 库访问最低有效位,我环顾四周但我还没有找到任何方法来做到这一点。当然有这个 http://cimg.eu/reference/group__cimg__storage.html但它并没有告诉我找到结束只是一个“......”的好方法。我的教授告诉我要么对 C++ 使用 cimg 要么使用 imagemagick,而 cimg 看起来最直接。我真的需要知道如何完成这项工作,我们将不胜感激。如果您有任何其他问题,请随时提出。

附言我正在使用 visual studio 2015 对此进行编程。

最佳答案

CImg 将图像存储为 R-red、G-green、B-blue、A-alpha。 让我们开始吧,这样您就可以将图像加载到内存中:

#define cimg_use_jpeg 1

CImg<unsigned char> *image = new CImg<unsigned char>("image.jpg");

//Now we will get pointers to each channel
unsigned char * ptr_r = image.data(0, 0, 0, 0);//red pixels array 1'st row
unsigned char * ptr_g = image.data(0, 0, 0, 1);//green pixels array 1'st row
unsigned char * ptr_b = image.data(0, 0, 0, 2);//blue pixels array 1'st row
unsigned char * ptr_a = image.data(0, 0, 0, 3);//alpha array 1'st row

//Iterating over image buffer

//image rows
for(int row = 0; row < image->height(); row++) {
  unsigned char * ptr_r = image.data(0, row, 0, 0);//red pixels array 1'st row
  unsigned char * ptr_g = image.data(0, row, 0, 1);//green pixels array 1'st row
  unsigned char * ptr_b = image.data(0, row, 0, 2);//blue pixels array 1'st row
  unsigned char * ptr_a = image.data(0, row, 0, 3);//alpha array 1'st row

  for(int col = 0; col < image->width(); col++) {
      //rewriting all r chanel values with 255
      *(ptr_r) = 255;
       ptr_r++;
      //this is equal
      ptr_r[col] = 255;
  }
}

What we need to do is remove the least significant bit of a pixel

我不确定你的意思,但我的例子应该对你有帮助。

关于c++ - 使用 cimg C++ 进行图像处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34122381/

相关文章:

windows - WAAD 使用图形 API 获取 ObjecId

python - Windows 上的无服务器部署

来自二维数组的 C++ 16 位灰度渐变图像

c++ - keypressevent()中的qt多个键

c++ - constexpr 函数及其参数

Windows 主机文件和带点的主机名

C++ Xcode 9 - 无法从 Cimg 调用函数 display()

c++ - 在 CImg 中实现动画循环的正确方法

c++ - 为什么我们不能使用两个具有不同类型但完全相同的成员的结构(或类)互换?

c++ - 如何正确地将 timespec 转换为 timeval?