Rotate

Source code notebook

The type Rotate defines a generic anticlockwise rotation operation around the center of the image. It is also possible to pass some abstract vector to the constructor, in which case Augmentor will randomly sample one of its elements every time the operation is applied.

using Augmentor
using ImageShow, ImageCore
using Random
Random.seed!(0)

img_in = testpattern(RGB, ratio=0.5)
mosaicview(
    img_in,

    # deterministic rotation
    augment(img_in, Rotate(45)),

    # random rotation
    augment(img_in, Rotate(-45:45));
    fillvalue=colorant"white", nrow=1, npad=10
)

Note that the output image size will be changed after rotation, CropNative can be particalually useful to preserve the image size.

mosaicview(
    augment(img_in, Rotate(45)),
    augment(img_in, Rotate(45) |> CropNative(axes(img_in)));
    nrow=1, npad=10
)

Rotation by some special degree (e.g.,90, 180 and 270) can be handled more efficiently without interpolation. Compared to Rotate(90), it is recommended to use Rotate90 when possible. Rotate180 and Rotate270 are available, too.

References

Augmentor.RotateType
Rotate <: Augmentor.AffineOperation

Description

Rotate the image upwards for the given degree. This operation can only be performed as an affine transformation and will in general cause other operations of the pipeline to use their affine formulation as well (if they have one).

In contrast to the special case rotations (e.g. Rotate90, the type Rotate can describe any arbitrary number of degrees. It will always perform the rotation around the center of the image. This can be particularly useful when combining the operation with CropNative.

Usage

Rotate(degree)

Arguments

  • degree : Real or AbstractVector of Real that denote the rotation angle(s) in degree. If a vector is provided, then a random element will be sampled each time the operation is applied.

See also

Rotate90, Rotate180, Rotate270, CropNative, augment

Examples

using Augmentor
img = testpattern()

# rotate exactly 45 degree
augment(img, Rotate(45))

# rotate between 10 and 20 degree upwards
augment(img, Rotate(10:20))

# rotate one of the five specified degrees
augment(img, Rotate([-10, -5, 0, 5, 10]))
source
Augmentor.Rotate90Type
Rotate90 <: Augmentor.AffineOperation

Description

Rotates the image upwards 90 degrees. This is a special case rotation because it can be performed very efficiently by simply rearranging the existing pixels. However, it is generally not the case that the output image will have the same size as the input image, which is something to be aware of.

If created using the parameter p, the operation will be lifted into Either(p=>Rotate90(), 1-p=>NoOp()), where p denotes the probability of applying Rotate90 and 1-p the probability for applying NoOp. See the documentation of Either for more information.

Usage

Rotate90()

Rotate90(p)

Arguments

  • p::Number : Optional. Probability of applying the operation. Must be in the interval [0,1].

See also

Rotate180, Rotate270, Rotate, Either, augment

Examples

julia> using Augmentor

julia> img = [200 150; 50 1]
2×2 Matrix{Int64}:
 200  150
  50    1

julia> img_new = augment(img, Rotate90())
2×2 Matrix{Int64}:
 150   1
 200  50
source
Augmentor.Rotate180Type
Rotate180 <: Augmentor.AffineOperation

Description

Rotates the image 180 degrees. This is a special case rotation because it can be performed very efficiently by simply rearranging the existing pixels. Furthermore, the output image will have the same dimensions as the input image.

If created using the parameter p, the operation will be lifted into Either(p=>Rotate180(), 1-p=>NoOp()), where p denotes the probability of applying Rotate180 and 1-p the probability for applying NoOp. See the documentation of Either for more information.

Usage

Rotate180()

Rotate180(p)

Arguments

  • p::Number : Optional. Probability of applying the operation. Must be in the interval [0,1].

See also

Rotate90, Rotate270, Rotate, Either, augment

Examples

julia> using Augmentor

julia> img = [200 150; 50 1]
2×2 Matrix{Int64}:
 200  150
  50    1

julia> img_new = augment(img, Rotate180())
2×2 Matrix{Int64}:
   1   50
 150  200
source
Augmentor.Rotate270Type
Rotate270 <: Augmentor.AffineOperation

Description

Rotates the image upwards 270 degrees, which can also be described as rotating the image downwards 90 degrees. This is a special case rotation, because it can be performed very efficiently by simply rearranging the existing pixels. However, it is generally not the case that the output image will have the same size as the input image, which is something to be aware of.

If created using the parameter p, the operation will be lifted into Either(p=>Rotate270(), 1-p=>NoOp()), where p denotes the probability of applying Rotate270 and 1-p the probability for applying NoOp. See the documentation of Either for more information.

Usage

Rotate270()

Rotate270(p)

Arguments

  • p::Number : Optional. Probability of applying the operation. Must be in the interval [0,1].

See also

Rotate90, Rotate180, Rotate, Either, augment

Examples

julia> using Augmentor

julia> img = [200 150; 50 1]
2×2 Matrix{Int64}:
 200  150
  50    1

julia> img_new = augment(img, Rotate270())
2×2 Matrix{Int64}:
 50  200
  1  150
source

This page was generated using DemoCards.jl and Literate.jl.