Main Content

Pad Zeros to Image

This example shows you how to add rows and columns of zeros to an image by using a padding operation.

Example Model

Open the Simulink® model.

modelname = 'ex_blkImagePad.slx';

This model reads an input image using an Image From File block with the File name parameter set to cameraman.tif.

The model pads zeros to all four sides of the input image by using an Image Pad block with these parameters:

  • MethodConstant

  • Pad value sourceSpecify via dialog

  • Pad value0

  • SpecifyPad size

  • Add columns toBoth left and right

  • Number of added columns[10,10]

  • Add rows toBoth top and bottom

  • Number of added rows[10,10]

Simulate the Model

Run the model. The model displays the input image and the zero-padded output image by using a Video Viewer block. The padded zeros create the black border of the output image.