对数变换:
CImg<int> SrcImg;
SrcImg.load_tiff("E:/Desktop/picture_process/Lenna/3/Fig0305(a)(DFT_no_log).tif");
SrcImg.display();
cimg_forXY(SrcImg, x, y) {
SrcImg(x, y) = int(log(double(SrcImg(x, y)) + 1));
}
SrcImg.display();
运行效果:
幂律变换
CImg<int> SrcImg;
SrcImg.load_tiff("E:/Desktop/picture_process/Lenna/3/Fig0308(a)(fractured_spine).tif");
SrcImg.display();
double t[3] = { 0.6,0.4,0.3 };
for (int i = 0; i < 3; i++) {
CImg<int> img = SrcImg;
cimg_forXY(img, x, y) {
img(x, y) = int(pow(double((img(x, y))), t[i]));
}
img.display();
}
运行结果:
比特面分层
CImg<int> img;
img.load_tiff("E:/Desktop/picture_process/Lenna/3/Fig0314(a)(100-dollars).tif");
img.display("原图");
int w = img.height();
int h = img.width();
CImg<int> p1(h,w,1,1), p2(h, w, 1, 1), p3(h, w, 1, 1), p4(h, w, 1, 1), p5(h, w, 1, 1), p6(h, w, 1, 1), p7(h, w, 1, 1), p8(h, w, 1, 1);
cimg_forXY(img, x, y) {
int num = img(x, y);
int *bit = binary(num);
p1(x, y) = fx(bit[0]); p2(x, y) = fx(bit[1]); p3(x, y) = fx(bit[2]); p4(x, y) = fx(bit[3]);
p5(x, y) = fx(bit[4]); p6(x, y) = fx(bit[5]); p7(x, y) = fx(bit[6]); p8(x, y) = fx(bit[7]);
}
p8.display("第八层比特图");
p7.display("第七层比特图");
p6.display("第六层比特图");
p5.display("第五层比特图");
p4.display("第四层比特图");
p3.display("第三层比特图");
p2.display("第二层比特图");
p1.display("第一层比特图");
}
//用于对图片进行黑白的赋值
int fx(int n) {
if (n == 1)
return 255;
else
return 0;
}
//用于进行二进制转化的函数
int* binary(int num) {
int *bit;
bit = new int[8];
for (int i = 0; i < 8; i++) {
bit[i] = 0;
}
int i = 0;
while (num) {
bit[i] = num % 2;
num /= 2;
i++;
}
return bit;
}
运行结果:
在这里插入图片描述
均衡化处理
- CImg有专门显示密度分布直方图的histogram函数
CImg<int> hist = img.histogram(256, 0, 255); //histogram的第一个参数是共有256个灰度级,第二个参数是灰度的最小值,第三个是灰度最大值
hist.display_graph();
CImg<int> img;
img.load_tiff("E:/Desktop/picture_process/Lenna/3/Fig0316(4)(bottom_left).tif");
CImg<int> pic = img;
img.display("处理前图片");
int size = img.size();
CImg<int> hist = img.histogram(256, 0, 255); //histogram的第一个参数是共有256个灰度级,第二个参数是灰度的最小值,第三个是灰度最大值
hist.display_graph("处理前直方图");
double sum = 0.0;
map<int, int> index;
for (int i = 0; i < 256; i++) {
sum += (double) hist(i)/size;
int Sum = (int)(sum * 255);
index.insert(pair<int, int>(i, Sum));
}
//map<int, int>::iterator iter = index.begin();
//map<int, int>::iterator end = index.end();
/*for (; iter != end; iter++) {
cout << iter->first<<":"<< iter->second << endl;
}*/
cimg_forXY(pic, x, y) {
pic(x, y) = index[pic(x, y)];
//cout << pic(x, y) << " ";
}
pic.display("处理后图片");
CImg<int> hist1 = pic.histogram(256, 0, 255);
hist1.display_graph("处理后直方图");
运行结果: