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

Function pad_to_bounding_box

tensorflow/python/ops/image_ops_impl.py:730–809  ·  view source on GitHub ↗

Pad `image` with zeros to the specified `height` and `width`. Adds `offset_height` rows of zeros on top, `offset_width` columns of zeros on the left, and then pads the image on the bottom and right with zeros until it has dimensions `target_height`, `target_width`. This op does nothing if

(image, offset_height, offset_width, target_height,
                        target_width)

Source from the content-addressed store, hash-verified

728
729@tf_export('image.pad_to_bounding_box')
730def pad_to_bounding_box(image, offset_height, offset_width, target_height,
731 target_width):
732 """Pad `image` with zeros to the specified `height` and `width`.
733
734 Adds `offset_height` rows of zeros on top, `offset_width` columns of
735 zeros on the left, and then pads the image on the bottom and right
736 with zeros until it has dimensions `target_height`, `target_width`.
737
738 This op does nothing if `offset_*` is zero and the image already has size
739 `target_height` by `target_width`.
740
741 Args:
742 image: 4-D Tensor of shape `[batch, height, width, channels]` or 3-D Tensor
743 of shape `[height, width, channels]`.
744 offset_height: Number of rows of zeros to add on top.
745 offset_width: Number of columns of zeros to add on the left.
746 target_height: Height of output image.
747 target_width: Width of output image.
748
749 Returns:
750 If `image` was 4-D, a 4-D float Tensor of shape
751 `[batch, target_height, target_width, channels]`
752 If `image` was 3-D, a 3-D float Tensor of shape
753 `[target_height, target_width, channels]`
754
755 Raises:
756 ValueError: If the shape of `image` is incompatible with the `offset_*` or
757 `target_*` arguments, or either `offset_height` or `offset_width` is
758 negative.
759 """
760 with ops.name_scope(None, 'pad_to_bounding_box', [image]):
761 image = ops.convert_to_tensor(image, name='image')
762
763 is_batch = True
764 image_shape = image.get_shape()
765 if image_shape.ndims == 3:
766 is_batch = False
767 image = array_ops.expand_dims(image, 0)
768 elif image_shape.ndims is None:
769 is_batch = False
770 image = array_ops.expand_dims(image, 0)
771 image.set_shape([None] * 4)
772 elif image_shape.ndims != 4:
773 raise ValueError('\'image\' must have either 3 or 4 dimensions.')
774
775 assert_ops = _CheckAtLeast3DImage(image, require_static=False)
776 batch, height, width, depth = _ImageDimensions(image, rank=4)
777
778 after_padding_width = target_width - offset_width - width
779
780 after_padding_height = target_height - offset_height - height
781
782 assert_ops += _assert(offset_height >= 0, ValueError,
783 'offset_height must be >= 0')
784 assert_ops += _assert(offset_width >= 0, ValueError,
785 'offset_width must be >= 0')
786 assert_ops += _assert(after_padding_width >= 0, ValueError,
787 'width must be <= target - offset')

Callers 2

Calls 10

_CheckAtLeast3DImageFunction · 0.85
_ImageDimensionsFunction · 0.85
_assertFunction · 0.85
reshapeMethod · 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