I have to do image processing. I have one data with 100 x 100 matrix and another with 300 x 300 matrix. I want to add zeros to 100 x100 matrix to equalize it like 300 x300 but zeros to be added after 100 x 100 equally and not in particular end.

 採用された回答

Bruno Luong
Bruno Luong 2020 年 8 月 5 日

0 投票

% Replace this with your image
Image100 = peaks(100)+10;
%Centering padding in 4 sides
PadImage300 = zeros(300,300,size(Image100,3),class(Image100));
PadImage300(101:200,101:200,:) = Image100;
imagesc(PadImage300)

その他の回答 (1 件)

KSSV
KSSV 2020 年 8 月 5 日
編集済み: KSSV 2020 年 8 月 5 日

1 投票

Let A be your 100*100 matrix.
B = zeros(300) ;
B(1:100,1:100) = A ;

3 件のコメント

Anjali Sharma
Anjali Sharma 2020 年 8 月 5 日
Thank you for the answer.
This yield a matrix with zeros added at the end of my data matrix.
Suppose A =
1 2
3 4
I want zeros to be added like this
A =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 2 0 0
0 0 3 4 0 0
0 0 0 0 0 0
0 0 0 0 0 0
equally all aorund. The data should lie in between zeros.
Can you pls suggest anything here.
KSSV
KSSV 2020 年 8 月 5 日
A = rand(2) ;
[m,n] = size(A) ;
B = zeros(3*m,3*n) ;
B((m+1):2*m,(n+1):2*n) = A ;
Also read about padarray
Anjali Sharma
Anjali Sharma 2020 年 8 月 5 日
Yes this worked..!!!
Thank you.
Unfortunately I dont have Image toolbox so cant use padarray otherwise it could be easy.

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

カテゴリ

ヘルプ センター および File Exchange で Images についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by