Commit f213d65d authored by Bellaktris's avatar Bellaktris

try to fix more errors

parent c26e0c08
...@@ -342,10 +342,10 @@ public: ...@@ -342,10 +342,10 @@ public:
* \param filename : name of the file where the model is stored * \param filename : name of the file where the model is stored
*/ */
StructuredEdgeDetectionImpl(const cv::String &filename, StructuredEdgeDetectionImpl(const cv::String &filename,
const RFFeatureGetter *howToGetFeatures) const RFFeatureGetter *_howToGetFeatures)
: name("StructuredEdgeDetection"), : name("StructuredEdgeDetection"),
howToGetFeatures( howToGetFeatures != NULL howToGetFeatures( _howToGetFeatures != NULL
? howToGetFeatures ? _howToGetFeatures
: createRFFeatureGetter() ) : createRFFeatureGetter() )
{ {
cv::FileStorage modelFile(filename, FileStorage::READ); cv::FileStorage modelFile(filename, FileStorage::READ);
......
...@@ -5,9 +5,7 @@ Automatic white balance correction ...@@ -5,9 +5,7 @@ Automatic white balance correction
balanceWhite balanceWhite
------------ ------------
.. ocv:function:: void balanceWhite(const Mat &src, Mat &dst, const int algorithmType, .. ocv:function:: 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)
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. 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 it tries to map image's white color to perceptual white (this can be violated
...@@ -15,9 +13,7 @@ due to specific illumination or camera settings). ...@@ -15,9 +13,7 @@ due to specific illumination or camera settings).
:param src : source image :param src : source image
:param dst : destination image :param dst : destination image
:param algorithmType : type of the algorithm to use. Use WHITE_BALANCE_SIMPLE to perform :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.
smart histogram adjustments (ignoring 4% pixels with minimal
and maximal values) for each channel.
:param inputMin : minimum value in the input image :param inputMin : minimum value in the input image
:param inputMax : maximum value in the input image :param inputMax : maximum value in the input image
:param outputMin : minimum value in the output image :param outputMin : minimum value in the output image
...@@ -25,5 +21,5 @@ due to specific illumination or camera settings). ...@@ -25,5 +21,5 @@ due to specific illumination or camera settings).
.. seealso:: .. seealso::
:ocv:function:`cvtColor`, :ocv:func:`cvtColor`,
:ocv:function:`equalizeHist` :ocv:func:`equalizeHist`
\ No newline at end of file \ No newline at end of file
...@@ -13,8 +13,8 @@ link: http://www.ipol.im/pub/art/2011/ys-dct/. ...@@ -13,8 +13,8 @@ link: http://www.ipol.im/pub/art/2011/ys-dct/.
:param src : source image :param src : source image
:param dst : destination image :param dst : destination image
:param sigma : expected noise standard deviation :param sigma : expected noise standard deviation
:param psize : size of block side where dct is computed :param psize : size of block side where dct is computed
.. seealso:: .. seealso::
:ocv:function:`fastNLMeansDenoising` :ocv:func:`fastNLMeansDenoising`
\ No newline at end of file \ No newline at end of file
...@@ -134,21 +134,21 @@ namespace cv ...@@ -134,21 +134,21 @@ namespace cv
{ {
CV_Assert( src.type() == CV_MAKE_TYPE(CV_32F, 3) ); CV_Assert( src.type() == CV_MAKE_TYPE(CV_32F, 3) );
Mat m = Mat_<float>(3, 3) << (cvInvSqrt(3), cvInvSqrt(3), cvInvSqrt(3), cv::Matx33f mt(cvInvSqrt(3), cvInvSqrt(3), cvInvSqrt(3),
cvInvSqrt(2), 0.0f, -cvInvSqrt(2), cvInvSqrt(2), 0.0f, -cvInvSqrt(2),
cvInvSqrt(6), -2.0f*cvInvSqrt(6), cvInvSqrt(6)); cvInvSqrt(6), -2.0f*cvInvSqrt(6), cvInvSqrt(6));
cv::transform(src, dst, m); cv::transform(src, dst, mt);
std::vector <Mat> mv; std::vector <Mat> mv;
split(dst, mv); split(dst, mv);
for (int i = 0; i < mv.size(); ++i) for (size_t i = 0; i < mv.size(); ++i)
grayDctDenoising(mv[i], mv[i], sigma, psize); grayDctDenoising(mv[i], mv[i], sigma, psize);
merge(mv, dst); merge(mv, dst);
cv::transform( dst, dst, m.inv() ); cv::transform( dst, dst, mt.inv() );
} }
/*! This function implements simple dct-based image denoising, /*! This function implements simple dct-based image denoising,
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
//M*/ //M*/
#include <vector> #include <vector>
#include <limits>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <iostream> #include <iostream>
......
...@@ -61,92 +61,93 @@ namespace cv ...@@ -61,92 +61,93 @@ namespace cv
{ {
switch ( algorithmType ) switch ( algorithmType )
{ {
case WHITE_BALANCE_SIMPLE: 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 <int> hist(nElements, 0); /********************* 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
typename Mat_<T>::iterator beginIt = src[i].begin(); int nElements = int( pow(bins, depth) );
typename Mat_<T>::iterator endIt = src[i].end(); // number of elements in histogram tree
for (typename Mat_<T>::iterator it = beginIt; it != endIt; ++it) for (size_t i = 0; i < src.size(); ++i)
// histogram filling
{ {
int pos = 0; std::vector <int> hist(nElements, 0);
float minValue = inputMin - 0.5f;
float maxValue = inputMax + 0.5f;
T val = *it;
float interval = float(maxValue - minValue) / bins; typename Mat_<T>::iterator beginIt = src[i].begin();
typename Mat_<T>::iterator endIt = src[i].end();
for (int j = 0; j < depth; ++j) for (typename Mat_<T>::iterator it = beginIt; it != endIt; ++it)
// histogram filling
{ {
int currentBin = (val - minValue + 1e-4) / interval; int pos = 0;
++hist[pos + currentBin]; float minValue = inputMin - 0.5f;
float maxValue = inputMax + 0.5f;
T val = *it;
pos = (pos + currentBin)*bins; float interval = float(maxValue - minValue) / bins;
minValue = minValue + currentBin*interval; for (int j = 0; j < depth; ++j)
maxValue = minValue + interval; {
int currentBin = int( (val - minValue + 1e-4f) / interval );
++hist[pos + currentBin];
interval /= bins; pos = (pos + currentBin)*bins;
minValue = minValue + currentBin*interval;
maxValue = minValue + interval;
interval /= bins;
}
} }
}
int total = src[i].total(); int total = int( src[i].total() );
int p1 = 0, p2 = bins - 1; int p1 = 0, p2 = bins - 1;
int n1 = 0, n2 = total; int n1 = 0, n2 = total;
float minValue = inputMin - 0.5f; float minValue = inputMin - 0.5f;
float maxValue = inputMax + 0.5f; float maxValue = inputMax + 0.5f;
float interval = (maxValue - minValue) / float(bins); float interval = (maxValue - minValue) / float(bins);
for (int j = 0; j < depth; ++j) for (int j = 0; j < depth; ++j)
// searching for s1 and s2 // searching for s1 and s2
{
while (n1 + hist[p1] < s1 * total / 100.0f)
{ {
n1 += hist[p1++]; while (n1 + hist[p1] < s1 * total / 100.0f)
minValue += interval; {
} n1 += hist[p1++];
p1 *= bins; minValue += interval;
}
p1 *= bins;
while (n2 - hist[p2] > (100.0f - s2) * total / 100.0f)
{
n2 -= hist[p2--];
maxValue -= interval;
}
p2 = p2*bins - 1;
while (n2 - hist[p2] > (100.0f - s2) * total / 100.0f) interval /= bins;
{
n2 -= hist[p2--];
maxValue -= interval;
} }
p2 = p2*bins - 1;
interval /= bins; src[i] = (outputMax - outputMin) * (src[i] - minValue)
/ (maxValue - minValue) + outputMin;
} }
/****************************************************************/
src[i] = (outputMax - outputMin) * (src[i] - minValue) break;
/ (maxValue - minValue) + outputMin;
} }
/****************************************************************/ default:
break; CV_Error_( CV_StsNotImplemented,
} ("Unsupported algorithm type (=%d)", algorithmType) );
default:
CV_Assert( false );
} }
dst.create(/**/ src[0].size(), CV_MAKETYPE( src[0].depth(), src.size() ) /**/); dst.create(/**/ src[0].size(), CV_MAKETYPE( src[0].depth(), int( src.size() ) ) /**/);
cv::merge(src, dst); cv::merge(src, dst);
} }
...@@ -169,37 +170,38 @@ namespace cv ...@@ -169,37 +170,38 @@ namespace cv
{ {
switch ( src.depth() ) switch ( src.depth() )
{ {
case CV_8U: case CV_8U:
{ {
std::vector < Mat_<uchar> > mv; std::vector < Mat_<uchar> > mv;
split(src, mv); split(src, mv);
balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType);
break; break;
} }
case CV_16S: case CV_16S:
{ {
std::vector < Mat_<short> > mv; std::vector < Mat_<short> > mv;
split(src, mv); split(src, mv);
balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType);
break; break;
} }
case CV_32S: case CV_32S:
{ {
std::vector < Mat_<int> > mv; std::vector < Mat_<int> > mv;
split(src, mv); split(src, mv);
balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType);
break; break;
} }
case CV_32F: case CV_32F:
{ {
std::vector < Mat_<float> > mv; std::vector < Mat_<float> > mv;
split(src, mv); split(src, mv);
balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType); balanceWhite(mv, dst, inputMin, inputMax, outputMin, outputMax, algorithmType);
break;
}
default:
CV_Error_( CV_StsNotImplemented,
("Unsupported source image format (=%d)", src.type()) );
break; break;
}
default:
CV_Assert( false );
break;
} }
} }
} }
...@@ -7,7 +7,7 @@ namespace cvtest ...@@ -7,7 +7,7 @@ namespace cvtest
cv::String dir = cvtest::TS::ptr()->get_data_path() + "dct_image_denoising/"; cv::String dir = cvtest::TS::ptr()->get_data_path() + "dct_image_denoising/";
int nTests = 1; int nTests = 1;
float psnrThreshold[] = {0.5}; float thresholds[] = {0.1};
int psize[] = {8}; int psize[] = {8};
double sigma[] = {9.0}; double sigma[] = {9.0};
...@@ -26,10 +26,9 @@ namespace cvtest ...@@ -26,10 +26,9 @@ namespace cvtest
cv::Mat sqrError = ( currentResult - previousResult ) cv::Mat sqrError = ( currentResult - previousResult )
.mul( currentResult - previousResult ); .mul( currentResult - previousResult );
cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( sqrError.total()*sqrError.channels() ); cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( double(sqrError.total()*sqrError.channels()) );
double psnr = 10*log10(3*255*255/(mse[0] + mse[1] + mse[2])) - psnr;
EXPECT_GE( psnr, psnrThreshold[i] ); EXPECT_LE( mse[0] + mse[1] + mse[2] + mse[3], thresholds[i] );
} }
} }
} }
\ No newline at end of file
...@@ -6,7 +6,7 @@ namespace cvtest ...@@ -6,7 +6,7 @@ namespace cvtest
{ {
cv::String dir = cvtest::TS::ptr()->get_data_path() + "simple_white_balance/"; cv::String dir = cvtest::TS::ptr()->get_data_path() + "simple_white_balance/";
int nTests = 12; int nTests = 12;
float threshold = 0.005; float threshold = 0.005f;
for (int i = 0; i < nTests; ++i) for (int i = 0; i < nTests; ++i)
{ {
...@@ -21,7 +21,7 @@ namespace cvtest ...@@ -21,7 +21,7 @@ namespace cvtest
cv::Mat sqrError = ( currentResult - previousResult ) cv::Mat sqrError = ( currentResult - previousResult )
.mul( currentResult - previousResult ); .mul( currentResult - previousResult );
cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( sqrError.total()*sqrError.channels() ); cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( double( sqrError.total()*sqrError.channels() ) );
EXPECT_LE( mse[0]+mse[1]+mse[2]+mse[3], threshold ); EXPECT_LE( mse[0]+mse[1]+mse[2]+mse[3], threshold );
} }
......
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