MATLAB: How to mirror pad a matrix

matrix manipulation

How to do mirror padding to the matrix
I = [
1 6 3 3 4 5 1 2
2 5 7 2 2 2 6 2
4 4 6 8 3 5 3 8
5 3 3 4 5 2 2 7
6 5 2 2 7 6 2 4
7 1 4 2 3 5 3 3
2 4 2 4 7 3 3 2
1 2 4 5 6 2 3 1];
mirror_padding = [
1 1 2 4 5 6 2 3 1 1
2 1 6 3 3 4 5 1 2 1
2 2 5 7 2 2 2 6 2 2
8 4 4 6 8 3 5 3 8 4
7 5 3 3 4 5 2 2 7 5
4 6 5 2 2 7 6 2 4 6
3 7 1 4 2 3 5 3 3 7
2 2 4 2 4 7 3 3 2 2
1 1 2 4 5 6 2 3 1 1
1 1 6 3 3 4 5 1 2 1];
When using padarray or imfilter i get different outputs for mirror padded matrix. How to get values as shown in the below image

Best Answer

I = [
1 6 3 3 4 5 1 2
2 5 7 2 2 2 6 2
4 4 6 8 3 5 3 8
5 3 3 4 5 2 2 7
6 5 2 2 7 6 2 4
7 1 4 2 3 5 3 3
2 4 2 4 7 3 3 2
1 2 4 5 6 2 3 1];
mirror_padded = [1, I(end,:), 1; I(:,end), I, I(:,1); 1, I(1,:), 1]
mirror_padded = 10×10
1 1 2 4 5 6 2 3 1 1 2 1 6 3 3 4 5 1 2 1 2 2 5 7 2 2 2 6 2 2 8 4 4 6 8 3 5 3 8 4 7 5 3 3 4 5 2 2 7 5 4 6 5 2 2 7 6 2 4 6 3 7 1 4 2 3 5 3 3 7 2 2 4 2 4 7 3 3 2 2 1 1 2 4 5 6 2 3 1 1 1 1 6 3 3 4 5 1 2 1
Related Question