Commit f213d65d authored by Bellaktris's avatar Bellaktris

try to fix more errors

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