How to pad zeros?

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?

 Respuesta aceptada

José-Luis
José-Luis el 5 de Sept. de 2012

0 votos

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)] ];

1 comentario

Andrei Bobrov
Andrei Bobrov el 5 de Sept. de 2012
xout = zeros(size(X)+1);
xout(1:end-1,1:end-1) = X;

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 5 de Sept. de 2012
Editada: Image Analyst el 5 de Sept. de 2012

0 votos

You can use the padarray() function. It's meant for doing exactly this.
paddedArray = padarray(originalArray, [1 1]);

3 comentarios

Sabarinathan Vadivelu
Sabarinathan Vadivelu el 5 de Sept. de 2012
Here I'm getting a size of 1025 X 1025.
Dishant Arora
Dishant Arora el 5 de Sept. de 2012
paddedArray = padarray(originalArray, [1 1],'post');
Image Analyst
Image Analyst el 5 de Sept. de 2012
Sorry - I misread and thought you wanted an extra zero all the way around. Thanks, Dishant, for the correction.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by