nanopyx.core.transform.padding

 1import numpy as np
 2
 3
 4def pad_w_zeros_2d(img, height, width):
 5    """
 6    Generate a 2D padded image with zeros.
 7
 8    Parameters:
 9        img (numpy.ndarray): The input image.
10        height (int): The desired height of the padded image.
11        width (int): The desired width of the padded image.
12
13    Returns:
14        numpy.ndarray: The padded image with zeros.
15    """
16    padded_img = np.zeros((height, width), dtype=img.dtype)
17    img_h, img_w = img.shape
18    padded_img[
19        (height - img_h) // 2 : (height - img_h) // 2 + img_h, (width - img_w) // 2 : (width - img_w) // 2 + img_w
20    ] = img
21
22    return padded_img
def pad_w_zeros_2d(img, height, width):
 5def pad_w_zeros_2d(img, height, width):
 6    """
 7    Generate a 2D padded image with zeros.
 8
 9    Parameters:
10        img (numpy.ndarray): The input image.
11        height (int): The desired height of the padded image.
12        width (int): The desired width of the padded image.
13
14    Returns:
15        numpy.ndarray: The padded image with zeros.
16    """
17    padded_img = np.zeros((height, width), dtype=img.dtype)
18    img_h, img_w = img.shape
19    padded_img[
20        (height - img_h) // 2 : (height - img_h) // 2 + img_h, (width - img_w) // 2 : (width - img_w) // 2 + img_w
21    ] = img
22
23    return padded_img

Generate a 2D padded image with zeros.

Parameters: img (numpy.ndarray): The input image. height (int): The desired height of the padded image. width (int): The desired width of the padded image.

Returns: numpy.ndarray: The padded image with zeros.