diff --git a/doc/tutorials/ximpgroc/prediction/prediction.rst b/doc/tutorials/ximpgroc/prediction/prediction.rst index 3cdf3ca0f..d8b57d2a9 100644 --- a/doc/tutorials/ximpgroc/prediction/prediction.rst +++ b/doc/tutorials/ximpgroc/prediction/prediction.rst @@ -111,11 +111,10 @@ Explanation return -1; } -2. **Convert source image to [0;1] range and RGB colospace** +2. **Convert source image to [0;1] range** .. code-block:: cpp - cv::cvtColor(image, image, CV_BGR2RGB); image.convertTo(image, cv::DataType::type, 1/255.0); 3. **Run main algorithm** diff --git a/modules/colorbalance/CMakeLists.txt b/modules/colorbalance/CMakeLists.txt new file mode 100644 index 000000000..5e94b6e8d --- /dev/null +++ b/modules/colorbalance/CMakeLists.txt @@ -0,0 +1,3 @@ +set(the_description "Color balance algorithms") +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) +ocv_define_module(colorbalance opencv_core opencv_imgproc OPTIONAL opencv_highgui) \ No newline at end of file diff --git a/modules/colorbalance/doc/colorbalance.rst b/modules/colorbalance/doc/colorbalance.rst new file mode 100644 index 000000000..0822d17dc --- /dev/null +++ b/modules/colorbalance/doc/colorbalance.rst @@ -0,0 +1,8 @@ +******************************************** +colorbalance. Color balance +******************************************** + +.. toctree:: + :maxdepth: 2 + + Color balance diff --git a/modules/colorbalance/doc/colorbalance/whitebalance.rst b/modules/colorbalance/doc/colorbalance/whitebalance.rst new file mode 100644 index 000000000..efc814268 --- /dev/null +++ b/modules/colorbalance/doc/colorbalance/whitebalance.rst @@ -0,0 +1,31 @@ +Automatic white balance correction +********************************** + +.. highlight:: cpp + +balanceWhite +------------ +.. ocv:function:: (const Mat &src, Mat &dst, const int algorithmType, + const float inputMin = 0.0f, const float inputMax = 255.0f, + const float outputMin = 0.0f, const float outputMax = 255.0f); + +The function implements different algorithm of automatic white balance, i.e. +it tries to map image's white color to perceptual white (this can be violated +due to specific illumination or camera settings). + + :param src : source image + :param dst : destination image + :param algorithmType : type of the algorithm to use. + Use WHITE_BALANCE_SIMPLE to perform + smart histogram adjustments + (ignoring 4% pixels with minimal + and maximal values) for each channel. + :param inputMin : minimum value in the input image + :param inputMax : maximum value in the input image + :param outputMin : minimum value in the output image + :param outputMax : maximum value in the output image + +.. seealso:: + + :ocv:class:`cvtColor`, + :ocv:class:`equalizeHist` \ No newline at end of file diff --git a/modules/colorbalance/include/opencv2/colorbalance.hpp b/modules/colorbalance/include/opencv2/colorbalance.hpp new file mode 100644 index 000000000..c73a2ee2c --- /dev/null +++ b/modules/colorbalance/include/opencv2/colorbalance.hpp @@ -0,0 +1,48 @@ +/*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) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., 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*/ + +#ifndef __OPENCV_EDGEDETECTION_HPP__ +#define __OPENCV_EDGEDETECTION_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/colorbalance/simple_color_balance.hpp" +#endif diff --git a/modules/colorbalance/include/opencv2/colorbalance/simple_color_balance.hpp b/modules/colorbalance/include/opencv2/colorbalance/simple_color_balance.hpp new file mode 100644 index 000000000..e236eee95 --- /dev/null +++ b/modules/colorbalance/include/opencv2/colorbalance/simple_color_balance.hpp @@ -0,0 +1,81 @@ +/*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) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., 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*/ + +#ifndef __OPENCV_SIMPLE_COLOR_BALANCE_HPP__ +#define __OPENCV_SIMPLE_COLOR_BALANCE_HPP__ + +/* +* simple_color_balance.hpp +* +* Created on: Jun 26, 2014 +* Author: Yury Gitman +*/ + +#include + +/*! \namespace cv +Namespace where all the C++ OpenCV functionality resides +*/ +namespace cv +{ + //! various white balance algorithms + enum + { + WHITE_BALANCE_SIMPLE = 0, + WHITE_BALANCE_GRAYWORLD = 1 + }; + + /*! This function implements different white balance algorithms + * \param src : source image + * \param dst : destination image + * \param algorithmType : type of the algorithm to use + * \param inputMin : minimum input value + * \param inputMax : maximum output value + * \param outputMin : minimum input value + * \param outputMax : maximum output value + */ + CV_EXPORTS_W void balanceWhite(const Mat &src, Mat &dst, const int algorithmType, + const float inputMin = 0.0f, const float inputMax = 255.0f, + const float outputMin = 0.0f, const float outputMax = 255.0f); +} + +#endif // __OPENCV_SIMPLE_COLOR_BALANCE_HPP__ \ No newline at end of file diff --git a/modules/colorbalance/samples/simple_color_balance.cpp b/modules/colorbalance/samples/simple_color_balance.cpp new file mode 100644 index 000000000..3755df567 --- /dev/null +++ b/modules/colorbalance/samples/simple_color_balance.cpp @@ -0,0 +1,60 @@ +#include "opencv2/colorbalance.hpp" + +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" + +#include "opencv2/core/utility.hpp" +#include "opencv2/imgproc/types_c.h" + +const char* keys = +{ + "{i || input image name}" + "{o || output image name}" +}; + +int main( int argc, const char** argv ) +{ + bool printHelp = ( argc == 1 ); + printHelp = printHelp || ( argc == 2 && std::string(argv[1]) == "--help" ); + printHelp = printHelp || ( argc == 2 && std::string(argv[1]) == "-h" ); + + if ( printHelp ) + { + printf("\nThis sample demonstrates simple color balance algorithm\n" + "Call:\n" + " simple_color_blance -i=in_image_name [-o=out_image_name]\n\n"); + return 0; + } + + cv::CommandLineParser parser(argc, argv, keys); + if ( !parser.check() ) + { + parser.printErrors(); + return -1; + } + + std::string inFilename = parser.get("i"); + std::string outFilename = parser.get("o"); + + cv::Mat src = cv::imread(inFilename, 1); + if ( src.empty() ) + { + printf("Cannot read image file: %s\n", inFilename.c_str()); + return -1; + } + + cv::Mat res(src.size(), src.type()); + cv::balanceWhite(src, res, cv::WHITE_BALANCE_SIMPLE); + + if ( outFilename == "" ) + { + cv::namedWindow("after white balance", 1); + cv::imshow("after white balance", res); + + cv::waitKey(0); + } + else + cv::imwrite(outFilename, res); + + return 0; +} \ No newline at end of file diff --git a/modules/colorbalance/src/simple_color_balance.cpp b/modules/colorbalance/src/simple_color_balance.cpp new file mode 100644 index 000000000..9bf77cb4d --- /dev/null +++ b/modules/colorbalance/src/simple_color_balance.cpp @@ -0,0 +1,205 @@ +/*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) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// * 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 Intel Corporation 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 +#include +#include +#include + +#include "opencv2/colorbalance.hpp" + +#include "opencv2/imgproc.hpp" + +#include "opencv2/core.hpp" +#include "opencv2/core/core_c.h" + +#include "opencv2/core/types.hpp" +#include "opencv2/core/types_c.h" + +namespace cv +{ + template + void balanceWhite(std::vector < Mat_ > &src, Mat &dst, + const float inputMin, const float inputMax, + const float outputMin, const float outputMax, const int algorithmType) + { + switch ( algorithmType ) + { + case WHITE_BALANCE_SIMPLE: + { + /********************* Simple white balance *********************/ + float s1 = 2.0f; // low quantile + float s2 = 2.0f; // high quantile + + int depth = 2; // depth of histogram tree + if (src[0].depth() != CV_8U) + ++depth; + int bins = 16; // number of bins at each histogram level + + int nElements = int( pow(bins, depth) ); + // number of elements in histogram tree + + for (size_t i = 0; i < src.size(); ++i) + { + std::vector hist(nElements, 0); + + Mat_::iterator beginIt = src[i].begin(); + Mat_::iterator endIt = src[i].end(); + + for (Mat_::iterator it = beginIt; it != endIt; ++it) + // histogram filling + { + int pos = 0; + float minValue = inputMin - 0.5f; + float maxValue = inputMax + 0.5f; + T val = *it; + + float interval = float(maxValue - minValue) / bins; + + for (int j = 0; j < depth; ++j) + { + int currentBin = (val - minValue + 1e-4) / interval; + ++hist[pos + currentBin]; + + pos = (pos + currentBin)*bins; + + minValue = minValue + currentBin*interval; + maxValue = minValue + interval; + + interval /= bins; + } + } + + int total = src[i].total(); + + int p1 = 0, p2 = bins - 1; + int n1 = 0, n2 = total; + + float minValue = inputMin - 0.5f; + float maxValue = inputMax + 0.5f; + + float interval = (maxValue - minValue) / float(bins); + + for (int j = 0; j < depth; ++j) + // searching for s1 and s2 + { + while (n1 + hist[p1] < s1 * total / 100.0f) + { + n1 += hist[p1++]; + minValue += interval; + } + p1 *= bins; + + while (n2 - hist[p2] > (100.0f - s2) * total / 100.0f) + { + n2 -= hist[p2--]; + maxValue -= interval; + } + p2 = p2*bins - 1; + + interval /= bins; + } + + src[i] = (outputMax - outputMin) * (src[i] - minValue) + / (maxValue - minValue) + outputMin; + } + /****************************************************************/ + break; + } + default: + CV_Assert( false ); + } + + dst.create(/**/ src[0].size(), CV_MAKETYPE( src[0].depth(), src.size() ) /**/); + cv::merge(src, dst); + } + + /*! + * Wrappers over different white balance algorithm + * + * \param src : source image (RGB) + * \param dst : destination image + * + * \param inputMin : minimum input value + * \param inputMax : maximum input value + * \param outputMin : minimum output value + * \param outputMax : maximum output value + * + * \param algorithmType : type of the algorithm to use + */ + void balanceWhite(const Mat &src, Mat &dst, const int algorithmType, + const float inputMin, const float inputMax, + const float outputMin, const float outputMax) + { + switch ( src.depth() ) + { + case CV_8U: + { + std::vector < Mat_ > mv; + split(src, mv); + balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); + break; + } + case CV_16S: + { + std::vector < Mat_ > mv; + split(src, mv); + balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); + break; + } + case CV_32S: + { + std::vector < Mat_ > mv; + split(src, mv); + balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); + break; + } + case CV_32F: + { + std::vector < Mat_ > mv; + split(src, mv); + balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); + break; + } + default: + CV_Assert( false ); + break; + } + } +} \ No newline at end of file diff --git a/modules/colorbalance/test/simple_color_balance.cpp b/modules/colorbalance/test/simple_color_balance.cpp new file mode 100644 index 000000000..12732d5f4 --- /dev/null +++ b/modules/colorbalance/test/simple_color_balance.cpp @@ -0,0 +1,29 @@ +#include "test_precomp.hpp" + +namespace cvtest +{ + TEST(colorbalance_SimpleColorBalance, regression) + { + cv::String dir = cvtest::TS::ptr()->get_data_path(); + int nTests = 12; + float threshold = 0.005; + + for (int i = 0; i < nTests; ++i) + { + cv::String srcName = dir + cv::format( "sources/%02d.png", i + 1); + cv::Mat src = cv::imread( srcName, 1 ); + + cv::String previousResultName = dir + cv::format( "results/%02d.png", i + 1 ); + cv::Mat previousResult = cv::imread( previousResultName, 1 ); + + cv::Mat currentResult; + cv::balanceWhite(src, currentResult, cv::WHITE_BALANCE_SIMPLE); + + cv::Mat sqrError = ( currentResult - previousResult ) + .mul( currentResult - previousResult ); + cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( sqrError.total()*sqrError.channels() ); + + EXPECT_LE( mse[0]+mse[1]+mse[2]+mse[3], threshold ); + } + } +} \ No newline at end of file diff --git a/modules/colorbalance/test/test_main.cpp b/modules/colorbalance/test/test_main.cpp new file mode 100644 index 000000000..8b9ad3bca --- /dev/null +++ b/modules/colorbalance/test/test_main.cpp @@ -0,0 +1,3 @@ +#include "test_precomp.hpp" + +CV_TEST_MAIN("colorbalance") diff --git a/modules/colorbalance/test/test_precomp.hpp b/modules/colorbalance/test/test_precomp.hpp new file mode 100644 index 000000000..4f9cc2d71 --- /dev/null +++ b/modules/colorbalance/test/test_precomp.hpp @@ -0,0 +1,20 @@ +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-declarations" +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic ignored "-Wmissing-prototypes" +# pragma GCC diagnostic ignored "-Wextra" +# endif +#endif + +#ifndef __OPENCV_TEST_PRECOMP_HPP__ +#define __OPENCV_TEST_PRECOMP_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/imgproc/types_c.h" +#include "opencv2/highgui.hpp" +#include "opencv2/colorbalance.hpp" +#include "opencv2/ts.hpp" +#include + +#endif diff --git a/modules/colorbalance/testdata/results/01.png b/modules/colorbalance/testdata/results/01.png new file mode 100644 index 000000000..0e35a9875 Binary files /dev/null and b/modules/colorbalance/testdata/results/01.png differ diff --git a/modules/colorbalance/testdata/results/02.png b/modules/colorbalance/testdata/results/02.png new file mode 100644 index 000000000..9bcbf295b Binary files /dev/null and b/modules/colorbalance/testdata/results/02.png differ diff --git a/modules/colorbalance/testdata/results/03.png b/modules/colorbalance/testdata/results/03.png new file mode 100644 index 000000000..c92e59b68 Binary files /dev/null and b/modules/colorbalance/testdata/results/03.png differ diff --git a/modules/colorbalance/testdata/results/04.png b/modules/colorbalance/testdata/results/04.png new file mode 100644 index 000000000..3df7fa933 Binary files /dev/null and b/modules/colorbalance/testdata/results/04.png differ diff --git a/modules/colorbalance/testdata/results/05.png b/modules/colorbalance/testdata/results/05.png new file mode 100644 index 000000000..50c51aac5 Binary files /dev/null and b/modules/colorbalance/testdata/results/05.png differ diff --git a/modules/colorbalance/testdata/results/06.png b/modules/colorbalance/testdata/results/06.png new file mode 100644 index 000000000..130e980a4 Binary files /dev/null and b/modules/colorbalance/testdata/results/06.png differ diff --git a/modules/colorbalance/testdata/results/07.png b/modules/colorbalance/testdata/results/07.png new file mode 100644 index 000000000..256811d36 Binary files /dev/null and b/modules/colorbalance/testdata/results/07.png differ diff --git a/modules/colorbalance/testdata/results/08.png b/modules/colorbalance/testdata/results/08.png new file mode 100644 index 000000000..afa68b0f5 Binary files /dev/null and b/modules/colorbalance/testdata/results/08.png differ diff --git a/modules/colorbalance/testdata/results/09.png b/modules/colorbalance/testdata/results/09.png new file mode 100644 index 000000000..afa68b0f5 Binary files /dev/null and b/modules/colorbalance/testdata/results/09.png differ diff --git a/modules/colorbalance/testdata/results/10.png b/modules/colorbalance/testdata/results/10.png new file mode 100644 index 000000000..7c7378694 Binary files /dev/null and b/modules/colorbalance/testdata/results/10.png differ diff --git a/modules/colorbalance/testdata/results/11.png b/modules/colorbalance/testdata/results/11.png new file mode 100644 index 000000000..99919996f Binary files /dev/null and b/modules/colorbalance/testdata/results/11.png differ diff --git a/modules/colorbalance/testdata/results/12.png b/modules/colorbalance/testdata/results/12.png new file mode 100644 index 000000000..4f80234da Binary files /dev/null and b/modules/colorbalance/testdata/results/12.png differ diff --git a/modules/colorbalance/testdata/results/13.png b/modules/colorbalance/testdata/results/13.png new file mode 100644 index 000000000..6d21a0dd3 Binary files /dev/null and b/modules/colorbalance/testdata/results/13.png differ diff --git a/modules/colorbalance/testdata/results/14.png b/modules/colorbalance/testdata/results/14.png new file mode 100644 index 000000000..4d31aa351 Binary files /dev/null and b/modules/colorbalance/testdata/results/14.png differ diff --git a/modules/colorbalance/testdata/sources/01.png b/modules/colorbalance/testdata/sources/01.png new file mode 100644 index 000000000..d44be3af3 Binary files /dev/null and b/modules/colorbalance/testdata/sources/01.png differ diff --git a/modules/colorbalance/testdata/sources/02.png b/modules/colorbalance/testdata/sources/02.png new file mode 100644 index 000000000..723e2124a Binary files /dev/null and b/modules/colorbalance/testdata/sources/02.png differ diff --git a/modules/colorbalance/testdata/sources/03.png b/modules/colorbalance/testdata/sources/03.png new file mode 100644 index 000000000..eeecf07c0 Binary files /dev/null and b/modules/colorbalance/testdata/sources/03.png differ diff --git a/modules/colorbalance/testdata/sources/04.png b/modules/colorbalance/testdata/sources/04.png new file mode 100644 index 000000000..096a79d6d Binary files /dev/null and b/modules/colorbalance/testdata/sources/04.png differ diff --git a/modules/colorbalance/testdata/sources/05.png b/modules/colorbalance/testdata/sources/05.png new file mode 100644 index 000000000..a23c632c1 Binary files /dev/null and b/modules/colorbalance/testdata/sources/05.png differ diff --git a/modules/colorbalance/testdata/sources/06.png b/modules/colorbalance/testdata/sources/06.png new file mode 100644 index 000000000..3bf87ef31 Binary files /dev/null and b/modules/colorbalance/testdata/sources/06.png differ diff --git a/modules/colorbalance/testdata/sources/07.png b/modules/colorbalance/testdata/sources/07.png new file mode 100644 index 000000000..448a86660 Binary files /dev/null and b/modules/colorbalance/testdata/sources/07.png differ diff --git a/modules/colorbalance/testdata/sources/08.png b/modules/colorbalance/testdata/sources/08.png new file mode 100644 index 000000000..5b4cd8008 Binary files /dev/null and b/modules/colorbalance/testdata/sources/08.png differ diff --git a/modules/colorbalance/testdata/sources/09.png b/modules/colorbalance/testdata/sources/09.png new file mode 100644 index 000000000..5b4cd8008 Binary files /dev/null and b/modules/colorbalance/testdata/sources/09.png differ diff --git a/modules/colorbalance/testdata/sources/10.png b/modules/colorbalance/testdata/sources/10.png new file mode 100644 index 000000000..e9e10baba Binary files /dev/null and b/modules/colorbalance/testdata/sources/10.png differ diff --git a/modules/colorbalance/testdata/sources/11.png b/modules/colorbalance/testdata/sources/11.png new file mode 100644 index 000000000..481059c55 Binary files /dev/null and b/modules/colorbalance/testdata/sources/11.png differ diff --git a/modules/colorbalance/testdata/sources/12.png b/modules/colorbalance/testdata/sources/12.png new file mode 100644 index 000000000..595cdef14 Binary files /dev/null and b/modules/colorbalance/testdata/sources/12.png differ diff --git a/modules/colorbalance/testdata/sources/13.png b/modules/colorbalance/testdata/sources/13.png new file mode 100644 index 000000000..226c7a796 Binary files /dev/null and b/modules/colorbalance/testdata/sources/13.png differ diff --git a/modules/colorbalance/testdata/sources/14.png b/modules/colorbalance/testdata/sources/14.png new file mode 100644 index 000000000..6374d4232 Binary files /dev/null and b/modules/colorbalance/testdata/sources/14.png differ diff --git a/modules/ximpgroc/doc/ximpgroc.rst b/modules/ximpgroc/doc/ximpgroc.rst index 46bbfa537..28e586fc1 100644 --- a/modules/ximpgroc/doc/ximpgroc.rst +++ b/modules/ximpgroc/doc/ximpgroc.rst @@ -5,4 +5,4 @@ ximpgroc. Advanced edge-detection algorithms .. toctree:: :maxdepth: 2 - Structured forests for fast edge detection + Structured forests for fast edge detection diff --git a/modules/ximpgroc/doc/structured_edge_detection/index.rst b/modules/ximpgroc/doc/ximpgroc/structured_edge_detection.rst similarity index 76% rename from modules/ximpgroc/doc/structured_edge_detection/index.rst rename to modules/ximpgroc/doc/ximpgroc/structured_edge_detection.rst index 565b99e61..2600ae276 100644 --- a/modules/ximpgroc/doc/structured_edge_detection/index.rst +++ b/modules/ximpgroc/doc/ximpgroc/structured_edge_detection.rst @@ -3,7 +3,8 @@ Structured forests for fast edge detection .. highlight:: cpp -... +This module contains implementations of modern structured edge detection algorithms, +i.e. algorithms which somehow takes into account pixel affinities in natural images. StructuredEdgeDetection ----------------------- @@ -40,12 +41,12 @@ StructuredEdgeDetection::detectEdges ++++++++++++++++++++++++++++++++++++ .. ocv:function:: void detectEdges(const Mat src, Mat dst) -The function detects edges in src and draw them to dst. The algorithm underlies this function -is much more robust to texture presence, than common approaches, e.g. Sobel + The function detects edges in src and draw them to dst. The algorithm underlies this function + is much more robust to texture presence, than common approaches, e.g. Sobel - :param src : source image (RGB, float, in [0;1]) to detect edges - :param dst : destination image (grayscale, float, in [0;1]) - where edges are drawn + :param src: source image (RGB, float, in [0;1]) to detect edges + :param dst: destination image (grayscale, float, in [0;1]) + where edges are drawn .. seealso:: @@ -56,15 +57,11 @@ createStructuredEdgeDetection +++++++++++++++++++++++++++++ .. ocv:function:: Ptr createStructuredEdgeDetection(String model) -The only available constructor + The only available constructor :param model: model file name -Literature ----------- - .. [Dollar2013] Dollár P., Zitnick C. L., "Structured forests for fast edge detection", IEEE International Conference on Computer Vision (ICCV), 2013, pp. 1841-1848. `DOI `_ - diff --git a/modules/ximpgroc/samples/structured_edge_detection.cpp b/modules/ximpgroc/samples/structured_edge_detection.cpp index 0cae87bef..936bf7813 100644 --- a/modules/ximpgroc/samples/structured_edge_detection.cpp +++ b/modules/ximpgroc/samples/structured_edge_detection.cpp @@ -6,8 +6,6 @@ #include "opencv2/core/utility.hpp" #include "opencv2/imgproc/types_c.h" -#include - const char* keys = { "{i || input image name}" @@ -47,7 +45,6 @@ int main( int argc, const char** argv ) return -1; } - cv::cvtColor(image, image, CV_BGR2RGB); image.convertTo(image, cv::DataType::type, 1/255.0); cv::Mat edges(image.size(), image.type()); diff --git a/modules/ximpgroc/src/structured_edge_detection.cpp b/modules/ximpgroc/src/structured_edge_detection.cpp index 0e19b74e8..9f690bcc6 100644 --- a/modules/ximpgroc/src/structured_edge_detection.cpp +++ b/modules/ximpgroc/src/structured_edge_detection.cpp @@ -88,7 +88,7 @@ static cv::Mat imsmooth(const cv::Mat &src, const int rad) return src; else { - const float p = 12/rad/(rad + 2) - 2; + const float p = 12.0f/rad/(rad + 2) - 2; cv::Mat dst; if (rad <= 1) @@ -98,7 +98,7 @@ static cv::Mat imsmooth(const cv::Mat &src, const int rad) } else { - float nrml = CV_SQR(rad + 1); + float nrml = CV_SQR(rad + 1.0f); std::vector kernelXY(2*rad + 1); for (int i = 0; i <= rad; ++i) @@ -164,7 +164,7 @@ static cv::Mat rgb2luv(const cv::Mat &src) const float xyz[] = {mX[0]*rgb[0] + mX[1]*rgb[1] + mX[2]*rgb[2], mY[0]*rgb[0] + mY[1]*rgb[1] + mY[2]*rgb[2], mZ[0]*rgb[0] + mZ[1]*rgb[1] + mZ[2]*rgb[2]}; - const float nz = 1.0f/(xyz[0] + 15*xyz[1] + 3*xyz[2] + 1e-35); + const float nz = 1.0f / float(xyz[0] + 15*xyz[1] + 3*xyz[2] + 1e-35); const float l = pDst[j] = lTable[cvFloor(1024*xyz[1])]; @@ -217,7 +217,7 @@ static void gradientHist(const cv::Mat &src, cv::Mat &magnitude, cv::Mat &histog for (int j = 0; j < src.cols*nchannels; j += nchannels) { - float fMagn = -1e-5, fdx, fdy; + float fMagn = float(-1e-5), fdx, fdy; for (int k = 0; k < nchannels; ++k) { float cMagn = CV_SQR( pDx[j + k] ) + CV_SQR( pDy[j + k] ); @@ -534,7 +534,7 @@ protected: // half of cell std::vector gridPositions; for(int i = 0; i < gridSize; i++) - gridPositions.push_back( (i+1)*(pSize/shrink + 2*hc - 1)/(gridSize + 1.0) - hc + 0.5 ); + gridPositions.push_back( int( (i+1)*(pSize/shrink + 2*hc - 1)/(gridSize + 1.0) - hc + 0.5f ) ); for (int i = 0, n = 0; i < CV_SQR(gridSize)*nchannels; ++i) for (int j = (i%CV_SQR(gridSize)) + 1; j < CV_SQR(gridSize); ++j, ++n) @@ -623,7 +623,7 @@ protected: } } - cv::reduce( dstM.reshape(1, dstM.total() ), dstM, 2, CV_REDUCE_SUM); + cv::reduce( dstM.reshape(1, int( dstM.total() ) ), dstM, 2, CV_REDUCE_SUM); imsmooth( dstM.reshape(1, dst.rows), 1 ).copyTo(dst); } diff --git a/modules/ximpgroc/test/structured_edge_detection.cpp b/modules/ximpgroc/test/structured_edge_detection.cpp index 3f896f559..cf82fd988 100644 --- a/modules/ximpgroc/test/structured_edge_detection.cpp +++ b/modules/ximpgroc/test/structured_edge_detection.cpp @@ -5,9 +5,9 @@ namespace cvtest TEST(ximpgroc_StructuredEdgeDetection, regression) { - cv::String dir = "C:/Users/Yury/Projects/opencv/sources/opencv_contrib/modules/ximpgroc/testdata/";//cvtest::TS::ptr()->get_data_path(); + cv::String dir = cvtest::TS::ptr()->get_data_path(); int nTests = 12; - float threshold = 0.01; + float threshold = 0.01f; cv::String modelName = dir + "model.yml.gz"; cv::Ptr pDollar = @@ -22,7 +22,6 @@ TEST(ximpgroc_StructuredEdgeDetection, regression) cv::Mat previousResult = cv::imread( previousResultName, 0 ); previousResult.convertTo( previousResult, cv::DataType::type, 1/255.0 ); - cv::cvtColor( src, src, CV_BGR2RGB ); src.convertTo( src, cv::DataType::type, 1/255.0 ); cv::Mat currentResult( src.size(), src.type() ); @@ -30,7 +29,7 @@ TEST(ximpgroc_StructuredEdgeDetection, regression) cv::Mat sqrError = ( currentResult - previousResult ) .mul( currentResult - previousResult ); - cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( sqrError.total() ); + cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( double( sqrError.total() ) ); EXPECT_LE( mse[0], threshold ); }