将 image 裁剪到指定的边界框。
用法
tf.image.crop_to_bounding_box(
image, offset_height, offset_width, target_height, target_width
)参数
-
image4-DTensor形状[batch, height, width, channels]或 3-DTensor形状[height, width, channels]。 -
offset_heightimage中边界框左上角的垂直坐标。 -
offset_widthimage中边界框左上角的水平坐标。 -
target_height边界框的高度。 -
target_width边界框的宽度。
返回
-
如果
image是 4-D,则形状为[batch, target_height, target_width, channels]的 4-DTensor。如果image是 3-D,则形状为[target_height, target_width, channels]的 3-DTensor。它与image具有相同的 dtype。
抛出
-
ValueErrorimage不是 3-D 或 4-DTensor。 -
ValueErroroffset_width < 0或offset_height < 0。 -
ValueErrortarget_width <= 0或target_width <= 0。 -
ValueErrorwidth < offset_width + target_width或height < offset_height + target_height。
此操作从 image 中切出一个矩形边界框。边界框的左上角位于 image 中的 offset_height, offset_width 处,右下角位于 offset_height + target_height, offset_width + target_width 处。
示例用法:
image = tf.constant(np.arange(1, 28, dtype=np.float32), shape=[3, 3, 3])
image[:,:,0] # print the first channel of the 3-D tensor
<tf.Tensor:shape=(3, 3), dtype=float32, numpy=
array([[ 1., 4., 7.],
[10., 13., 16.],
[19., 22., 25.]], dtype=float32)>
cropped_image = tf.image.crop_to_bounding_box(image, 0, 0, 2, 2)
cropped_image[:,:,0] # print the first channel of the cropped 3-D tensor
<tf.Tensor:shape=(2, 2), dtype=float32, numpy=
array([[ 1., 4.],
[10., 13.]], dtype=float32)>
相关用法
- Python tf.image.crop_and_resize用法及代码示例
- Python tf.image.convert_image_dtype用法及代码示例
- Python tf.image.central_crop用法及代码示例
- Python tf.image.random_brightness用法及代码示例
- Python tf.image.pad_to_bounding_box用法及代码示例
- 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.stateless_random_flip_up_down用法及代码示例
- Python tf.image.random_saturation用法及代码示例
- Python tf.image.extract_glimpse用法及代码示例
- Python tf.image.flip_up_down用法及代码示例
- Python tf.image.stateless_random_jpeg_quality用法及代码示例
- Python tf.image.psnr用法及代码示例
- 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.crop_to_bounding_box。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
