简体   繁体   English

使用Cimg C ++进行图像处理

[英]Image manipulation with cimg C++

I'm using c++ and I have a project Im working on that requires us to remove the take in a command of encode or decode along with an "image.jpg" a "new image name" and an "ASCII_file.txt" that contains ascii characters. 我正在使用c ++,我有一个正在执行的项目,该项目要求我们删除编码或解码命令以及“ image.jpg”,“新图像名称”和“ ASCII_file.txt”,其中包含ASCII字符。 What we need to do is remove the least significant bit of a pixel and replace that with the ASCII value until there is no more ASCII characters. 我们需要做的是删除像素的最低有效位,并将其替换为ASCII值,直到不再有ASCII字符为止。 What I need to know is how to access the least significant bit using the cimg library, I have looked around but I haven't found any way of doing this. 我需要知道的是如何使用cimg库访问最低有效位,尽管我环顾四周,但没有找到任何方法。 There is of course this http://cimg.eu/reference/group__cimg__storage.html but it does not tell me a good way of finding the end just a "...". 当然有这个http://cimg.eu/reference/group__cimg__storage.html,但是它并不能告诉我找到结尾的好方法,只是一个“ ...”。 My proffessor told me to either use cimg or imagemagick for C++ and cimg looked the most straightforward. 我的校长告诉我,对于c + +使用cimg或imagemagick,cimg看起来最简单。 I really need to know how to get this done, any help is appreciated. 我真的需要知道如何完成这项工作,感谢您的帮助。 If you have any further questions, feel free to ask. 如果您还有其他问题,请随时提问。

PS Im using visual studio 2015 to program this in. PS Im使用Visual Studio 2015对此进行编程。

CImg store image as R-red, G-green, B-blue, A-alpha. CImg将图像存储为R-红色,G-绿色,B-蓝色,A-alpha。 Let's start, so you have your image loaded to memory: 让我们开始吧,让您将图像加载到内存中:

#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 我们需要做的是去除像素的最低有效位

I'm not sure what you mean, but my example should help you. 我不确定您的意思,但是我的示例可以为您提供帮助。

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

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