Commit 7ec59fc0 authored by Christof Kaufmann's avatar Christof Kaufmann

Revert changes of mean and meanStdDev

parent 46a668c5
...@@ -608,7 +608,7 @@ CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx ); ...@@ -608,7 +608,7 @@ CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
The function cv::mean calculates the mean value M of array elements, The function cv::mean calculates the mean value M of array elements,
independently for each channel, and return it: independently for each channel, and return it:
\f[\begin{array}{l} N_c = \sum _{I: \; {\texttt{mask} (I)_c} \ne 0} 1 \\ M_c = \left ( \sum _{I: \; {\texttt{mask} (I)_c} \ne 0}{ \texttt{src} (I)_c} \right )/N_c \end{array}\f] \f[\begin{array}{l} N = \sum _{I: \; \texttt{mask} (I) \ne 0} 1 \\ M_c = \left ( \sum _{I: \; \texttt{mask} (I) \ne 0}{ \texttt{mtx} (I)_c} \right )/N \end{array}\f]
When all the mask elements are 0's, the function returns Scalar::all(0) When all the mask elements are 0's, the function returns Scalar::all(0)
@param src input array that should have from 1 to 4 channels so that the result can be stored in @param src input array that should have from 1 to 4 channels so that the result can be stored in
Scalar_ . Scalar_ .
...@@ -622,7 +622,7 @@ CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray()); ...@@ -622,7 +622,7 @@ CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray());
The function cv::meanStdDev calculates the mean and the standard deviation M The function cv::meanStdDev calculates the mean and the standard deviation M
of array elements independently for each channel and returns it via the of array elements independently for each channel and returns it via the
output parameters: output parameters:
\f[\begin{array}{l} N_c = \sum _{I, {\texttt{mask} (I)_c} \ne 0} 1 \\ \texttt{mean} _c = \frac{\sum_{ I: \; {\texttt{mask} (I)_c} \ne 0} \texttt{src} (I)_c}{N_c} \\ \texttt{stddev} _c = \sqrt{\frac{\sum_{ I: \; {\texttt{mask} (I)_c} \ne 0} \left ( \texttt{src} (I)_c - \texttt{mean} _c \right )^2}{N_c}} \end{array}\f] \f[\begin{array}{l} N = \sum _{I, \texttt{mask} (I) \ne 0} 1 \\ \texttt{mean} _c = \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c = \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c - \texttt{mean} _c \right )^2}{N}} \end{array}\f]
When all the mask elements are 0's, the function returns When all the mask elements are 0's, the function returns
mean=stddev=Scalar::all(0). mean=stddev=Scalar::all(0).
@note The calculated standard deviation is only the diagonal of the @note The calculated standard deviation is only the diagonal of the
......
This diff is collapsed.
...@@ -1162,7 +1162,7 @@ struct CartToPolarToCartOp : public BaseElemWiseOp ...@@ -1162,7 +1162,7 @@ struct CartToPolarToCartOp : public BaseElemWiseOp
struct MeanOp : public BaseElemWiseOp struct MeanOp : public BaseElemWiseOp
{ {
MeanOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK+SUPPORT_MULTICHANNELMASK+SCALAR_OUTPUT, 1, 1, Scalar::all(0)) MeanOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK+SCALAR_OUTPUT, 1, 1, Scalar::all(0))
{ {
context = 3; context = 3;
}; };
...@@ -1244,7 +1244,7 @@ struct MeanStdDevOp : public BaseElemWiseOp ...@@ -1244,7 +1244,7 @@ struct MeanStdDevOp : public BaseElemWiseOp
Scalar sqmeanRef; Scalar sqmeanRef;
int cn; int cn;
MeanStdDevOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK+SUPPORT_MULTICHANNELMASK+SCALAR_OUTPUT, 1, 1, Scalar::all(0)) MeanStdDevOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK+SCALAR_OUTPUT, 1, 1, Scalar::all(0))
{ {
cn = 0; cn = 0;
context = 7; context = 7;
......
...@@ -2598,11 +2598,11 @@ void divide(const Mat& src1, const Mat& src2, Mat& dst, double scale) ...@@ -2598,11 +2598,11 @@ void divide(const Mat& src1, const Mat& src2, Mat& dst, double scale)
template<typename _Tp> static void template<typename _Tp> static void
mean_(const _Tp* src, const uchar* mask, size_t total, int cn, int mcn, Scalar& sum, Scalar_<int>& nz) mean_(const _Tp* src, const uchar* mask, size_t total, int cn, Scalar& sum, int& nz)
{ {
if( !mask ) if( !mask )
{ {
nz += Scalar_<int>::all((int)total); nz += (int)total;
total *= cn; total *= cn;
for( size_t i = 0; i < total; i += cn ) for( size_t i = 0; i < total; i += cn )
{ {
...@@ -2610,41 +2610,23 @@ mean_(const _Tp* src, const uchar* mask, size_t total, int cn, int mcn, Scalar& ...@@ -2610,41 +2610,23 @@ mean_(const _Tp* src, const uchar* mask, size_t total, int cn, int mcn, Scalar&
sum[c] += src[i + c]; sum[c] += src[i + c];
} }
} }
else if( mcn == 1 ) else
{ {
for( size_t i = 0; i < total; i++ ) for( size_t i = 0; i < total; i++ )
if( mask[i] ) if( mask[i] )
{ {
nz++;
for( int c = 0; c < cn; c++ ) for( int c = 0; c < cn; c++ )
{
nz[c]++;
sum[c] += src[i*cn + c]; sum[c] += src[i*cn + c];
}
} }
} }
else
{
total *= cn;
for( size_t i = 0; i < total; i += cn )
{
for( int c = 0; c < cn; c++ )
{
if( mask[i + c] )
{
nz[c]++;
sum[c] += src[i + c];
}
}
}
}
} }
Scalar mean(const Mat& src, const Mat& mask) Scalar mean(const Mat& src, const Mat& mask)
{ {
CV_Assert(mask.empty() || (mask.depth() == CV_8U && mask.size == src.size && CV_Assert(mask.empty() || (mask.type() == CV_8U && mask.size == src.size));
(mask.channels() == 1 || mask.channels() == src.channels())));
Scalar sum; Scalar sum;
Scalar_<int> nz = Scalar_<int>::all(0); int nz = 0;
const Mat *arrays[]={&src, &mask, 0}; const Mat *arrays[]={&src, &mask, 0};
Mat planes[2]; Mat planes[2];
...@@ -2652,7 +2634,7 @@ Scalar mean(const Mat& src, const Mat& mask) ...@@ -2652,7 +2634,7 @@ Scalar mean(const Mat& src, const Mat& mask)
NAryMatIterator it(arrays, planes); NAryMatIterator it(arrays, planes);
size_t total = planes[0].total(); size_t total = planes[0].total();
size_t i, nplanes = it.nplanes; size_t i, nplanes = it.nplanes;
int c, depth = src.depth(), cn = src.channels(), mcn = mask.channels(); int depth = src.depth(), cn = src.channels();
for( i = 0; i < nplanes; i++, ++it ) for( i = 0; i < nplanes; i++, ++it )
{ {
...@@ -2662,34 +2644,32 @@ Scalar mean(const Mat& src, const Mat& mask) ...@@ -2662,34 +2644,32 @@ Scalar mean(const Mat& src, const Mat& mask)
switch( depth ) switch( depth )
{ {
case CV_8U: case CV_8U:
mean_((const uchar*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const uchar*)sptr, mptr, total, cn, sum, nz);
break; break;
case CV_8S: case CV_8S:
mean_((const schar*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const schar*)sptr, mptr, total, cn, sum, nz);
break; break;
case CV_16U: case CV_16U:
mean_((const ushort*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const ushort*)sptr, mptr, total, cn, sum, nz);
break; break;
case CV_16S: case CV_16S:
mean_((const short*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const short*)sptr, mptr, total, cn, sum, nz);
break; break;
case CV_32S: case CV_32S:
mean_((const int*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const int*)sptr, mptr, total, cn, sum, nz);
break; break;
case CV_32F: case CV_32F:
mean_((const float*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const float*)sptr, mptr, total, cn, sum, nz);
break; break;
case CV_64F: case CV_64F:
mean_((const double*)sptr, mptr, total, cn, mcn, sum, nz); mean_((const double*)sptr, mptr, total, cn, sum, nz);
break; break;
default: default:
CV_Error(Error::StsUnsupportedFormat, ""); CV_Error(Error::StsUnsupportedFormat, "");
} }
} }
for( c = 0; c < cn; c++ ) return sum * (1./std::max(nz, 1));
sum[c] *= (1./std::max(nz[c], 1));
return sum;
} }
......
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