Converts a pixel image to another unit of length.
# S3 method for im
rescale(X, s, unitname)
Pixel image (object of class "im"
).
Conversion factor: the new units are s
times the old units.
Optional. New name for the unit of length.
See unitname
.
Another pixel image (of class "im"
),
containing the same pixel values, but with pixel coordinates
expressed in the new units.
This is a method for the generic function rescale
.
The spatial coordinates of the pixels in X
will be re-expressed
in terms of a new unit of length that is s
times the current
unit of length given in X
.
(Thus, the coordinate values are divided by s
,
while the unit value is multiplied by s
).
If s
is missing, then the coordinates will be re-expressed
in ‘native’ units; for example if the current unit is
equal to 0.1 metres, then the coordinates will be re-expressed in metres.
The result is a pixel image representing the same data but re-expressed in a different unit.
Pixel values are unchanged. This may not be what you intended!
# NOT RUN {
# Bramble Canes data: 1 unit = 9 metres
data(bramblecanes)
# distance transform
Z <- distmap(bramblecanes)
# convert to metres
# first alter the pixel values
Zm <- eval.im(9 * Z)
# now rescale the pixel coordinates
Z <- rescale(Zm, 1/9)
# or equivalently
Z <- rescale(Zm)
# }
Run the code above in your browser using DataLab