用C++代码实现tif影像的匀光匀色程序
时间: 2024-05-04 22:18:18 浏览: 94
影像自动匀光、匀色(程序)
4星 · 用户满意度95%
以下是一个简单的C++程序,用于对tif影像进行均匀光照和色彩平衡:
```cpp
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
if (argc < 2)
{
cout << "Usage: ./image_balance <filename>" << endl;
return -1;
}
string filename = argv[1];
Mat image = imread(filename, IMREAD_COLOR);
if (image.empty())
{
cout << "Could not open or find the image" << endl;
return -1;
}
Mat gray_image;
cvtColor(image, gray_image, COLOR_BGR2GRAY);
Mat lab_image;
cvtColor(image, lab_image, COLOR_BGR2Lab);
vector<Mat> lab_planes;
split(lab_image, lab_planes);
Ptr<CLAHE> clahe = createCLAHE();
clahe->setClipLimit(4);
Mat dst;
clahe->apply(lab_planes[0], dst);
dst.copyTo(lab_planes[0]);
merge(lab_planes, lab_image);
Mat balanced_image;
cvtColor(lab_image, balanced_image, COLOR_Lab2BGR);
namedWindow("Original Image", WINDOW_NORMAL);
namedWindow("Balanced Image", WINDOW_NORMAL);
imshow("Original Image", image);
imshow("Balanced Image", balanced_image);
waitKey(0);
destroyAllWindows();
return 0;
}
```
该程序使用OpenCV库来加载tif影像,然后将其转换为灰度图像和Lab色彩空间。接下来,它使用对比度有限自适应直方图均衡化(CLAHE)算法来对亮度通道进行均匀化。最后,它将图像转换回BGR色彩空间,并显示原始图像和均衡化后的图像。
阅读全文