# persp.im

0th

Percentile

##### Perspective Plot of Pixel Image

Displays a perspective plot of a pixel image.

Keywords
hplot, spatial
##### Usage
## S3 method for class 'im':
persp(x, \dots,
colmap=NULL, colin=x, apron=FALSE, visible=FALSE)
##### Arguments
x
The pixel image to be plotted as a surface. An object of class "im" (see im.object).
...
Extra arguments passed to persp.default to control the display.
colmap
Optional data controlling the colour map. See Details.
colin
Optional. Colour input. Another pixel image (of the same dimensions as x) containing the values that will be mapped to colours.
apron
Logical. If TRUE, a grey apron is placed around the sides of the perspective plot.
visible
Logical value indicating whether to compute which pixels of x are visible in the perspective view. See Details.
##### Details

This is the persp method for the class "im".

The pixel image x must have real or integer values. These values are treated as heights of a surface, and the surface is displayed as a perspective plot on the current plot device, using equal scales on the x and y axes.

The optional argument colmap gives an easy way to display different altitudes in different colours (if this is what you want).

• Ifcolmapis a colour map (object of class"colourmap", created by the functioncolourmap) then this colour map will be used to associate altitudes with colours.
• Ifcolmapis a character vector, then the range of altitudes in the perspective plot will be divided intolength(colmap)intervals, and those parts of the surface which lie in a particular altitude range will be assigned the corresponding colour fromcolmap.
• Ifcolmapis a function in theRlanguage of the formfunction(n, ...), this function will be called with an appropriate value ofnto generate a character vector ofncolours. Examples of such functions areheat.colors,terrain.colors,topo.colorsandcm.colors.
• Ifcolmapis a function in theRlanguage of the formfunction(range, ...)then it will be called withrangeequal to the range of altitudes, to determine the colour values or colour map. Examples of such functions arebeachcoloursandbeachcolourmap.
• Ifcolmapis a list with entriesbreaksandcol, thencolmap$breaksdetermines the breakpoints of the altitude intervals, andcolmap$colprovides the corresponding colours.
Alternatively, if the argument colin (colour input) is present, then the colour map colmap will be applied to the pixel values of colin instead of the pixel values of x. The result is a perspective view of a surface with heights determined by x and colours determined by colin (mapped by colmap). If apron=TRUE, vertical surface is drawn around the boundary of the perspective plot, so that the terrain appears to have been cut out of a solid material. If colour data were supplied, then the apron is coloured light grey.

Graphical parameters controlling the perspective plot are passed through the ... arguments directly to the function persp.default. See the examples in persp.default or in demo(persp).

The vertical scale is controlled by the argument expand: setting expand=1 will interpret the pixel values as being in the same units as the spatial coordinates $x$ and $y$ and represent them at the same scale.

If visible=TRUE, the algorithm also computes whether each pixel in x is visible in the perspective view. In order to be visible, a pixel must not be obscured by another pixel which lies in front of it (as seen from the viewing direction), and the three-dimensional vector normal to the surface must be pointing toward the viewer. The return value of persp.im then has an attribute "visible" which is a pixel image, compatible with x, with pixel value equal to TRUE if the corresponding pixel in x is visible, and FALSE if it is not visible.

##### Value

• (invisibly) the 3D transformation matrix returned by persp.default, together with an attribute "expand" which gives the relative scale of the $z$ coordinate.

If argument visible=TRUE was given, the return value also has an attribute "visible" which is a pixel image, compatible with x, with logical values which are TRUE when the corresponding pixel is visible in the perspective view, and FALSE when it is obscured.

perspPoints, perspLines for drawing additional points or lines on the surface.

im.object, plot.im, contour.im

• persp.im
##### Examples
# an image
Z <- setcov(owin())
persp(Z, colmap=terrain.colors(128))
co <- colourmap(range=c(0,1), col=rainbow(128))
expand=6)