1
module ParasitemiaCore.Otsu
5 let otsu (hist
: Histogram) : float32
* float32
* float32
=
8 let mutable maximum = 0.0
10 let sum = hist
.data
|> Array.mapi
(fun i v
-> i
* v
|> float) |> Array.sum
12 for i
in 0 .. hist
.data
.Length - 1 do
13 wB <- wB + hist
.data
.[i
]
16 let wF = hist
.total
- wB
19 sumB <- sumB + i
* hist
.data
.[i
]
20 let mB = (float sumB) / (float wB)
21 let mF = (sum - float sumB) / (float wF)
22 let between = (float wB) * (float wF) * (mB - mF) ** 2.;
31 for i
in 0 .. level - 1 do
32 sum <- sum + i
* hist
.data
.[i
]
33 nb <- nb + hist
.data
.[i
]
34 (sum + level * hist
.data
.[level] / 2) / (nb + hist
.data
.[level] / 2)
39 for i
in level + 1 .. hist
.data
.Length - 1 do
40 sum <- sum + i
* hist
.data
.[i
]
41 nb <- nb + hist
.data
.[i
]
42 (sum + level * hist
.data
.[level] / 2) / (nb + hist
.data
.[level] / 2)
45 float32 l
/ float32 hist
.data
.Length * (hist
.max
- hist
.min
) + hist
.min
47 toFloat level, toFloat mean1, toFloat mean2