# Which function should I use to interpolate (boundaries set by fillPolly)

Hello,

I would like to interpolate this picture (not by increasing the resolution).

I filled the areas with fillPoly() by providing the corners of the Polygon and displayed it with via colorMap. But now I would like to “smooth” / Interpolate so that I do not have these strict and hard boundaries anymore.

I was looking for a simple function provided by opencv like reMap or convertMaps. But I am not quite sure wether these functions will work. (I could not get them working).

Do you guys have a hint for what I am looking for? Or do I have to write a function by myself.

Kind regards
Tim

it’s a bit unclear, what you want. maybe , simple blurring like:

`````` cv::blur(img, img, Size(10,10));
``````

no not exactly but thanks for your help

If you imagine a square with clear boundaries (straight line). Instead of this I would like to have soemthing like a circle around this square.

For example I have this 2d Array which represents the image I am plotting.

array =
[
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 3 3 3 3 0 0 0;
0 0 3 3 3 3 0 0 0;
0 0 3 3 3 3 0 0 0;
0 0 3 3 3 3 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
]

Each scalar is another color in my map. This array represents one square (Polygon) filled with the value 3. Around the square there are other squares/Polygons filled with the value 0.
If it is like this, I have clear boundaries (straight lines);

I would like to change the values around this square so there isnt a strict boundary anymore.

Something like that:

array2 =
[
0 0 1 1 1 0 0 0;
0 1 2 2 2 1 0 0;
1 2 3 3 3 3 1 0 0;
1 2 3 3 3 3 2 1 0;
1 2 3 3 3 3 2 1 0;
1 2 3 3 3 3 1 0 0;
1 1 2 2 2 1 00;
0 0 1 1 1 0 0 0;
]

I think I could write a function by myself which is doing exactly this. But I would like to use a function provided by opencv.

hehe, that’s actually, what filters do:

``````Mat ocv = Mat::zeros(10,10,CV_8U);
ocv(Rect(3,3,4,4)) = 3;
cout << ocv << endl;

blur(ocv,ocv,Size(3,3));
cout << ocv << endl;

[  0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   3,   3,   3,   3,   0,   0,   0;
0,   0,   0,   3,   3,   3,   3,   0,   0,   0;
0,   0,   0,   3,   3,   3,   3,   0,   0,   0;
0,   0,   0,   3,   3,   3,   3,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0]

[  0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   1,   1,   1,   1,   0,   0,   0;
0,   0,   1,   1,   2,   2,   1,   1,   0,   0;
0,   0,   1,   2,   3,   3,   2,   1,   0,   0;
0,   0,   1,   2,   3,   3,   2,   1,   0,   0;
0,   0,   1,   1,   2,   2,   1,   1,   0,   0;
0,   0,   0,   1,   1,   1,   1,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
0,   0,   0,   0,   0,   0,   0,   0,   0,   0]
``````

(to get exactly your output above you’d probably have to dilate your square 3 pixels)

(and the blur() is just an example, there are a lot more builtin filters in opencv, you can even use your own kernels)

1 Like