MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / crop_to_bounding_box

Function crop_to_bounding_box

tensorflow/python/ops/image_ops_impl.py:813–889  ·  view source on GitHub ↗

Crops an image to a specified bounding box. This op cuts a rectangular part out of `image`. The top-left corner of the returned image is at `offset_height, offset_width` in `image`, and its lower-right corner is at `offset_height + target_height, offset_width + target_width`. Args: i

(image, offset_height, offset_width, target_height,
                         target_width)

Source from the content-addressed store, hash-verified

811
812@tf_export('image.crop_to_bounding_box')
813def crop_to_bounding_box(image, offset_height, offset_width, target_height,
814 target_width):
815 """Crops an image to a specified bounding box.
816
817 This op cuts a rectangular part out of `image`. The top-left corner of the
818 returned image is at `offset_height, offset_width` in `image`, and its
819 lower-right corner is at
820 `offset_height + target_height, offset_width + target_width`.
821
822 Args:
823 image: 4-D Tensor of shape `[batch, height, width, channels]` or 3-D Tensor
824 of shape `[height, width, channels]`.
825 offset_height: Vertical coordinate of the top-left corner of the result in
826 the input.
827 offset_width: Horizontal coordinate of the top-left corner of the result in
828 the input.
829 target_height: Height of the result.
830 target_width: Width of the result.
831
832 Returns:
833 If `image` was 4-D, a 4-D float Tensor of shape
834 `[batch, target_height, target_width, channels]`
835 If `image` was 3-D, a 3-D float Tensor of shape
836 `[target_height, target_width, channels]`
837
838 Raises:
839 ValueError: If the shape of `image` is incompatible with the `offset_*` or
840 `target_*` arguments, or either `offset_height` or `offset_width` is
841 negative, or either `target_height` or `target_width` is not positive.
842 """
843 with ops.name_scope(None, 'crop_to_bounding_box', [image]):
844 image = ops.convert_to_tensor(image, name='image')
845
846 is_batch = True
847 image_shape = image.get_shape()
848 if image_shape.ndims == 3:
849 is_batch = False
850 image = array_ops.expand_dims(image, 0)
851 elif image_shape.ndims is None:
852 is_batch = False
853 image = array_ops.expand_dims(image, 0)
854 image.set_shape([None] * 4)
855 elif image_shape.ndims != 4:
856 raise ValueError('\'image\' must have either 3 or 4 dimensions.')
857
858 assert_ops = _CheckAtLeast3DImage(image, require_static=False)
859
860 batch, height, width, depth = _ImageDimensions(image, rank=4)
861
862 assert_ops += _assert(offset_width >= 0, ValueError,
863 'offset_width must be >= 0.')
864 assert_ops += _assert(offset_height >= 0, ValueError,
865 'offset_height must be >= 0.')
866 assert_ops += _assert(target_width > 0, ValueError,
867 'target_width must be > 0.')
868 assert_ops += _assert(target_height > 0, ValueError,
869 'target_height must be > 0.')
870 assert_ops += _assert(width >= (target_width + offset_width), ValueError,

Callers 1

Calls 10

_CheckAtLeast3DImageFunction · 0.85
_ImageDimensionsFunction · 0.85
_assertFunction · 0.85
sliceMethod · 0.80
_is_tensorFunction · 0.70
name_scopeMethod · 0.45
get_shapeMethod · 0.45
expand_dimsMethod · 0.45
set_shapeMethod · 0.45
stackMethod · 0.45

Tested by

no test coverage detected