Skip to content

Instantly share code, notes, and snippets.

@kashimAstro
Created February 15, 2018 18:32
Show Gist options
  • Save kashimAstro/0d474c807746c0c02c6fcf596707815b to your computer and use it in GitHub Desktop.
Save kashimAstro/0d474c807746c0c02c6fcf596707815b to your computer and use it in GitHub Desktop.
Adaptive histogram equalization opencv
#include <opencv2/core.hpp>
#include <vector>
int main(int argc, char** argv)
{
cv::Mat bgr_image = cv::imread("image.png");
cv::Mat lab_image;
cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab);
// Estrazione L channel
std::vector<cv::Mat> lab_planes(3);
cv::split(lab_image, lab_planes);
// CLAHE algorithm per L channel
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
clahe->setClipLimit(4);
cv::Mat dst;
clahe->apply(lab_planes[0], dst);
// Merge
dst.copyTo(lab_planes[0]);
cv::merge(lab_planes, lab_image);
// RGB
cv::Mat image_clahe;
cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);
// out
cv::imshow("image original", bgr_image);
cv::imshow("image CLAHE", image_clahe);
cv::waitKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment