Commit 444abe82 authored by Bellaktris's avatar Bellaktris

dct image denoising added

parent a200e8ab
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
set(the_description "Addon to basic photo module")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
ocv_define_module(xphoto opencv_core opencv_imgproc OPTIONAL opencv_highgui)
\ No newline at end of file
......@@ -27,5 +27,5 @@ due to specific illumination or camera settings).
.. seealso::
:ocv:class:`cvtColor`,
:ocv:class:`equalizeHist`
\ No newline at end of file
:ocv:function:`cvtColor`,
:ocv:function:`equalizeHist`
\ No newline at end of file
Image denoising techniques
**************************
.. highlight:: cpp
dctDenoising
------------
.. ocv:function:: (const Mat &src, Mat &dst, const float sigma);
The function implements simple dct-based denoising,
link: http://www.ipol.im/pub/art/2011/ys-dct/.
:param src : source image
:param dst : destination image
:param sigma : expected noise standard deviation
:param psize : size of block side where dct is computed
.. seealso::
:ocv:function:`fastNLMeansDenoising`
\ No newline at end of file
********************************************
colorbalance. Color balance
********************************************
**********************************
xphoto. Addon to basic photo modul
**********************************
.. toctree::
:maxdepth: 2
Color balance <colorbalance/whitebalance>
Denoising <denoising/denoising>
......@@ -43,6 +43,7 @@
#ifndef __OPENCV_EDGEDETECTION_HPP__
#define __OPENCV_EDGEDETECTION_HPP__
#include "opencv2/core.hpp"
#include "opencv2/colorbalance/simple_color_balance.hpp"
#include "opencv2/xphoto.hpp"
#include "opencv2/xphoto/simple_color_balance.hpp"
#include "opencv2/xphoto/dct_image_denoising.hpp"
#endif
/*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_DCT_IMAGE_DENOISING_HPP__
#define __OPENCV_DCT_IMAGE_DENOISING_HPP__
/*
* dct_image_denoising.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
{
/*! This function implements simple dct-based image denoising,
* link: http://www.ipol.im/pub/art/2011/ys-dct/
*
* \param src : source image
* \param dst : destination image
* \param sigma : expected noise standard deviation
* \param psize : size of block side where dct is computed
*/
CV_EXPORTS_W void dctDenoising(const Mat &src, Mat &dst, const double sigma, const int psize = 16);
}
#endif // __OPENCV_DCT_IMAGE_DENOISING_HPP__
\ No newline at end of file
#include "opencv2/xphoto.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}"
"{sigma || expected noise standard deviation}"
"{psize |16| expected noise standard deviation}"
};
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 dct-based image denoising\n"
"Call:\n"
" dct_image_denoising -i=<string> -sigma=<double> -psize=<int> [-o=<string>]\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;
}
double sigma = parser.get<double>("sigma");
if (sigma == 0.0)
sigma = 15.0;
int psize = parser.get<int>("psize");
if (psize == 0)
psize = 16;
cv::Mat res(src.size(), src.type());
cv::dctDenoising(src, res, sigma, psize);
if ( outFilename == "" )
{
cv::namedWindow("denoising result", 1);
cv::imshow("denoising result", res);
cv::waitKey(0);
}
else
cv::imwrite(outFilename, res);
return 0;
}
\ No newline at end of file
#include "opencv2/colorbalance.hpp"
#include "opencv2/xphoto.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
......
/*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 <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#include "opencv2/xphoto.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
{
void grayDctDenoising(const Mat_<float> &src, Mat_<float> &dst, const double sigma, const int psize)
{
CV_Assert( src.channels() == 1 );
Mat_<float> res( src.size(), 0.0f ),
num( src.size(), 0.0f );
for (int i = 0; i <= src.rows - psize; ++i)
for (int j = 0; j <= src.cols - psize; ++j)
{
Mat_<float> patch = src( Rect(j, i, psize, psize) ).clone();
dct(patch, patch);
float * ptr = (float *) patch.data;
for (int k = 0; k < psize*psize; ++k)
if (fabs(ptr[k]) < 3.0f*sigma)
ptr[k] = 0.0f;
idct(patch, patch);
res( Rect(j, i, psize, psize) ) += patch;
num( Rect(j, i, psize, psize) ) += Mat_<float>::ones(psize, psize);
}
res /= num;
res.convertTo( dst, src.type() );
}
void rgbDctDenoising(const Mat_<Vec3f> &src, Mat_<Vec3f> &dst, const double sigma, const int psize)
{
CV_Assert( src.channels() == 3 );
float M[] = {cvInvSqrt(3), cvInvSqrt(3), cvInvSqrt(3),
cvInvSqrt(2), 0.0f, -cvInvSqrt(2),
cvInvSqrt(6), -2.0f*cvInvSqrt(6), cvInvSqrt(6)};
Mat_<Vec3f>::iterator outIt = dst.begin();
for (Mat_<Vec3f>::const_iterator it = src.begin(); it != src.end(); ++it, ++outIt)
{
Vec3f rgb = *it;
*outIt = Vec3f(M[0]*rgb[0] + M[3]*rgb[1] + M[6]*rgb[2],
M[1]*rgb[0] + M[4]*rgb[1] + M[7]*rgb[2],
M[2]*rgb[0] + M[5]*rgb[1] + M[8]*rgb[2]);
}
/*************************************/
std::vector < Mat_<float> > mv;
split(dst, mv);
for (int i = 0; i < mv.size(); ++i)
grayDctDenoising(mv[0], mv[0], sigma, psize);
merge(mv, dst);
/*************************************/
for (Mat_<Vec3f>::iterator it = dst.begin(); it != dst.end(); ++it)
{
Vec3f rgb = *it;
*it = Vec3f(M[0]*rgb[0] + M[1]*rgb[1] + M[2]*rgb[2],
M[3]*rgb[0] + M[4]*rgb[1] + M[5]*rgb[2],
M[6]*rgb[0] + M[7]*rgb[1] + M[8]*rgb[2]);
}
}
/*! This function implements simple dct-based image denoising,
* link: http://www.ipol.im/pub/art/2011/ys-dct/
*
* \param src : source image (rgb, or gray)
* \param dst : destination image
* \param sigma : expected noise standard deviation
* \param psize : size of block side where dct is computed
*/
void dctDenoising(const Mat &src, Mat &dst, const double sigma, const int psize)
{
CV_Assert( src.channels() == 3 || src.channels() == 1 );
int xtype = CV_MAKE_TYPE( CV_32F, src.channels() );
Mat img( src.size(), xtype );
src.convertTo(img, xtype);
if ( img.type() == CV_32FC3 )
rgbDctDenoising( Mat_<Vec3f>(img), Mat_<Vec3f>(img), sigma, psize );
else if ( img.type() == CV_32FC1 )
grayDctDenoising( Mat_<float>(img), Mat_<float>(img), sigma, psize );
else
CV_Assert( false );
img.convertTo( dst, src.type() );
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@
#include <iterator>
#include <iostream>
#include "opencv2/colorbalance.hpp"
#include "opencv2/xphoto.hpp"
#include "opencv2/imgproc.hpp"
......@@ -79,10 +79,10 @@ namespace cv
{
std::vector <int> hist(nElements, 0);
Mat_<T>::iterator beginIt = src[i].begin();
Mat_<T>::iterator endIt = src[i].end();
typename Mat_<T>::iterator beginIt = src[i].begin();
typename Mat_<T>::iterator endIt = src[i].end();
for (Mat_<T>::iterator it = beginIt; it != endIt; ++it)
for (typename Mat_<T>::iterator it = beginIt; it != endIt; ++it)
// histogram filling
{
int pos = 0;
......
#include "test_precomp.hpp"
namespace cvtest
{
TEST(xphoto_simplecolorbalance, regression)
{
cv::String dir = cvtest::TS::ptr()->get_data_path() + "dct_image_denoising/";
int nTests = 12;
int psize = 3.0;
float psnrThreshold = 40.0;
float sigma = 15.0;
for (int i = 0; i < nTests; ++i)
{
cv::String srcName = dir + cv::format( "sources/%02d.png", i + 1);
cv::Mat src = cv::imread( srcName );
cv::String previousResultName = dir + cv::format( "results/%02d.png", i + 1 );
cv::Mat previousResult = cv::imread( previousResultName, 1 );
cv::Mat currentResult;
cv::dctDenoising(src, currentResult, sigma, psize);
cv::Mat sqrError = ( currentResult - previousResult )
.mul( currentResult - previousResult );
cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( sqrError.total()*sqrError.channels() );
double psnr = 10*log10(3*255*255/(mse[0] + mse[1] + mse[2]));
EXPECT_GE( psnr, psnrThreshold );
}
}
}
\ No newline at end of file
......@@ -2,9 +2,9 @@
namespace cvtest
{
TEST(colorbalance_SimpleColorBalance, regression)
TEST(xphoto_simplecolorbalance, regression)
{
cv::String dir = cvtest::TS::ptr()->get_data_path();
cv::String dir = cvtest::TS::ptr()->get_data_path() + "simple_white_balance/";
int nTests = 12;
float threshold = 0.005;
......
source-file = C:\Users\Yury\Projects\opencv\sources\opencv_contrib\modules\xphoto\test\simple_color_balance.cpp
new-output-format=yes
exclude-path = *\boost\*
exclude-path = *\zlib\*
exclude-path = *\png\*
exclude-path = *\libpng\*
exclude-path = *\pnglib\*
exclude-path = *\freetype\*
exclude-path = *\ImageMagick\*
exclude-path = *\jpeglib\*
exclude-path = *\libxml\*
exclude-path = *\libxslt\*
exclude-path = *\tifflib\*
exclude-path = *\wxWidgets\*
exclude-path = *\libtiff\*
exclude-path = C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
exclude-path = C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include
exclude-path = C:\Program Files (x86)\Windows Kits\8.0\Include\um
exclude-path = C:\Program Files (x86)\Windows Kits\8.0\Include\shared
exclude-path = C:\Program Files (x86)\Windows Kits\8.0\Include\winrt
exclude-path = C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64
exclude-path = C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\lib\amd64
exclude-path = C:\Program Files (x86)\Windows Kits\8.0\lib\win8\um\x64
openmp-disabled=yes
analysis-mode=0
independent=no
timeout=600
vcprojectdir=C:\Users\Yury\Projects\opencv\build\modules\xphoto
vcinstalldir=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\
platform=x64
cl-params="C:\Users\Yury\Projects\opencv\sources\opencv_contrib\modules\xphoto\test\simple_color_balance.cpp" /D"PVS_STUDIO" /I"C:/Users/Yury/Projects/opencv/sources/opencv_main/modules/highgui/include/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_main/modules/imgproc/include/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_main/modules/core/include/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_main/modules/cudev/include/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_main/modules/ts/include/" /I"C:/Users/Yury/Projects/opencv/build/modules/xphoto/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_main/3rdparty/ippicv/unpack/ippicv_win/include/" /I"C:/Users/Yury/Projects/opencv/build/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_contrib/modules/xphoto/include/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_contrib/modules/xphoto/src/" /I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.5/include/" /I"C:/Users/Yury/Projects/opencv/sources/opencv_contrib/modules/xphoto/test/" /WX- /D"WIN32" /D"_WINDOWS" /D"_CRT_SECURE_NO_DEPRECATE" /D"_CRT_NONSTDC_NO_DEPRECATE" /D"_SCL_SECURE_NO_WARNINGS" /D"NDEBUG" /D"_VARIADIC_MAX=10" /D"__OPENCV_BUILD=1" /D"CMAKE_INTDIR=\"Release\"" /D"_MBCS" /FI"C:/Users/Yury/Projects/opencv/sources/opencv_contrib/modules/xphoto/test/test_precomp.hpp" /Gm- /EHa /MD /GR /Yu"C:/Users/Yury/Projects/opencv/sources/opencv_contrib/modules/xphoto/test/test_precomp.hpp" /TP /fp:precise /I"C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/include/" /I"C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/atlmfc/include/" /I"C:/Program Files (x86)/Windows Kits/8.0/Include/um/" /I"C:/Program Files (x86)/Windows Kits/8.0/Include/shared/" /I"C:/Program Files (x86)/Windows Kits/8.0/Include/winrt/" /I"C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/lib/amd64/" /I"C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/atlmfc/lib/amd64/" /I"C:/Program Files (x86)/Windows Kits/8.0/lib/win8/um/x64/" /nologo /Od /P /c /bigobj /W0
language = C++11
analyzer-db-file= C:\Users\Yury\AppData\Local\Temp\tmp2E30.tmp
stage=inprogress
remove-intermediate-files=yes
preprocessor= visualcpp
#include "test_precomp.hpp"
CV_TEST_MAIN("colorbalance")
CV_TEST_MAIN("xphoto")
......@@ -13,7 +13,7 @@
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/types_c.h"
#include "opencv2/highgui.hpp"
#include "opencv2/colorbalance.hpp"
#include "opencv2/xphoto.hpp"
#include "opencv2/ts.hpp"
#include <iostream>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment