blur: boxes_for_gaussian changes
This commit is contained in:
parent
9199791f51
commit
61f0408bad
17
src/blur.rs
17
src/blur.rs
@ -30,18 +30,17 @@ impl Blur {
|
|||||||
|
|
||||||
/// Approximate 1D Gaussian filter of standard deviation sigma with N box filter passes. Each element in the output array contains the radius of the box filter for the corresponding pass.
|
/// Approximate 1D Gaussian filter of standard deviation sigma with N box filter passes. Each element in the output array contains the radius of the box filter for the corresponding pass.
|
||||||
fn boxes_for_gaussian<const N: usize>(sigma: f32) -> [usize; N] {
|
fn boxes_for_gaussian<const N: usize>(sigma: f32) -> [usize; N] {
|
||||||
let w_ideal = (12.0 * sigma * sigma / N as f32 + 1.0).sqrt();
|
let sigma_sq = sigma.powi(2);
|
||||||
|
let w_ideal = (12.0 * sigma_sq / N as f32 + 1.0).sqrt();
|
||||||
let mut w = w_ideal as usize;
|
let mut w = w_ideal as usize;
|
||||||
w -= 1 - (w & 1);
|
w -= 1 - (w & 1);
|
||||||
let mut m = 0.25 * (N * (w + 3)) as f32;
|
let m = (0.25 * (N * (w + 3)) as f32 - 3.0 * sigma_sq / (w + 1) as f32).round() as usize;
|
||||||
m -= 3.0 * sigma * sigma / (w + 1) as f32;
|
|
||||||
let m = m.round() as usize;
|
|
||||||
|
|
||||||
let mut result = [0; N];
|
(0..N)
|
||||||
for (i, value) in result.iter_mut().enumerate() {
|
.map(|i| (w + 1 - 2 * (i < m) as usize) / 2)
|
||||||
*value = (if i < m { w - 1 } else { w + 1 }) / 2;
|
.collect::<Vec<_>>()
|
||||||
}
|
.try_into()
|
||||||
result
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform one pass of the 2D box filter of the given radius. The result will be written to the src slice, while the buf slice is used as a scratch space.
|
/// Perform one pass of the 2D box filter of the given radius. The result will be written to the src slice, while the buf slice is used as a scratch space.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user