How to mirror pad a matrix

34 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2021 年 2 月 8 日
編集済み: KSSV 2021 年 2 月 8 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 8 日
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.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 8 日
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

その他の回答 (1 件)

KSSV
KSSV 2021 年 2 月 8 日
編集済み: KSSV 2021 年 2 月 8 日
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

Community Treasure Hunt

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

Start Hunting!

Translated by