MATLAB: How to pad zeros

Image Processing Toolboxzero padding

I have an image whose size is 1023*1023. I want to make this image as 1024*1024 by zero padding.
A = zeros (1023,1);
I1 = horzcat (I1,A);
I2 = horzcat (I2,A);
B = zeros (1,1024);
I1 = vertcat (I1,B);
I2 = vertcat (I2,B);
Is this right?

Best Answer

If you want to add a dark edge (that's what the zeros will be), at the bottom and to the right:
load mandrill
[m n] = size(X); %in your case it will be [1023 1023]

X = [ [X;zeros(1,n)] zeros(m+1,1)];
At the top and to the left:
load mandrill
[m n] = size(X); %in your case it will be [1023 1023]
X = [ zeros(m+1,1) [zeros(1,n);X] ];
Plus the two other alternatives, with the same principle:
X = [[zeros(1,n);X] zeros(m+1,1)];
X = [ zeros(m,1) [X;zeros(1,n+1)] ];