(image, offset_height, offset_width, target_height,
                         target_width)
return cropped
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:
    image: 4-D Tensor of shape `[batch, height, width, channels]` or
           3-D Tensor of shape `[height, width, channels]`.
    offset_height: Vertical coordinate of the top-left corner of the result in
                   the input.
    offset_width: Horizontal coordinate of the top-left corner of the result in
                  the input.
    target_height: Height of the result.
    target_width: Width of the result.

  Returns:
    If `image` was 4-D, a 4-D float Tensor of shape
    `[batch, target_height, target_width, channels]`
    If `image` was 3-D, a 3-D float Tensor of shape
    `[target_height, target_width, channels]`

  Raises:
    ValueError: If the shape of `image` is incompatible with the `offset_*` or
      `target_*` arguments, or either `offset_height` or `offset_width` is
      negative, or either `target_height` or `target_width` is not positive.
Crops an image to a specified bounding box.
Crops an image to a specified bounding box .
def crop_to_bounding_box(image, offset_height, offset_width, target_height,
                         target_width):
  """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:
    image: 4-D Tensor of shape `[batch, height, width, channels]` or
           3-D Tensor of shape `[height, width, channels]`.
    offset_height: Vertical coordinate of the top-left corner of the result in
                   the input.
    offset_width: Horizontal coordinate of the top-left corner of the result in
                  the input.
    target_height: Height of the result.
    target_width: Width of the result.

  Returns:
    If `image` was 4-D, a 4-D float Tensor of shape
    `[batch, target_height, target_width, channels]`
    If `image` was 3-D, a 3-D float Tensor of shape
    `[target_height, target_width, channels]`

  Raises:
    ValueError: If the shape of `image` is incompatible with the `offset_*` or
      `target_*` arguments, or either `offset_height` or `offset_width` is
      negative, or either `target_height` or `target_width` is not positive.
  """
  image = ops.convert_to_tensor(image, name='image')

  is_batch = True
  image_shape = image.get_shape()
  if image_shape.ndims == 3:
    is_batch = False
    image = array_ops.expand_dims(image, 0)
  elif image_shape.ndims is None:
    is_batch = False
    image = array_ops.expand_dims(image, 0)
    image.set_shape([None] * 4)
  elif image_shape.ndims != 4:
    raise ValueError('\'image\' must have either 3 or 4 dimensions.')

  assert_ops = _CheckAtLeast3DImage(image, require_static=False)

  batch, height, width, depth = _ImageDimensions(image, rank=4)

  assert_ops += _assert(offset_width >= 0, ValueError,
                        'offset_width must be >= 0.')
  assert_ops += _assert(offset_height >= 0, ValueError,
                        'offset_height must be >= 0.')
  assert_ops += _assert(target_width > 0, ValueError,
                        'target_width must be > 0.')
  assert_ops += _assert(target_height > 0, ValueError,
                        'target_height must be > 0.')
  assert_ops += _assert(width >= (target_width + offset_width), ValueError,
                        'width must be >= target + offset.')
  assert_ops += _assert(height >= (target_height + offset_height), ValueError,
                        'height must be >= target + offset.')
  image = control_flow_ops.with_dependencies(assert_ops, image)

  cropped = array_ops.slice(
      image,
      array_ops.stack([0, offset_height, offset_width, 0]),
      array_ops.stack([-1, target_height, target_width, -1]))

  cropped_shape = [None if _is_tensor(i) else i
                   for i in [batch, target_height, target_width, depth]]
  cropped.set_shape(cropped_shape)

  if not is_batch:
    cropped = array_ops.squeeze(cropped, squeeze_dims=[0])

  return cropped
def crop_to_bounding_box ( image , offset_height , offset_width , target_height , target_width ) : image = ops . convert_to_tensor ( image , name = 'image' ) is_batch = True image_shape = image . get_shape ( ) if image_shape . ndims == 3 : is_batch = False image = array_ops . expand_dims ( image , 0 ) elif image_shape . ndims is None : is_batch = False image = array_ops . expand_dims ( image , 0 ) image . set_shape ( [ None ] * 4 ) elif image_shape . ndims != 4 : raise ValueError ( '\'image\' must have either 3 or 4 dimensions.' ) assert_ops = _CheckAtLeast3DImage ( image , require_static = False ) batch , height , width , depth = _ImageDimensions ( image , rank = 4 ) assert_ops += _assert ( offset_width >= 0 , ValueError , 'offset_width must be >= 0.' ) assert_ops += _assert ( offset_height >= 0 , ValueError , 'offset_height must be >= 0.' ) assert_ops += _assert ( target_width > 0 , ValueError , 'target_width must be > 0.' ) assert_ops += _assert ( target_height > 0 , ValueError , 'target_height must be > 0.' ) assert_ops += _assert ( width >= ( target_width + offset_width ) , ValueError , 'width must be >= target + offset.' ) assert_ops += _assert ( height >= ( target_height + offset_height ) , ValueError , 'height must be >= target + offset.' ) image = control_flow_ops . with_dependencies ( assert_ops , image ) cropped = array_ops . slice ( image , array_ops . stack ( [ 0 , offset_height , offset_width , 0 ] ) , array_ops . stack ( [ - 1 , target_height , target_width , - 1 ] ) ) cropped_shape = [ None if _is_tensor ( i ) else i for i in [ batch , target_height , target_width , depth ] ] cropped . set_shape ( cropped_shape ) if not is_batch : cropped = array_ops . squeeze ( cropped , squeeze_dims = [ 0 ] ) return cropped