Learn R Programming

mmand (version 1.6.3)

sketch: Show an ASCII art representation of a 2D image or matrix

Description

This function prints a rough, text-only representation of an image argument to the R terminal, mapping image intensities to a 10-level pseudo-greyscale. The image is first rescaled to fit into the terminal or other specified width, and downsampled in the row direction to correct for nonsquare character shapes.

Usage

sketch(x, invert = FALSE, width = getOption("width"), squash = 0.5)

Value

This function is called for the side-effect of printing an ASCII representation of its argument.

Arguments

x

An object that can be coerced to a numeric matrix or array. 3D arrays with third dimension no greater than 4 will be taken as multichannel 2D images, and their channels averaged before display. Plain vectors and 1D arrays will be treated as single-row matrices.

invert

By default the mapping uses heavier type for brighter areas. If this option is TRUE, the sense of the scale will be reversed.

width

The width of sketch to draw, in characters.

squash

The factor by which to scale the row direction of the image. Generally this should be markedly less than one, to preserve the aspect ratio of the image, since most fixed-width font characters are taller than they are wide.

Author

Jon Clayden <code@clayden.org>

Details

The result is a compact representation of a matrix that can be used for visualising kernel arrays, sparse matrices and other non-images.

See Also

display

Examples

Run this code
sketch(shapeKernel(c(9,15), type="diamond"))
sketch(shapeKernel(c(9,15), type="diamond"), squash=1)

Run the code above in your browser using DataLab