How to mirror pad a matrix

9 views (last 30 days)
Elysi Cochin
Elysi Cochin on 8 Feb 2021
Edited: KSSV on 8 Feb 2021
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
  1 Comment
Walter Roberson
Walter Roberson on 8 Feb 2021
How are the diagonal corners chosen? You have set them all to 1, but the mirror of the 2 in the upper right corner should show up as the bottom left corner of the padded image.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Feb 2021
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

More Answers (1)

KSSV
KSSV on 8 Feb 2021
Edited: KSSV on 8 Feb 2021
Let A be your given matrix of size 8*8 and vec be your vector which has to be padded and of size 1*8;
iwant = ones(10) ;
iwant(2:end-1,2:end-1) = A ; % repalce A
iwant(1,2:end-1) = vec ; % top
iwant(2:end-1,end) = vec' ; % right
iwant(end,2:end-1) = fliplr(vec) ; % bottom
iwant(2:end-1,1) = flipud(vec') ; % left

Categories

Find more on Modify Image Colors in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!