用零填充 image 到指定的 height 和 width 。
用法
tf.image.pad_to_bounding_box(
image, offset_height, offset_width, target_height, target_width
)参数
-
image形状为[batch, height, width, channels]的 4-D 张量或形状为[height, width, channels]的 3-D 张量。 -
offset_height要在顶部添加的零行数。 -
offset_width要在左侧添加的零列数。 -
target_height输出图像的高度。 -
target_width输出图像的宽度。
返回
-
如果
image是 4-D,则形状为[batch, target_height, target_width, channels]的 4-D 浮点张量 如果image是 3-D,则形状为[target_height, target_width, channels]的 3-D 浮点张量
抛出
-
ValueError如果image的形状与offset_*或target_*参数不兼容,或者offset_height或offset_width为负数。
在顶部添加 offset_height 行零,在左侧添加 offset_width 零列,然后用零填充底部和右侧的图像,直到它具有尺寸 target_height , target_width 。
如果 offset_* 为零并且图像已经具有 target_height 的大小 target_width ,则此操作不执行任何操作。
使用示例:
x = [[[1., 2., 3.],
[4., 5., 6.]],
[[7., 8., 9.],
[10., 11., 12.]]]
padded_image = tf.image.pad_to_bounding_box(x, 1, 1, 4, 4)
padded_image
<tf.Tensor:shape=(4, 4, 3), dtype=float32, numpy=
array([[[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]],
[[ 0., 0., 0.],
[ 1., 2., 3.],
[ 4., 5., 6.],
[ 0., 0., 0.]],
[[ 0., 0., 0.],
[ 7., 8., 9.],
[10., 11., 12.],
[ 0., 0., 0.]],
[[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]]], dtype=float32)>
相关用法
- Python tf.image.psnr用法及代码示例
- Python tf.image.per_image_standardization用法及代码示例
- Python tf.image.random_brightness用法及代码示例
- Python tf.image.adjust_hue用法及代码示例
- Python tf.image.random_contrast用法及代码示例
- Python tf.image.rot90用法及代码示例
- Python tf.image.random_hue用法及代码示例
- Python tf.image.flip_left_right用法及代码示例
- Python tf.image.convert_image_dtype用法及代码示例
- Python tf.image.stateless_random_flip_up_down用法及代码示例
- Python tf.image.random_saturation用法及代码示例
- Python tf.image.extract_glimpse用法及代码示例
- Python tf.image.flip_up_down用法及代码示例
- Python tf.image.crop_to_bounding_box用法及代码示例
- Python tf.image.stateless_random_jpeg_quality用法及代码示例
- Python tf.image.crop_and_resize用法及代码示例
- Python tf.image.stateless_random_hue用法及代码示例
- Python tf.image.rgb_to_yiq用法及代码示例
- Python tf.image.stateless_random_crop用法及代码示例
- Python tf.image.resize_with_crop_or_pad用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.image.pad_to_bounding_box。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
