How to mirror pad a matrix

16 Ansichten (letzte 30 Tage)
Elysi Cochin
Elysi Cochin am 8 Feb. 2021
Bearbeitet: KSSV am 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 Kommentar
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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

Weitere Antworten (1)

KSSV
KSSV am 8 Feb. 2021
Bearbeitet: KSSV am 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

Kategorien

Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by