Repository: opencv
Issue: Faulty interpolation values in cv2.linearPolar
Labels: bug,category: imgproc

### System Information

OpenCV version - 4.7.0
Python version - 3.9.12

### Detailed description

I just so happen to use images of size 127x127 when performing linearPolar-transformation on said images. By letting (0,0) denote the upper left pixel, there are two pixel locations at (0, 126) and (32, 126) that goes bananas in values whenever I try to use **bilinear interpolation**. I have not been able to seed the reproduction of this bug properly. If you try enough times, it will show itself, and is possibly why it went unnoticed for me so long.



Here are some example values, along with the executed line (dimX=127, dimY=127):

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
1.4463031015707752e-307

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.2950010635605724

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.2950010635605724

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.6144859365941906

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.8123130143238755

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.6056811550848846

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.8123130143238755

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
0.8123130143238755

cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2, 1)[32][126]
3.7586523876106726e+233


--------------NOTE---------------

After some frustration, I have partially solved the solution by setting the third argument in the cv2.linearPolar call to dimY // 2, and understood now that bilinear interpolation does not handle outliers at all. I've now understood that you can combine different interpolation techniques by adding them together. 

But I digress.

This has been very damaging for me, taking up a week of my soon-to-be-handed-in Master's thesis. 
Whenever outliers goes bananas like the provided example code shows, it should _at least_ warn the user of what is happening. Now all my deep learning results will have to be rerun again, and it would be nice if the OpenCV-implementation could warned me about this beforehand.

### Steps to reproduce

These lines of Python code will reproduce som very interesting results:

```
import matplotlib.pyplot as plt
import cv2
import numpy as np

dimX = 127
dimY = 127

randomImage = np.random.rand(127, 127)

for _ in range(10):
    plt.figure()
    plt.imshow(cv2.linearPolar(randomImage, (dimX // 2, dimY // 2), dimY / 2 + 10, cv2.INTER_LINEAR), cmap='gray', vmin=0, vmax=1)

```

Here is an image of how it can suddenly look like. The pixel values are clipped, and MUCH higher than 1. Some interpolations have set the pixel at (32, 126) at up to 3.7586523876106726e+233.
![CV2Bug](https://github.com/opencv/opencv/assets/123562638/25cfbaef-c451-4b13-861c-fb87f001480a)


### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [X] I updated to the latest OpenCV version and the issue is still there
- [X] There is reproducer code and related data files (videos, images, onnx, etc)