| Video and Image Processing Blockset™ | ![]() |
Utilities

The Image Pad block expands or crops the dimensions of a signal by padding or truncating its rows, columns, or both.
| Port | Input/Output | Supported Data Types | Complex Values Supported |
|---|---|---|---|
Image / I | M-by-N matrix of intensity values or an M-by-N-by-P color video signal where P is the number of color planes |
| Yes |
PVal | Scalar value that represents the constant pad value | Same as I port | Yes |
Output | Padded scalar, vector, or matrix | Same as I port | Yes |
The data type of the input signal is the data type of the output signal.
Use the Method parameter to specify how you pad the input signal.
Constant — Pad with a constant value
Replicate — Pad by repeating its border values
Symmetric — Pad with its mirror image
Circular — Pad using a circular repetition of its elements
If you set the Method parameter to Constant, the Pad value source parameter appears on the dialog box.
Input port — The PVal port appears on the block. Use this port to specify the constant value with which to pad your signal
Specify via dialog — The Pad value parameter appears in the dialog box. Enter the constant value with which to pad your signal.
If you set the Specify parameter to Pad size, you can enter the size of the padding in the horizontal and vertical directions.
The Pad rows at parameter controls the padding at the left, right or both sides of the input signal.
Left — The block adds additional columns on the left side.
Right — The block adds additional columns on the right side.
Both left and right — The block adds additional columns to the left and right side.
No padding — The block does not change the number of columns.
Use the Pad size along rows parameter to specify the size of the padding in the horizontal direction. Enter a scalar value, and the block adds this number of columns to the left, right, or both sides of your input signal. If you set the Pad rows at parameter to Both left and right, you can enter a two element vector. The left element controls the number of columns the block adds to the left side of the signal; the right element controls the number of columns the block adds to the right side of the signal.
The Pad columns at parameter controls the padding at the top and bottom of the input signal.
Top — The block adds additional rows to the top.
Bottom — The block adds additional rows to the bottom.
Both top and bottom — The block adds additional rows to the top and bottom.
No padding — The block does not change the number of rows.
Use the Pad size along columns parameter to specify the size of the padding in the vertical direction. Enter a scalar value, and the block adds this number of rows to the top, bottom, or both of your input signal. If you set the Pad columns at parameter to Both top and bottom, you can enter a two element vector. The left element controls the number of rows the block adds to the top of the signal; the right element controls the number of rows the block adds to the bottom of the signal.
If, for the Specify parameter, you select Output size, you can enter the total number of output columns and rows. This setting enables you to pad or truncate the input signal. See the previous section for descriptions of the Pad rows at and Pad columns at parameters. If you are using the Image Pad block to truncate the input signal, these parameters control where the signal is truncated.
If Pad rows at parameter is set to Both left and right, the block splits the padding or truncation evenly. If an even split is not possible, the block adds or removes elements from the end of the rows. The block behaves similarly if the Pad columns at parameter is set to Both top and bottom.
Use the Output row mode parameter to describe how to pad the input signal.
User-specified — Use the Row size parameter to specify the total number of rows.
Next power of two — The block pads the input signal along the rows until the length of the rows is equal to a power of two. When the length of the input signal's rows is equal to a power of two, the block does not pad the input signal's rows.
Use the Output column mode parameter to describe how to pad the input signal.
User-specified — Use the Column size parameter to specify the total number of columns.
Next power of two — The block pads the input signal along the columns until the length of the columns is equal to a power of two. When the length of the input signal's columns is equal to a power of two, the block does not pad the input signal's columns.
The following options are available for the Action when truncation occurs parameter:
None — Select this option when you do not want to be notified that the input signal is truncated.
Warning — Select this option when you want to receive a warning in the MATLAB Command Window when the input signal is truncated.
Error — Select this option when you want an error dialog box displayed and the simulation terminated when the input signal is truncated.
The following four examples demonstrate the four different padding methods:
Example 1 — Demonstrates the block's behavior when the Method parameter is set to Constant.
Example 2— Demonstrates the block's behavior when the Method parameter is set to Replicate.
Example 3— Demonstrates the block's behavior when the Method parameter is set to Symmetric.
Example 4— Demonstrates the block's behavior when the Method parameter is set to Circular.
Suppose you want to pad the rows of your input signal with three initial values equal to 0 and your input signal is defined as follows:

Set the Image Pad block parameters as follows:
Method = Constant
Pad value source = Specify via dialog
Pad value = 0
Specify = Output size
Pad rows at = Left
Output row mode = User-specified
Row size = 6
Pad columns at = No padding
The Image Pad block outputs the following signal:

