erase¶
- paddle.vision.transforms. erase ( img, i, j, h, w, v, inplace=False ) [source]
-
Erase the pixels of selected area in input image with given value.
- Parameters
-
img (paddle.Tensor | np.array | PIL.Image) – input Tensor image. For Tensor input, the shape should be (C, H, W). For np.array input, the shape should be (H, W, C).
i (int) – y coordinate of the top-left point of erased region.
j (int) – x coordinate of the top-left point of erased region.
h (int) – Height of the erased region.
w (int) – Width of the erased region.
v (paddle.Tensor | np.array) – value used to replace the pixels in erased region. It should be np.array when img is np.array or PIL.Image.
inplace (bool, optional) – Whether this transform is inplace. Default: False.
- Returns
-
Erased image. The type is same with input image.
- Return type
-
paddle.Tensor | np.array | PIL.Image
Examples
>>> import paddle >>> paddle.seed(2023) >>> fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32) >>> print(fake_img) Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, [[[ 0.06132207, 1.11349595, 0.41906244, -0.24858207], [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], [[ 1.66359663, -0.55764782, -0.59911072, -0.57773495], [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], [[ 0.67233968, -1.07747352, 0.80170447, -0.06695852], [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) >>> values = paddle.zeros((1,1,1), dtype=paddle.float32) >>> result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values) >>> print(result) Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, [[[ 0.06132207, 0. , 0. , -0.24858207], [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], [[ 1.66359663, 0. , 0. , -0.57773495], [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], [[ 0.67233968, 0. , 0. , -0.06695852], [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]])