Calculate focal statistics on a hyperspectral image using non-overlapping sliding windows.

slideBrick(Brick, slide_windows, fun = median)

Arguments

Brick

An object of class RasterBrick or RasterStack (from package raster), containing multiple layers (spectral bands).

slide_windows

An object of class slideWindows, which consists of a list of spatial extents giving the location of the non-overlapping sliding windows that covers the entire image.

fun

A vectorized function indicating the statistics to be calculated within each sliding-windows, e.g. median (default), mean, sd.

Value

A vector or matrix containing the estimates of each sliding windows.

See also

Examples

p <- system.file('exdata', 'obory.dat', package = 'hyperbrick')
im <- buildBrick(p, ref_layer = 35,
                spectral_feature = "radiance",
                hFOV = 36.8, vFOV = 36.8, height = 45)
print(im)
#> class      : RasterBrick 
#> dimensions : 128, 128, 16384, 81  (nrow, ncol, ncell, nlayers)
#> resolution : 0.2338986, 0.2338986  (x, y)
#> extent     : 512700.2, 512730.1, 5769447, 5769477  (xmin, xmax, ymin, ymax)
#> crs        : +proj=utm +zone=34 +datum=WGS84 +units=m +no_defs 
#> source     : memory
#> names      :      b500,      b505,      b510,      b515,      b520,      b525,      b530,      b535,      b540,      b545,      b550,      b555,      b560,      b565,      b570, ... 
#> min values :  0.000000,  0.000000,  3.897654,  4.049472,  4.437743,  4.817500,  4.343040,  4.413920,  4.358121,  4.428270,  4.682880,  4.520327,  4.454752,  4.520215,  4.809630, ... 
#> max values :   0.00000,   0.00000,  66.79552,  67.92139,  70.52788,  71.32485,  70.51176,  68.90576,  68.98065,  70.26558,  69.09466,  69.58734,  70.76328,  73.18644,  75.02528, ... 
#> 
plotRGB(im, r = 63, b = 34, g = 11, scale = 90)

ext <- extent(c(512700.2, 512715, 5769462, 5769477))
sw <- slideWindows(ext, n = c(7, 7))
lapply(sw, lines, col = "white") -> null_obj


sb <- slideBrick(im, sw, fun = mean)
head(sb)
#>          [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
#> b500  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b505  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b510 12.75857 13.26442 13.17248 13.04623 12.30576 12.01026 11.88891 13.03600
#> b515 13.07932 13.53732 13.47865 13.38056 12.66994 12.40043 12.25170 13.23369
#> b520 13.87847 14.39375 14.30749 14.28247 13.46109 13.28651 13.00823 14.10483
#> b525 14.93502 15.48548 15.34373 15.23994 14.49004 14.36838 14.09447 15.09697
#>          [,9]    [,10]    [,11]    [,12]    [,13]    [,14]    [,15]    [,16]
#> b500  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b505  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b510 13.49851 13.60887 13.13858 13.12507 12.84848 12.42397 13.39208 13.58370
#> b515 13.81157 13.87270 13.53837 13.50300 13.17613 12.91251 13.58336 13.89090
#> b520 14.70460 14.70545 14.51737 14.34615 14.08241 13.65188 14.52388 14.67861
#> b525 15.86491 15.96884 15.63053 15.50381 15.06732 14.83548 15.62891 16.01627
#>         [,17]    [,18]    [,19]    [,20]    [,21]    [,22]    [,23]    [,24]
#> b500  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b505  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b510 13.82219 13.48634 13.31101 13.58479 13.67281 13.49489 13.70267 13.66638
#> b515 14.26368 13.87919 13.67203 13.97965 14.01743 13.84810 13.99755 13.95825
#> b520 15.15102 14.86996 14.60093 14.86746 14.89736 14.74459 14.93873 14.87836
#> b525 16.34274 15.94733 15.76267 16.01032 16.00211 16.02839 16.06759 16.07639
#>         [,25]    [,26]    [,27]    [,28]    [,29]    [,30]    [,31]    [,32]
#> b500  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b505  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b510 13.41429 13.30737 14.36494 13.99048 13.74639 13.73866 13.78157 13.81657
#> b515 13.77630 13.85798 14.75049 14.37514 14.06252 14.10911 14.20901 14.14137
#> b520 14.83823 14.66493 15.70809 15.40301 14.97668 15.05564 15.10792 15.03636
#> b525 15.89962 15.81535 17.08151 16.70013 16.30041 16.39099 16.33064 16.48963
#>         [,33]    [,34]    [,35]    [,36]    [,37]    [,38]    [,39]    [,40]
#> b500  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b505  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b510 13.71083 13.25106 13.57133 13.62107 14.45981 13.83782 14.08953 14.04554
#> b515 14.20134 13.74085 14.07975 13.91306 14.89052 14.14819 14.36706 14.34790
#> b520 15.07304 14.73906 14.93303 14.79873 15.74393 15.28412 15.41741 15.36628
#> b525 16.37096 16.00250 16.31982 16.16844 17.36903 16.67739 16.75917 16.83041
#>         [,41]    [,42]    [,43]    [,44]    [,45]    [,46]    [,47]    [,48]
#> b500  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b505  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
#> b510 13.71103 13.80403 13.12301 14.42943 14.70058 14.29837 13.97457 14.49605
#> b515 14.17775 14.31161 13.46501 14.81396 14.98094 14.71744 14.44486 14.90458
#> b520 15.21705 15.26637 14.41905 15.79131 16.02945 15.76661 15.40824 15.93892
#> b525 16.54259 16.66572 15.74046 17.37034 17.53368 17.20365 16.87555 17.48165
#>         [,49]
#> b500  0.00000
#> b505  0.00000
#> b510 14.39896
#> b515 15.04551
#> b520 15.98496
#> b525 17.63996