本文介绍了图像openCV c ++中的简单照明校正的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些彩色照片,照明不是照片中的规律。



在图像的一边比另一边明亮。
我想通过校正照明来解决这个问题。
我认为局部对比度会帮助我,但我不知道怎么:(
请你帮我用一块代码或管道??

解决方案

RGB图像转换为Lab色彩空间(例如,具有亮度通道的任何色彩空间将正常工作),然后应用的,但扩展了颜色。

  include< opencv2 / core / core.hpp> 
#include< vector> // std :: vector
int main(int argc,char ** argv)
{
//读取RGB彩色图像并将其转换为Lab
cv :: Mat bgr_image = cv :: imread(image.png);
cv :: Mat lab_image;
cv :: cvtColor(bgr_image,lab_image,CV_BGR2Lab);

//提取L通道
std :: vector< cv :: Mat> lab_planes(3);
cv :: split(lab_image,lab_planes); //现在我们在lab_planes [0]中有L图像

//将CLAHE算法应用于L通道
cv :: Ptr< cv :: CLAHE> clahe = cv :: createCLAHE();
clahe-> setClipLimit(4);
cv :: Mat dst;
clahe-> apply(lab_planes [0],dst);

//将颜色平面合并回Lab图像
dst.copyTo(lab_planes [0]);
cv :: merge(lab_planes,lab_image);

//转换回RGB
cv :: Mat image_clahe;
cv :: cvtColor(lab_image,image_clahe,CV_Lab2BGR);

//显示结果(您可能还想在前后查看lab_planes [0])。
cv :: imshow(image original,bgr_image);
cv :: imshow(image CLAHE,image_clahe);
cv :: waitKey();
}


I have some color photos and the illumination is not regular in the photos.

On one side of the image is brighter than the other side.I would like to solve this problem by correcting the illumination.I think local contrast will help me but I don't know how :(would you please help me with a piece of code or with pipeline??

解决方案

Convert the RGB image to Lab color-space (e.g., any color-space with a luminance channel will work fine), then apply adaptive histogram equalization to the L channel. Finally convert the resulting Lab back to RGB.

What you want is OpenCV's CLAHE (Contrast Limited Adaptive Histogram Equalization) algorithm. However, as far as I know it is not documented. There is an example in python. You can read about CLAHE in Graphics Gems IV, pp474-485

Here is an example of CLAHE in action:

And here is the C++ that produced the above image, based on http://answers.opencv.org/question/12024/use-of-clahe/, but extended for color.

#include <opencv2/core/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();
}

这篇关于图像openCV c ++中的简单照明校正的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:25