Create stats module
This commit is contained in:
1 parent
f68fa6f0b7
commit
c0372a15cb
3 files changed
+24
-24
No files matched your search
+4
-24
@@ -40,8 +40,8 @@ pub fn lines(
|
||||
) -> Vec<Line> {
|
||||
let hough = transform(img);
|
||||
|
||||
let mu = mean((&hough.pixels).into_iter().map(|p| *p));
|
||||
let sigma = stddev((&hough.pixels).into_iter().map(|p| *p), mu);
|
||||
let mu = stats::mean((&hough.pixels).into_iter().map(|p| *p));
|
||||
let sigma = stats::stddev((&hough.pixels).into_iter().map(|p| *p), mu);
|
||||
|
||||
let mut lines = Vec::<Line>::new();
|
||||
for y in 0..hough.extent.y {
|
||||
@@ -59,29 +59,9 @@ pub fn lines(
|
||||
}
|
||||
}
|
||||
}
|
||||
lines
|
||||
lines
|
||||
}
|
||||
|
||||
fn theta_from(x: usize) -> f32 {
|
||||
x as f32 * std::f32::consts::PI / THETA_N as f32
|
||||
}
|
||||
|
||||
fn mean(xs: impl Iterator<Item = f32>) -> f32 {
|
||||
let mut n = 0;
|
||||
let mut sum = 0.0;
|
||||
for x in xs {
|
||||
sum += x;
|
||||
n += 1;
|
||||
}
|
||||
sum / n as f32
|
||||
}
|
||||
|
||||
fn stddev(xs: impl Iterator<Item = f32>, mean: f32) -> f32 {
|
||||
let mut n = 0;
|
||||
let mut sum = 0.0;
|
||||
for x in xs {
|
||||
sum += (x - mean).powf(2.0);
|
||||
n += 1;
|
||||
}
|
||||
(sum / (n - 1) as f32).sqrt()
|
||||
x as f32 * std::f32::consts::PI / THETA_N as f32
|
||||
}
|
||||
@@ -5,3 +5,4 @@ pub mod filter;
|
||||
pub mod hough;
|
||||
pub mod image;
|
||||
pub mod kernel;
|
||||
pub mod stats;
|
||||
@@ -0,0 +1,19 @@
|
||||
pub fn mean(xs: impl Iterator<Item = f32>) -> f32 {
|
||||
let mut n = 0;
|
||||
let mut sum = 0.0;
|
||||
for x in xs {
|
||||
sum += x;
|
||||
n += 1;
|
||||
}
|
||||
sum / n as f32
|
||||
}
|
||||
|
||||
pub fn stddev(xs: impl Iterator<Item = f32>, mean: f32) -> f32 {
|
||||
let mut n = 0;
|
||||
let mut sum = 0.0;
|
||||
for x in xs {
|
||||
sum += (x - mean).powf(2.0);
|
||||
n += 1;
|
||||
}
|
||||
(sum / (n - 1) as f32).sqrt()
|
||||
}
|
||||
Reference in new issue
Block a user