Bidirectional concatenation using cat (image zero-padding)

1 vue (au cours des 30 derniers jours)
Sordin
Sordin le 17 Avr 2017
Réponse apportée : Jan le 17 Avr 2017
I am trying to zero-pad the borders of an image by a certain amount (xPad, yPad) using the cat function. It takes four lines of code to achieve this. For instance, for the padding in the y direction I have:
[x, y] = size(Image);
padI = cat(2, Image, zeros(x,yPad));
padI = cat(2, zeros(x,yPad),padI);
Is it possible to concatenate in both directions similataneously using a single line of code (i.e., using cat only once)?
Any suggestions are greatly appreciated.

Réponse acceptée

Jan
Jan le 17 Avr 2017
You could write a function for this purpose:
function ImgP = ImagePad(Img, xPad, yPad)
siz = size(Img);
ImgP = zeros(siz + 2 * [XPad, YPad], class(Img));
ImgP(XPad + 1:XPad + siz(1), YPad + 1:YPad + siz(2)) = Img;

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type 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