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)
| 811 | |
| 812 | @tf_export('image.crop_to_bounding_box') |
| 813 | def 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, |
no test coverage detected