knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

A common application of supervised machine learning is identifying the object of an image. One issue that users encounter is a model misclassifying a new image because the object is rotated or translated in some way that was not captured in the training images. The purpose of this package is to create a more robust set of images for users to train their model with. The package will accept an image as an input, apply a series of transformations to it, and return an array of transformed pixel values. Transformations include: rotating, mirroring, and translating (shifting the object's location in the frame).

Functions

Rotate

Rotates an image the user-specified number of times. The image will be rotated to a random degree of roation in the clockwise direction, with the maximum rotation angle specified by the user. The pixel values of the original and rotated images is returned.

Function:

rotate(image_path, num_images, max_rotation)

Arguments:

Output:

Example:

Mirror

Mirrors an image in the horizontal and/or vertical direction and returns the pixel values of the original and mirrored image(s).

Function:

mirror(image_path, direction)

Arguments:

Output:

Example:

Translate

Translate will move an image within its frame, so that the topic of the image will be shifted to a new location in the frame. The distance and direction of translation will be chosen randomly, but the user specifies the maximum distance of the translation and the number of images they want generated. It returns the pixel values of the original and translated images.

Function:

translate(image_path, num_images, max_translation)

Arguments:

Output

Example:

Usage Examples

Perform transformations on the image using the mirror, rotate, and translate functions:

library(AutoTransformR)

# mirror function with horizontal and vertical mirroring
m <- mirror("../tests/testthat/img/milad.jpg")

# rotation with 8 rotated images returned and a maximum rotation of 360 degrees
r <- rotate("../tests/testthat/img/milad.jpg", 8, 360)

# translation with 8 translated images returned and a maximum translation of 60 pixels
t <- translate("../tests/testthat/img/milad.jpg", 5, 60)

OUTPUT:

Use dim() to see the dimensions of the returned array.

dim(m)  # mirror function
dim(r)  # rotate function
dim(t)  # translate function

VIEW TRANSFORMED IMAGES:

To access individual images in the returned array, you must use the last dimension of the array to index to the image in question. The first image in the array is the original, the transformed images follow. Below are examples of how to view the images using the the function imageshow from the package OpenImageR.

Original Image:

library(OpenImageR)

# View original image
imageShow(m[,,,1])

Mirrored Image:

If the direction of mirroring is "all", the array will have the horizontally mirrored image at index 2, and the vertically mirrored image at index 3.

# view horizontal mirroring
imageShow(m[,,,2])

Rotated Image:

# view one of the rotated images
imageShow(r[,,,3])

Translated Image:

# view one of the translated images
imageShow(t[,,,2])


UBC-MDS/AutoTransformR documentation built on May 7, 2019, 7:13 p.m.