cv3.transform.pad
- cv3.transform.pad(img, y0, y1, x0, x1, border=0, value=None, rel=None)[source]
Pad image with specified borders.
- Parameters:
img (numpy.ndarray) – Input image.
y0 (int or float) – Padding values for each side.
y1 (int or float) – Padding values for each side.
x0 (int or float) – Padding values for each side.
x1 (int or float) – Padding values for each side.
border (int or str, optional) – Border type. Can be one of: ‘constant’, ‘replicate’, ‘reflect’, ‘wrap’, ‘default’ or OpenCV flags. Defaults to cv2.BORDER_CONSTANT.
value – Border color value for constant border type. Defaults to None.
rel (bool, optional) – Whether to interpret padding values as relative. Defaults to None.
- Returns:
Padded image.
- Return type:
numpy.ndarray
Example
>>> import cv3 >>> import numpy as np >>> # Create a simple image >>> img = np.zeros((100, 100, 3), dtype=np.uint8) >>> img[25:75, 25:75] = [255, 255, 255] # White square >>> # Pad with 10 pixels on each side >>> padded = cv3.pad(img, 10, 10, 10, 10) >>> # Pad with custom border color >>> padded = cv3.pad(img, 10, 10, 10, 10, value=[128, 128, 0])