Skip to content

Commit 6da62f5

Browse files
Add some useful input assertions to PSNR function
Input arrays must be depth CV_8U and of identical size.
1 parent 1caca21 commit 6da62f5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/core/src/stat.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4150,7 +4150,10 @@ double cv::PSNR(InputArray _src1, InputArray _src2)
41504150
{
41514151
CV_INSTRUMENT_REGION()
41524152

4153-
CV_Assert( _src1.depth() == CV_8U );
4153+
//Input arrays must have depth CV_8U and be of identical size
4154+
CV_Assert( _src1.depth() == CV_8U && _src2.depth() == CV_8U );
4155+
CV_Assert( _src1.rows() == _src2.rows() && _src1.cols() == _src2.cols() && _src1.dims() == _src2.dims() );
4156+
41544157
double diff = std::sqrt(norm(_src1, _src2, NORM_L2SQR)/(_src1.total()*_src1.channels()));
41554158
return 20*log10(255./(diff+DBL_EPSILON));
41564159
}

0 commit comments

Comments
 (0)