open Histogram
-let otsu (hist: Histogram) : float32 * float32 * float32 =
+let otsu (hist : Histogram) : float32 * float32 * float32 =
let mutable sumB = 0
let mutable wB = 0
let mutable maximum = 0.0
for i = 0 to hist.data.Length - 1 do
wB <- wB + hist.data.[i]
- if wB <> 0
- then
+ if wB <> 0 then
let wF = hist.total - wB
- if wF <> 0
- then
+ if wF <> 0 then
sumB <- sumB + i * hist.data.[i]
let mB = (float sumB) / (float wB)
let mF = (sum - float sumB) / (float wF)
let between = (float wB) * (float wF) * (mB - mF) ** 2.;
- if between >= maximum
- then
+ if between >= maximum then
level <- i
maximum <- between