cv::resize of one-dimensional Mat returns wrong results (Bug #1156)


Added by hype blade over 13 years ago. Updated almost 13 years ago.


Status:Cancelled Start date:
Priority:High Due date:
Assignee:Marina Kolpakova % Done:

0%

Category:imgproc, video
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Hi there,
I don't know if it really is a bug but I have a problem when using the
cv::resize function with one-dimensional matrices. I'd like to use linear interpolation to resize a vector (actually stored as a cv::Mat with '1' row and 'n' columns). Here's the example code:

1cv::Mat_<unsigned char> matVector(1,2);
2matVector(0,0) =  0;
3matVector(0,1) =  31;
4
5cv::Mat matVectorResized;
6cv::resize(matVector,matVectorResized,cv::Size(32,1),0,0,cv::INTER_LINEAR);
7
8std::cout<<matVectorResized<<endl;

What I expected was, that I'll get a matrice of 32 colmuns and one row that holds a ramp from '0' to '31', execpt I'm getting this:
matVectorResized = =[0,0,0,0,0,0,0,0,1,3,5,7,9,11,13,15,16,18,20,22,24,26,28,30,31,31,31,31,31,31,31,31]

I don't understand why the linear interpolation won't work on this simple task. Is the cv::resize function only meant for two-dimensional 'images'? Is this simply a problem of correct padding? What do I have to do to correctly resize a one-dimensional matrice?

Regards
Matthias


Associated revisions

Revision cdcb5ed1
Added by Andrey Pavlenko over 11 years ago

Merge pull request #1156 from StevenPuttemans:bugfix_1873_new

History

Updated by Marina Kolpakova almost 13 years ago

  • Description changed from Hi there, I don't know if it really is a bug but I have a problem when us... to Hi there, I don't know if it really is a bug but I have a problem when us... More

Updated by Marina Kolpakova almost 13 years ago

The behavior of cv::resize is fully correct.

To understand the algorithm will give the following simple example:
  • given matrix [0, 32]
  • we need to resize it 16 times (like you but numbers are more convenient)

OpenCV use default for computer vision algorithms pixel to numerical axis mapping: the center of the i-th pixel has coordinate i+0.5
In this example we have with two bounding virtual pixels: [0 ,0 ,32, 32] with coordinates [-0,5, 0.5, 1.5, 2.5].

Now resize all of this using bilinear interpolation technique [[http://en.wikipedia.org/wiki/Bilinear_interpolation]].

Coordinate mapping:
-0.5 -> -8
0.5 -> 8
1.5 -> 24
2.5 -> 40

Resulting array [0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7 , 9 , 11, 13, 15, 17, 19, 21, 23, 25 , 27, 29, 31, 32, 32, 32, 32, 32, 32, 32, 32]

  • Status changed from Open to Cancelled
  • Target version set to 2.4.0
  • Assignee changed from Vadim Pisarevsky to Marina Kolpakova

Also available in: Atom PDF