|
| 1 | +.. _cn_api_vision_transforms_erase: |
| 2 | + |
| 3 | +erase |
| 4 | +------------------------------- |
| 5 | + |
| 6 | +.. py:function:: paddle.vision.transforms.erase(img, i, j, h, w, v, inplace=False) |
| 7 | +
|
| 8 | +使用给定的值擦除输入图像中的选定区域中的像素。 |
| 9 | + |
| 10 | +参数 |
| 11 | +::::::::: |
| 12 | + |
| 13 | + - img (paddle.Tensor|np.array|PIL.Image) - 输入的图像。对于Tensor类型的输入,形状应该为(C, H, W)。对于np.array类型的输入,形状应该为(H, W, C)。 |
| 14 | + - i (int) - 擦除区域左上角点的纵坐标。 |
| 15 | + - j (int) - 擦除区域左上角点的横坐标。 |
| 16 | + - h (int) - 擦除区域的高。 |
| 17 | + - w (int) - 擦除区域的宽。 |
| 18 | + - v (paddle.Tensor|np.array) - 用于替换擦除区域中像素的值。当输入为np.array或者PIL.Image类型时,需要为np.array类型。 |
| 19 | + - inplace (bool, 可选) - 该变换是否在原地操作。默认值:False。 |
| 20 | + |
| 21 | +返回 |
| 22 | +::::::::: |
| 23 | + |
| 24 | + ``paddle.Tensor`` 或 ``numpy.array`` 或 ``PIL.Image``,擦除后的图像,类型与输入图像的类型一致。 |
| 25 | + |
| 26 | +代码示例 |
| 27 | +::::::::: |
| 28 | + |
| 29 | +.. code-block:: python |
| 30 | +
|
| 31 | + import paddle |
| 32 | +
|
| 33 | + fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32) |
| 34 | + print(fake_img) |
| 35 | +
|
| 36 | + #Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, |
| 37 | + # [[[ 0.02169025, -0.97859967, -1.39175487, -1.07478464], |
| 38 | + # [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], |
| 39 | + # |
| 40 | + # [[-0.14993843, 1.10793507, -0.40056887, -1.94395220], |
| 41 | + # [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], |
| 42 | + # |
| 43 | + # [[-0.24998808, -1.47699273, -0.88838995, 0.42629015], |
| 44 | + # [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) |
| 45 | +
|
| 46 | + values = paddle.zeros((1,1,1), dtype=paddle.float32) |
| 47 | + result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values) |
| 48 | +
|
| 49 | + print(result) |
| 50 | +
|
| 51 | + #Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, |
| 52 | + # [[[ 0.02169025, 0. , 0. , -1.07478464], |
| 53 | + # [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], |
| 54 | + # |
| 55 | + # [[-0.14993843, 0. , 0. , -1.94395220], |
| 56 | + # [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], |
| 57 | + # |
| 58 | + # [[-0.24998808, 0. , 0. , 0.42629015], |
| 59 | + # [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) |
| 60 | +
|
0 commit comments