Stage 1 baseline implementation of the graph Laplacian smoother
used as a correctness reference for the Rust kernel
(graph_smooth_rust()). Builds the pixel adjacency, the combinatorial
graph Laplacian \(L = D - W\) on a width x height grid, and
solves the dense linear system
graph_smooth_r(data, width, height, alpha = 1, neighbors = 4L)numeric matrix of input spectra. Rows index pixels in
column-major order (k = j * width + i, with i the x-coordinate
and j the y-coordinate, both 0-based), columns index wavelength
bands.
integer image dimensions; nrow(data) must equal
width * height.
non-negative numeric smoothing strength. alpha = 0
returns data unchanged.
integer, either 4 (von Neumann) or 8 (Moore)
neighborhood connectivity.
Dense numeric matrix of smoothed spectra with the same shape
as data.
$$(I + \alpha L)\, X = B$$
band-by-band using dense solve(). With neighbors = 4 or 8,
L is symmetric positive semi-definite, so I + alpha * L is SPD for
any alpha > 0 and the solve is well-posed.
set.seed(1)
B <- matrix(rnorm(16 * 3), nrow = 16, ncol = 3)
graph_smooth_r(B, width = 4, height = 4, alpha = 0.5, neighbors = 4L)
#> [,1] [,2] [,3]
#> [1,] -0.31862214 0.30327164 0.12163137
#> [2,] -0.05940985 0.63880583 -0.10757710
#> [3,] -0.09444793 0.50123567 -0.53475554
#> [4,] 0.93378963 0.19436961 -0.22994205
#> [5,] 0.03782890 0.60666128 -0.18124065
#> [6,] -0.25126584 0.50184939 -0.01715128
#> [7,] 0.32463779 0.03056052 0.41786059
#> [8,] 0.63904486 -0.91155985 0.44497646
#> [9,] 0.10001695 0.39023062 -0.22210341
#> [10,] -0.16971514 0.17079613 -0.11332370
#> [11,] 0.67963757 -0.05729206 0.41404315
#> [12,] 0.46014744 -0.80402601 0.51061226
#> [13,] -0.51959174 -0.06595580 -0.48690553
#> [14,] -0.93590273 0.30224629 -0.34800731
#> [15,] 0.43919300 0.57050799 0.27518301
#> [16,] 0.20236830 -0.10977337 0.58071528