How to mirror pad a matrix

11 vues (au cours des 30 derniers jours)
Elysi Cochin
Elysi Cochin le 8 Fév 2021
Modifié(e) : KSSV le 8 Fév 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 commentaire
Walter Roberson
Walter Roberson le 8 Fév 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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Fév 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

Plus de réponses (1)

KSSV
KSSV le 8 Fév 2021
Modifié(e) : KSSV le 8 Fév 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

Catégories

En savoir plus sur Modify Image Colors dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by