Interpolation of a 1-dimensional array using OpenCV

I am defining an array of 2 values ​​and trying to use the imgproc module resize function to change it by 10 elements with linear interpolation as an interpolation method.

cv::Mat input = cv::Mat(1, 2, CV_32F); input.at<float>(0, 0) = 0.f; input.at<float>(0, 1) = 1.f; cv::Mat output = cv::Mat(1, 11, CV_32F); cv::resize(input, output, output.size(), 0, 0, cv::INTER_LINEAR); for(int i=0; i<11; ++i) { std::cout<< output.at<float>(0, i) << " "; } 

The result I would expect:

 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 

However, I get the following:

 0 0 0 0.136364 0.318182 0.5 0.681818 0.863636 1 1 1 

Clearly, my understanding of how resizing works is wrong at the fundamental level. Can someone please tell me what I am doing wrong? Admittedly, OpenCV is redundant for such a simple linear interpolation, but please help me with what's wrong here.

+3
source share
1 answer

It is really easy. OpenCV is an image processing library. Therefore, you must remember that we are working on images.

Take a look at the result when we have only 8 pixels in the target image

0 0 0.125 0.375 0.625 0.875 1 1

If you look at this image, it’s very easy to understand the resizing behavior.

Example

As you can see in this link , you use the image conversion library: "The functions in this section perform various geometric transformations of a 2D image"

Do you want to get results

enter image description here

but it will not correctly interpolate the original 2-pixel image

+1
source

Source: https://habr.com/ru/post/1267111/


All Articles