From c73a56235aeae36267302cb4aadf8a94ece5e63e Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Tue, 27 Oct 2015 08:40:02 -0400 Subject: [PATCH] generalized EqualizeHist to 3 channels --- openbr/plugins/imgproc/equalizehist.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/openbr/plugins/imgproc/equalizehist.cpp b/openbr/plugins/imgproc/equalizehist.cpp index 50b4894..9c9d614 100644 --- a/openbr/plugins/imgproc/equalizehist.cpp +++ b/openbr/plugins/imgproc/equalizehist.cpp @@ -18,6 +18,8 @@ #include +using namespace cv; + namespace br { @@ -32,7 +34,20 @@ class EqualizeHistTransform : public UntrainableTransform void project(const Template &src, Template &dst) const { - cv::equalizeHist(src, dst); + if (src.m().channels() == 1) { + equalizeHist(src, dst); + } else if (src.m().channels() == 3) { + // http://stackoverflow.com/questions/15007304/histogram-equalization-not-working-on-color-image-opencv + Mat ycrcb; + cvtColor(src, ycrcb, CV_BGR2YCrCb); + vector channels; + split(ycrcb, channels); + equalizeHist(channels[0], channels[0]); + merge(channels, ycrcb); + cvtColor(ycrcb, dst, CV_YCrCb2BGR); + } else { + qFatal("Invalid channel count!"); + } } }; -- libgit2 0.21.4