Scale

Source code notebook

Relatively resizing image

using Augmentor
using ImageShow, ImageCore
using Random

In the case that only a single scale factor is specified, the operation will assume that the intention is to scale all dimensions uniformly by that factor.

img_in = testpattern(RGB, ratio=0.5)

mosaicview(
    img_in,
    augment(img_in, Scale(0.8)),
    augment(img_in, Scale(0.8, 1));

    fillvalue=colorant"white", nrow=1, npad=10
)

It is also possible to pass some abstract vector(s) to the constructor, in which case Augmentor will randomly sample one of its elements every time the operation is applied.

Random.seed!(1337)
img_out = [augment(img_in, Scale(0.9:0.05:1.2)) for _ in 1:4]
mosaicview(img_out...; fillvalue=colorant"white", nrow=2)

References

Augmentor.ScaleType
Scale <: Augmentor.AffineOperation

Description

Multiplies the image height and image width by the specified factors. This means that the size of the output image depends on the size of the input image.

The provided factors can either be numbers or vectors of numbers.

  • If numbers are provided, then the operation is deterministic and will always scale the input image with the same factors.

  • In the case vectors are provided, then each time the operation is applied a valid index is sampled and the elements corresponding to that index are used as scaling factors.

The scaling is performed relative to the image center, which can be useful when following the operation with CropNative.

Usage

Scale(factors)

Scale(factors...)

Arguments

  • factors : NTuple or Vararg of Real or AbstractVector that denote the scale factor(s) for each array dimension. If only one variable is specified it is assumed that height and width should be scaled by the same factor(s).

See also

Zoom, Resize, augment

Examples

using Augmentor
img = testpattern()

# half the image size
augment(img, Scale(0.5))

# uniformly scale by a random factor from 1.2, 1.3, or 1.4
augment(img, Scale([1.2, 1.3, 1.4]))

# scale by either 0.5x0.7 or by 0.6x0.8
augment(img, Scale([0.5, 0.6], [0.7, 0.8]))
source

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