What are these warpPolar artifacts?

I have some small (typically about 60x60 orless) BGR images for which I’m generating polar projections using OpenCV’s warpPolar. Most of the time it works fine, but occasionally I get an image (from that same camera source as the images that worked OK) that has a scattering of artifacts within it. Three different interpolation methods all produce artifacts. I did find that increasing the maxradius eliminates the artifacts for this image, but it adds artifacts for the others! Can anyone help me prevent those artifacts? I’ve noticed that it’s sensitive to the maxRadius parameter. Changing that by a bit can make it better or worse, but it’s unclear as to how to pick a good value. I’ve also tried using the max(image.cols,image.rows), but that does guarantee the results either.

Here is code representative of the call to warpPolar:

Mat m = imread( "image.png", IMREAD_COLOR);
Moments mom = moments( m);
int len = //... semi-major axis*2 for ellipse fit
warpPolar( m, polar, Size(), Point( mom.m10/mom.m00, mom.m01/mom.m00) , len, INTER_LINEAR);

Here is a resulting polar image that has a rainbow of artifacts about a quarter of the way down and an extra band of grayish at the bottom, using NEAREST:
blob_001.png-polar

welcome.

that… looks like a bug to me. corrupted memory, something writing to memory where it shouldn’t. I’m sure this happens regardless of picture content.

do you see this issue when you imshow the output right after calling the function? at this point, does the source image contain any of these defects?

please prepare a “minimal reproducible example” including necessary data.

with what version of OpenCV do you see this issue?

I figured out the answer. The warpPolar call needed an additional flag set to specify how to fill in pixels outside of the source image. This works:

warpPolar( m, polar, Size(), Point( mom.m10/mom.m00, mom.m01/mom.m00) , len, INTER_LINEAR | CV_WARP_FILL_OUTLIERS);
1 Like

oh, so the API doesn’t always initialize the output matrix… that’s surprising behavior.

if you feel like it, I think that’s definitely worth opening an issue, either for a change in behavior or a change in documentation.