resize( ... , INTER_AREA ) - wrong scaling (Bug #921)
Description
Hi,
when shrinking images with INTER_AREA, the scaling on the y-axis is wrong for some image/factor combinations.
It can easily be reproduced with this image
http://1bsbvthrwzq3cksa.1b.funpic.de/obskur.png
and the following code:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
int boxSize( 10 );
double downScale( 1.0 / static_cast<double>(boxSize) );
Mat img = imread( "obskur.png" );
if ( !img.rows )
return 1;
Mat smallLinear;
Mat smallCubic;
Mat smallArea;
resize( img, smallLinear, Size(), downScale, downScale, INTER_LINEAR );
resize( img, smallCubic, Size(), downScale, downScale, INTER_CUBIC );
resize( img, smallArea, Size(), downScale, downScale, INTER_AREA );
namedWindow( "linear" );
namedWindow( "cubic" );
namedWindow( "area" );
imshow( "linear", smallLinear );
imshow( "cubic", smallCubic );
imshow( "area", smallArea );
waitKey();
destroyWindow( "linear" );
destroyWindow( "cubic" );
destroyWindow( "area" );
return 0;
}
Regards,
Dobias
Associated revisions
fixed the fast branch of INTER_AREA resize (ticket #921)
#921 less signatures for func-s with default arg val-s (aka smart overloads);
moving inpaintTest() to 'photo';
hiding 'Point*' arg in Java signature of Core.checkRange().
Merge pull request #921 from SpecLad:merge-2.4
History
Updated by Vadim Pisarevsky about 14 years ago
In my opinion, the function works fine. What OS and compiler are you using?
Updated by Vadim Pisarevsky about 14 years ago
the result is attached (obskur_area.png)
Updated by Do Bi about 14 years ago
Replying to [comment:1 vp153]:
In my opinion, the function works fine. What OS and compiler are you using?
Interesting. I am using gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) under Ubuntu 10.10 (32 bit) and the stable 2.2 version of OpenCV.
Here is my result:
http://1bsbvthrwzq3cksa.1b.funpic.de/obskurScreenshot.png
I tested this also on Windows 7 with Microsoft Visual C++ 2008 Express and got the same problem.
An interesting effect:
When I change
double downScale( 1.0 / static_cast<double>(boxSize) );
to (for example)
double downScale( 1.00001 / static_cast<double>(boxSize) );
it scales correctly.
Updated by Vadim Pisarevsky about 14 years ago
ok, this is really a bug. I fixed it in r4776.
Indeed, you can avoid the bug by choosing a "fractional" scale factor, i.e. instead of 1/n use 1/n + eps, where eps can be around FLT_EPSILON (but greater than DBL_EPSILON).
- Status changed from Open to Done
- (deleted custom field) set to fixed
Updated by Do Bi about 14 years ago
Replying to [comment:4 vp153]:
ok, this is really a bug. I fixed it in r4776.
Indeed, you can avoid the bug by choosing a "fractional" scale factor, i.e. instead of 1/n use 1/n + eps, where eps can be around FLT_EPSILON (but greater than DBL_EPSILON).
Wow, cool. That was quick. Thanks.