/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of the copyright holders may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the Intel Corporation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M*/ #include "precomp.hpp" #include "opencv2/photo.hpp" #include #include #include #include "contrast_preserve.hpp" using namespace std; using namespace cv; void cv::decolor(InputArray _src, OutputArray _dst, OutputArray _color_boost) { CV_INSTRUMENT_REGION(); Mat I = _src.getMat(); _dst.create(I.size(), CV_8UC1); Mat dst = _dst.getMat(); _color_boost.create(I.size(), CV_8UC3); Mat color_boost = _color_boost.getMat(); CV_Assert(!I.empty() && (I.channels()==3)); // Parameter Setting const int maxIter = 15; const double tol = .0001; int iterCount = 0; double E = 0; double pre_E = std::numeric_limits::infinity(); Mat img; I.convertTo(img, CV_32FC3, 1.0/255.0); // Initialization Decolor obj; vector Cg; vector < vector > polyGrad; vector comb; vector alf; obj.grad_system(img,polyGrad,Cg,comb); obj.weak_order(img,alf); // Solver Mat Mt = Mat(int(polyGrad.size()),int(polyGrad[0].size()), CV_32FC1); obj.wei_update_matrix(polyGrad,Cg,Mt); vector wei; obj.wei_inti(comb,wei); //////////////////////////////// main loop starting //////////////////////////////////////// vector G_pos(alf.size()); vector G_neg(alf.size()); vector EXPsum(G_pos.size()); vector EXPterm(G_pos.size()); vector temp(polyGrad[0].size()); vector temp1(polyGrad[0].size()); vector temp2(EXPsum.size()); vector wei1(polyGrad.size()); while(sqrt(pow(E-pre_E,2)) > tol) { iterCount +=1; pre_E = E; for(size_t i=0; i(i,j) * EXPterm[j]); } wei1[i] = val1; } for(size_t i=0; i maxIter) break; } Mat Gray = Mat::zeros(img.size(),CV_32FC1); obj.grayImContruct(wei, img, Gray); Gray.convertTo(dst,CV_8UC1,255); /////////////////////////////////// Contrast Boosting ///////////////////////////////// Mat lab; cvtColor(I,lab,COLOR_BGR2Lab); vector lab_channel; split(lab,lab_channel); dst.copyTo(lab_channel[0]); merge(lab_channel,lab); cvtColor(lab,color_boost,COLOR_Lab2BGR); }