# Revision history [back]

Here my code to understand BORDER_REPLICATE :

void main(void)
{
Mat x = (Mat_<float>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
Mat x7 = (Mat_<float>(7, 7) << 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 0, 0, 1, 1, 2, 3, 3, 0, 0, 4, 4, 5, 6, 6, 0, 0, 7, 7, 8, 9, 9, 0, 0, 7, 7, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0);
Mat kernel = (Mat_<float>(3, 3) << 1, 1, 1, 1, 1, 1, 1, 1, 1);
Mat dst;

filter2D(x, dst, -1, kernel, Point(-1, -1), 0, BORDER_REPLICATE);
cout << "*************BORDER_REPLICATE *******************\n"<<dst << "\n";
cout << "\n data for BORDER_REPLICATE are \n";
cout << x7<<"\n";
cout << "*************Filter2d for x7 *******************\n" << dst << "\n";
filter2D(x7, dst, -1, kernel, Point(-1, -1), 0, BORDER_ISOLATED);
cout << dst << "\n";

}


and results :

*************BORDER_REPLICATE *******************
[21, 27, 33;
39, 45, 51;
57, 63, 69]

data for BORDER_REPLICATE are
[0, 0, 0, 0, 0, 0, 0;
0, 1, 1, 2, 3, 3, 0;
0, 1, 1, 2, 3, 3, 0;
0, 4, 4, 5, 6, 6, 0;
0, 7, 7, 8, 9, 9, 0;
0, 7, 7, 8, 9, 9, 0;
0, 0, 0, 0, 0, 0, 0]
*************Filter2d for x7 *******************
[21, 27, 33;
39, 45, 51;
57, 63, 69]
[1, 2, 4, 6, 8, 6, 3;
2, 4, 8, 12, 16, 12, 6;
6, 12, 21, 27, 33, 24, 12;
12, 24, 39, 45, 51, 36, 18;
18, 36, 57, 63, 69, 48, 24;
14, 28, 44, 48, 52, 36, 18;
7, 14, 22, 24, 26, 18, 9]


Here my code to understand BORDER_REPLICATE :

void main(void)
{
Mat x = (Mat_<float>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
Mat x7 = (Mat_<float>(7, 7) << 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 0, 0, 1, 1, 2, 3, 3, 0, 0, 4, 4, 5, 6, 6, 0, 0, 7, 7, 8, 9, 9, 0, 0, 7, 7, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0);
Mat kernel = (Mat_<float>(3, 3) << 1, 1, 1, 1, 1, 1, 1, 1, 1);
Mat dst;

filter2D(x, dst, -1, kernel, Point(-1, -1), 0, BORDER_REPLICATE);
cout << "*************BORDER_REPLICATE *******************\n"<<dst << "\n";
cout << "\n data for BORDER_REPLICATE are \n";
cout << x7<<"\n";
cout << "*************Filter2d for x7 *******************\n" << dst << "\n";
filter2D(x7, dst, -1, kernel, Point(-1, -1), 0, BORDER_ISOLATED);
BORDER_ISOLATED);// Don't use BORDER_REPLICATE
cout << dst << "\n";

}


and results :

*************BORDER_REPLICATE *******************
[21, 27, 33;
39, 45, 51;
57, 63, 69]

data for BORDER_REPLICATE are
[0, 0, 0, 0, 0, 0, 0;
0, 1, 1, 2, 3, 3, 0;
0, 1, 1, 2, 3, 3, 0;
0, 4, 4, 5, 6, 6, 0;
0, 7, 7, 8, 9, 9, 0;
0, 7, 7, 8, 9, 9, 0;
0, 0, 0, 0, 0, 0, 0]
*************Filter2d for x7 *******************
[21, 27, 33;
39, 45, 51;
57, 63, 69]
[1, 2, 4, 6, 8, 6, 3;
2, 4, 8, 12, 16, 12, 6;
6, 12, 21, 27, 33, 24, 12;
12, 24, 39, 45, 51, 36, 18;
18, 36, 57, 63, 69, 48, 24;
14, 28, 44, 48, 52, 36, 18;
7, 14, 22, 24, 26, 18, 9]