nativeRaster
images to/from PNG and JPEG
Both the png and jpeg packages allow
images to be loaded directly as nativeRaster
images.
img <- jpeg::readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"), native = TRUE)
class(img)
#> [1] "nativeRaster"
grid.raster(img, interpolate = FALSE)
img <- png::readPNG(system.file("img", "Rlogo.png", package="png"), native = TRUE)
class(img)
#> [1] "nativeRaster"
grid.raster(img, interpolate = FALSE)
raster
image to/from
nativeRaster
ras <- matrix(c('brown', 'darkblue', 'darkblue', 'brown'), 2, 2)
ras
#> [,1] [,2]
#> [1,] "brown" "darkblue"
#> [2,] "darkblue" "brown"
grid.raster(ras, interpolate = FALSE)
nr <- nara::raster_to_nr(ras)
nr
#> [,1] [,2]
#> [1,] -14013787 -7667712
#> [2,] -7667712 -14013787
#> attr(,"class")
#> [1] "nativeRaster"
grid.raster(nr, interpolate = FALSE)
array
image to/from
nativeRaster
arr <- array(c(
1, 1, 0,
0, 0, 0,
0, 0, 0,
1, 1, 0
), dim = c(2, 2, 3))
arr
#> , , 1
#>
#> [,1] [,2]
#> [1,] 1 0
#> [2,] 1 0
#>
#> , , 2
#>
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 0
#>
#> , , 3
#>
#> [,1] [,2]
#> [1,] 0 1
#> [2,] 1 0
grid.raster(arr, interpolate = FALSE)
nr <- nara::array_to_nr(arr)
nr
#> [,1] [,2]
#> [1,] -16776961 -65281
#> [2,] -65536 -16777216
#> attr(,"class")
#> [1] "nativeRaster"
grid.raster(nr, interpolate = FALSE)