Skip to contents

A collection of helpers to generate kernel matrices

Usage

kernel_square(size = 3)

kernel_circle(size = 3)

kernel_gaussian(size = 3, sigma = 1)

kernel_plot(x)

Arguments

size

integer size of the kernel matrix to generate. Must be an odd number so that the central pixel is actually central.

sigma

numeric the sigma parameter for the gaussian kernel

x

a kernel to visualize

Value

a kernel matrix (or a plot for kernel_plot)

Examples

kernel_square(3)
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    1    1    1
#> [3,]    1    1    1
kernel_circle(7)
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,]    0    0    0    1    0    0    0
#> [2,]    0    1    1    1    1    1    0
#> [3,]    0    1    1    1    1    1    0
#> [4,]    1    1    1    1    1    1    1
#> [5,]    0    1    1    1    1    1    0
#> [6,]    0    1    1    1    1    1    0
#> [7,]    0    0    0    1    0    0    0
kg <- kernel_gaussian(9, sigma=3)
kg
#>              [,1]        [,2]        [,3]        [,4]        [,5]        [,6]
#>  [1,] 0.003965247 0.005850089 0.007723246 0.009123937 0.009645167 0.009123937
#>  [2,] 0.005850089 0.008630874 0.011394418 0.013460915 0.014229906 0.013460915
#>  [3,] 0.007723246 0.011394418 0.015042829 0.017771002 0.018786220 0.017771002
#>  [4,] 0.009123937 0.013460915 0.017771002 0.020993959 0.022193296 0.020993959
#>  [5,] 0.009645167 0.014229906 0.018786220 0.022193296 0.023461149 0.022193296
#>  [6,] 0.009123937 0.013460915 0.017771002 0.020993959 0.022193296 0.020993959
#>  [7,] 0.007723246 0.011394418 0.015042829 0.017771002 0.018786220 0.017771002
#>  [8,] 0.005850089 0.008630874 0.011394418 0.013460915 0.014229906 0.013460915
#>  [9,] 0.003965247 0.005850089 0.007723246 0.009123937 0.009645167 0.009123937
#>              [,7]        [,8]        [,9]
#>  [1,] 0.007723246 0.005850089 0.003965247
#>  [2,] 0.011394418 0.008630874 0.005850089
#>  [3,] 0.015042829 0.011394418 0.007723246
#>  [4,] 0.017771002 0.013460915 0.009123937
#>  [5,] 0.018786220 0.014229906 0.009645167
#>  [6,] 0.017771002 0.013460915 0.009123937
#>  [7,] 0.015042829 0.011394418 0.007723246
#>  [8,] 0.011394418 0.008630874 0.005850089
#>  [9,] 0.007723246 0.005850089 0.003965247
kg %>% kernel_plot()