I have a binary image of 18x18 pixels and I want to put margins around this image with the purpose of obtaining an image 20x20 pixels.
The image is binary and
The padarray function from the image processing toolbox can be used for this purpose:
B=padarray(A,[1,1])