將 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
