我有一些彩色照片,照片中的照明不规则:图像的一侧比另一侧亮。
我想通过校正照明来解决这个问题。 我认为局部对比会对我有所帮助,但我不知道如何:(
你能帮我写一段代码或管道吗?
最佳答案
将 RGB 图像转换为 Lab 颜色空间(例如,任何具有亮度 channel 的颜色空间都可以正常工作),然后应用 adaptive histogram equalization到 L channel 。最后将生成的 Lab 转换回 RGB。
您想要的是 OpenCV 的 CLAHE(对比度受限自适应直方图均衡)算法。但是,据我所知,它没有记录在案。有an example in python .您可以在 Graphics Gems IV, pp474-485 中阅读有关 CLAHE 的信息。
以下是 CLAHE 的示例:
这是生成上述图像的 C++,基于 http://answers.opencv.org/question/12024/use-of-clahe/ ,但扩展到颜色。
#include <opencv2/core.hpp>
#include <vector> // std::vector
int main(int argc, char** argv)
{
// READ RGB color image and convert it to Lab
cv::Mat bgr_image = cv::imread("image.png");
cv::Mat lab_image;
cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab);
// Extract the L channel
std::vector<cv::Mat> lab_planes(3);
cv::split(lab_image, lab_planes); // now we have the L image in lab_planes[0]
// apply the CLAHE algorithm to the L channel
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
clahe->setClipLimit(4);
cv::Mat dst;
clahe->apply(lab_planes[0], dst);
// Merge the the color planes back into an Lab image
dst.copyTo(lab_planes[0]);
cv::merge(lab_planes, lab_image);
// convert back to RGB
cv::Mat image_clahe;
cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);
// display the results (you might also want to see lab_planes[0] before and after).
cv::imshow("image original", bgr_image);
cv::imshow("image CLAHE", image_clahe);
cv::waitKey();
}
关于c++ - 图像中的简单照明校正 OpenCV C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24341114/