提交 7ec59fc0 编写于 作者: C Christof Kaufmann

Revert changes of mean and meanStdDev

上级 46a668c5
......@@ -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,
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)
@param src input array that should have from 1 to 4 channels so that the result can be stored in
Scalar_ .
......@@ -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
of array elements independently for each channel and returns it via the
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
mean=stddev=Scalar::all(0).
@note The calculated standard deviation is only the diagonal of the
......
此差异已折叠。
......@@ -1162,7 +1162,7 @@ struct CartToPolarToCartOp : 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;
};
......@@ -1244,7 +1244,7 @@ struct MeanStdDevOp : public BaseElemWiseOp
Scalar sqmeanRef;
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;
context = 7;
......
......@@ -2598,11 +2598,11 @@ void divide(const Mat& src1, const Mat& src2, Mat& dst, double scale)
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 )
{
nz += Scalar_<int>::all((int)total);
nz += (int)total;
total *= 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&
sum[c] += src[i + c];
}
}
else if( mcn == 1 )
else
{
for( size_t i = 0; i < total; i++ )
if( mask[i] )
{
nz++;
for( int c = 0; c < cn; c++ )
{
nz[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)
{
CV_Assert(mask.empty() || (mask.depth() == CV_8U && mask.size == src.size &&
(mask.channels() == 1 || mask.channels() == src.channels())));
CV_Assert(mask.empty() || (mask.type() == CV_8U && mask.size == src.size));
Scalar sum;
Scalar_<int> nz = Scalar_<int>::all(0);
int nz = 0;
const Mat *arrays[]={&src, &mask, 0};
Mat planes[2];
......@@ -2652,7 +2634,7 @@ Scalar mean(const Mat& src, const Mat& mask)
NAryMatIterator it(arrays, planes);
size_t total = planes[0].total();
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 )
{
......@@ -2662,34 +2644,32 @@ Scalar mean(const Mat& src, const Mat& mask)
switch( depth )
{
case CV_8U:
mean_((const uchar*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const uchar*)sptr, mptr, total, cn, sum, nz);
break;
case CV_8S:
mean_((const schar*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const schar*)sptr, mptr, total, cn, sum, nz);
break;
case CV_16U:
mean_((const ushort*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const ushort*)sptr, mptr, total, cn, sum, nz);
break;
case CV_16S:
mean_((const short*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const short*)sptr, mptr, total, cn, sum, nz);
break;
case CV_32S:
mean_((const int*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const int*)sptr, mptr, total, cn, sum, nz);
break;
case CV_32F:
mean_((const float*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const float*)sptr, mptr, total, cn, sum, nz);
break;
case CV_64F:
mean_((const double*)sptr, mptr, total, cn, mcn, sum, nz);
mean_((const double*)sptr, mptr, total, cn, sum, nz);
break;
default:
CV_Error(Error::StsUnsupportedFormat, "");
}
}
for( c = 0; c < cn; c++ )
sum[c] *= (1./std::max(nz[c], 1));
return sum;
return sum * (1./std::max(nz, 1));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册