Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

resize_matrix

Resize Matrix


Description

Resizes a matrix (preserving contents) by specifying the desired output dimensions or a scaling factor.

Usage

resize_matrix(
  heightmap,
  scale = 1,
  width = NULL,
  height = NULL,
  method = "bilinear"
)

Arguments

heightmap

The elevation matrix.

scale

Default '0.5'. The amount to scale down the matrix. Scales using bilinear interpolation.

width

Default 'NULL'. Alternative to 'scale' argument. The desired output width. If 'width' is less than 1, it will be interpreted as a scaling factor– e.g. 0.5 would halve the resolution for the width.

height

Default 'NULL'. Alternative to 'scale' argument. The desired output width. If 'height' is less than 1, it will be interpreted as a scaling factor– e.g. 0.5 would halve the resolution for the height.

method

Default 'bilinear'. Method of interpolation. Alteratively 'cubic', which is slightly smoother, although current implementation slightly scales the image.

Examples

#Reduce the size of the monterey bay dataset by half


montbaysmall = resize_matrix(montereybay, scale=0.5)
montbaysmall %>%
 sphere_shade() %>%
 plot_map()

#Reduce the size of the monterey bay dataset from 540x540 to 100x100
montbaysmall = resize_matrix(montereybay, width = 100, height = 100)
montbaysmall %>%
 sphere_shade() %>%
 plot_map()
 
#Increase the size of the volcano dataset 3x
volcanobig = resize_matrix(volcano, scale=3)
volcanobig %>% 
 sphere_shade() %>%
 plot_map()
 
#Increase the size of the volcano dataset 2x, using cubic interpolation
volcanobig = resize_matrix(volcano, scale=3, method="cubic")
volcanobig %>% 
 sphere_shade() %>%
 plot_map()

rayshader

Create Maps and Visualize Data in 2D and 3D

v0.24.10
GPL-3
Authors
Tyler Morgan-Wall
Initial release
2021-04-25

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.