Skip to content

Commit

Permalink
colorbalance module added, now it contains the only WHITE_BALANCE_SIM…
Browse files Browse the repository at this point in the history
…PLE implementation
  • Loading branch information
Bellaktris committed Jun 26, 2014
1 parent 62c4145 commit 0fd4823
Show file tree
Hide file tree
Showing 44 changed files with 507 additions and 27 deletions.
3 changes: 1 addition & 2 deletions doc/tutorials/ximpgroc/prediction/prediction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>::type, 1/255.0);
3. **Run main algorithm**
Expand Down
3 changes: 3 additions & 0 deletions modules/colorbalance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions modules/colorbalance/doc/colorbalance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
********************************************
colorbalance. Color balance
********************************************

.. toctree::
:maxdepth: 2

Color balance <colorbalance/whitebalance>
31 changes: 31 additions & 0 deletions modules/colorbalance/doc/colorbalance/whitebalance.rst
Original file line number Diff line number Diff line change
@@ -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`
48 changes: 48 additions & 0 deletions modules/colorbalance/include/opencv2/colorbalance.hpp
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 <opencv2/core.hpp>

/*! \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__
60 changes: 60 additions & 0 deletions modules/colorbalance/samples/simple_color_balance.cpp
Original file line number Diff line number Diff line change
@@ -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<std::string>("i");
std::string outFilename = parser.get<std::string>("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;
}
Loading

0 comments on commit 0fd4823

Please sign in to comment.