Suppose you want to pad your input signal with its border values, and your input signal is defined as follows:

Set the Image Pad block parameters as follows:
Method = Replicate
Specify = Pad size
Pad rows at = Both left and right
Pad size along rows = 2
Pad columns at = Both top and bottom
Pad size along columns = [1 3]
The Image Pad block outputs the following signal:

The border values of the input signal are replicated on the top, bottom, left, and right of the input signal so that the output is a 7-by-7 matrix. The values in the corners of this output matrix are determined by replicating the border values of the matrices on the top, bottom, left and right side of the original input signal.
Suppose you want to pad your input signal using its mirror image, and your input signal is defined as follows:

Set the Image Pad block parameters as follows:
Method = Symmetric
Specify = Pad size
Pad rows at = Both left and right
Pad size along rows = [5 6]
Pad columns at = Both top and bottom
Pad size along columns = 2
The Image Pad block outputs the following signal:

The block flips the original input matrix and each matrix it creates about their top, bottom, left, and right sides to populate the 7-by-13 output signal. For example, in the preceding figure, you can see how the block flips the input matrix about its right side to create the matrix directly to its right.
Suppose you want to pad your input signal using a circular repetition of its values. Your input signal is defined as follows:

Set the Image Pad block parameters as follows:
Method = Circular
Specify = Output size
Pad rows at = Both left and right
Output row mode = User-specified
Row size = 9
Pad columns at = Both top and bottom
Output column mode = User-specified
Column size = 9
The Image Pad block outputs the following signal:

The block repeats the values of the input signal in a circular pattern to populate the 9-by-9 output matrix.
The Image Pad dialog box appears as shown in the following figure.

Specify how you want the block to pad your signal.
If you select Input port, the PVal port appears on the block. Use this port to specify the constant value with which to pad your signal. If you select Specify via dialog, the Pad value parameter becomes available. This parameter is visible if, for the Method parameter, you select Constant.
Enter the constant value with which to pad your signal. This parameter is visible if, for the Pad value source parameter, you select Specify via dialog. This parameter is tunable.
If you select Pad size, you can enter the size of the padding in the horizontal and vertical directions. If you select Output size, you can enter the total number of output columns and rows.
Select Left to add additional columns to the left side of the signal. Select Right to add additional columns to the right side of the signal. Select Both left and right to add additional columns to the left and right side of the signal. If you select No padding, the block does not change the number of columns of the input signal.
This parameter controls how many columns are added to the right and/or left side of your input signal. Enter a scalar value, and the block adds this number of columns to the left, right, or both sides of your signal. If, for the Pad rows at parameter you selected Both left and right, enter a two-element vector. The left element controls the number of columns the block adds to the left side of the signal and the right element controls how many columns the block adds to the right side of the signal. This parameter is visible if, for the Specify parameter, you select Pad size.
Describe how to pad the input signal. If you select User-specified, the Row size parameter appears on the block dialog box. If you select Next power of two, the block pads the input signal along the rows until the length of the rows is equal to a power of two. This parameter is visible if, for the Specify parameter, you select Output size.
Enter a scalar value that represents the total number of output columns. This parameter is visible if you set the Output row mode parameter to User-specified.
Select Top to add additional rows at the top of the input signal. Select Bottom to add additional rows at the bottom of the signal. Select Both top and bottom to add additional rows at the top and bottom of the signal. If you select No padding, the block does not change the number of rows of the input signal.
This parameter controls how many rows are added to the top, bottom, or both of your input signal. Enter a scalar value and the block adds this number of columns to the top, bottom, or both of your signal. If, for the Pad columns at parameter you selected Both top and bottom, enter a two-element vector. The left element controls the number of rows the block adds to the top of the signal and the right element controls how many rows the block adds to the bottom of the signal. This parameter is visible if you set the Specify parameter to Pad size.
Describe how to pad the input signal. If you select User-specified, the Column size parameter appears on the block dialog box. If you select Next power of two, the block pads the input signal along the columns until the length of the columns is equal to a power of two. This parameter is visible if, for the Specify parameter, you select Output size.
Enter a scalar value that represents the total number of output columns. This parameter is visible if you set the Output column mode parameter to User-specified.
Choose None when you do not want to be notified that the input signal is truncated. Select Warning to display a warning when the input signal is truncated. Choose Error when you want an error dialog box displayed and the simulation terminated when the input signal is truncated.
![]() | Image From Workspace | Insert Text | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |