Rotate image(s) counterclockwise by the passed angle(s) in radians. Args: images: A tensor of shape (num_images, num_rows, num_columns, num_channels) (NHWC), (num_rows, num_columns, num_channels) (HWC), or (num_rows, num_columns) (HW). The rank must be statically known (the
(images, angles, interpolation="NEAREST", name=None)
| 47 | # used by PIL, maybe more readable) mode, which determines the correct |
| 48 | # output_shape and translation for the transform. |
| 49 | def rotate(images, angles, interpolation="NEAREST", name=None): |
| 50 | """Rotate image(s) counterclockwise by the passed angle(s) in radians. |
| 51 | |
| 52 | Args: |
| 53 | images: A tensor of shape (num_images, num_rows, num_columns, num_channels) |
| 54 | (NHWC), (num_rows, num_columns, num_channels) (HWC), or |
| 55 | (num_rows, num_columns) (HW). The rank must be statically known (the |
| 56 | shape is not `TensorShape(None)`. |
| 57 | angles: A scalar angle to rotate all images by, or (if images has rank 4) |
| 58 | a vector of length num_images, with an angle for each image in the batch. |
| 59 | interpolation: Interpolation mode. Supported values: "NEAREST", "BILINEAR". |
| 60 | name: The name of the op. |
| 61 | |
| 62 | Returns: |
| 63 | Image(s) with the same type and shape as `images`, rotated by the given |
| 64 | angle(s). Empty space due to the rotation will be filled with zeros. |
| 65 | |
| 66 | Raises: |
| 67 | TypeError: If `image` is an invalid type. |
| 68 | """ |
| 69 | with ops.name_scope(name, "rotate"): |
| 70 | image_or_images = ops.convert_to_tensor(images) |
| 71 | if image_or_images.dtype.base_dtype not in _IMAGE_DTYPES: |
| 72 | raise TypeError("Invalid dtype %s." % image_or_images.dtype) |
| 73 | elif image_or_images.get_shape().ndims is None: |
| 74 | raise TypeError("image_or_images rank must be statically known") |
| 75 | elif len(image_or_images.get_shape()) == 2: |
| 76 | images = image_or_images[None, :, :, None] |
| 77 | elif len(image_or_images.get_shape()) == 3: |
| 78 | images = image_or_images[None, :, :, :] |
| 79 | elif len(image_or_images.get_shape()) == 4: |
| 80 | images = image_or_images |
| 81 | else: |
| 82 | raise TypeError("Images should have rank between 2 and 4.") |
| 83 | |
| 84 | image_height = math_ops.cast(array_ops.shape(images)[1], |
| 85 | dtypes.float32)[None] |
| 86 | image_width = math_ops.cast(array_ops.shape(images)[2], |
| 87 | dtypes.float32)[None] |
| 88 | output = transform( |
| 89 | images, |
| 90 | angles_to_projective_transforms(angles, image_height, image_width), |
| 91 | interpolation=interpolation) |
| 92 | if image_or_images.get_shape().ndims is None: |
| 93 | raise TypeError("image_or_images rank must be statically known") |
| 94 | elif len(image_or_images.get_shape()) == 2: |
| 95 | return output[0, :, :, 0] |
| 96 | elif len(image_or_images.get_shape()) == 3: |
| 97 | return output[0, :, :, :] |
| 98 | else: |
| 99 | return output |
| 100 | |
| 101 | |
| 102 | def translate(images, translations, interpolation="NEAREST", name=None): |
no test coverage detected