CImg库下载:https://sourceforge.net/projects/cimg/
C++附加库CImg的基本函数:
#include "CImg.h"
using namespace cimg_library;
using namespace std;
void cimg()
{
CImg<unsigned char> img; //声明一个CImg对象
img.load_bmp("hw.bmp"); //读取bmp格式图片到该对象中
//或者直接CImg<unsigned char> img("hw.bmp")
int w = img._width;
int h = img._height; //获取图像的长与宽
CImg<unsigned char> TempImg(w, h, 1, 1, 0); //初始化一个新的灰度图像
img.display(); //图像显示
cimg_forXY(img, x, y) //该函数用于逐个像素点处理
{
if(img(x, y, 0) == 102 && img(x, y, 1) == 102 && img(x, y, 2) == 102)
//0、1、2分别对应rbg三个颜色通道
TempImg(x, y) = 255;
} //找出所有像素值为(102,102,102)的点并在TempImg上记录
TempImg.display();
TempImg.save("hw1.bmp); //图像保存
}