MCPcopy Create free account
hub / github.com/Ruddle/Fomos / kernel

Function kernel

app_console/src/main.rs:113–134  ·  view source on GitHub ↗
(sigma: f32)

Source from the content-addressed store, hash-verified

111}
112
113fn kernel<const S: usize>(sigma: f32) -> [f32; S] {
114 let mut kernel = [0.0; S];
115 let mid = S / 2;
116
117 // calculate the Gaussian distribution
118 let variance = sigma.powi(2);
119 let factor = 1.0 / (2.0 * 3.141592 * variance);
120 let mut sum = 0.0;
121 for i in 0..S {
122 let x = (i as i32 - mid as i32) as f32;
123 let value = factor * (-x.powi(2) / (2.0 * variance)).exp();
124 kernel[i] = value;
125 sum += value;
126 }
127 sum *= 0.997;
128 // normalize the kernel
129 for i in 0..S {
130 kernel[i] /= sum;
131 }
132
133 kernel
134}
135fn blur(
136 fx: isize,
137 fy: isize,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected