1
module ParasitemiaCore.Histogram
12 total
: int // Number of elements.
13 sum
: int // Sum of all intensity.
18 let histogramImg (img
: Image<Gray, float32
>) (nbSamples
: int) : Histogram =
19 let imgData = img
.Data
22 let min = ref [| 0.0
|]
23 let minLocation = ref <| [| Point() |]
24 let max = ref [| 0.0
|]
25 let maxLocation = ref <| [| Point() |]
26 img
.MinMax(min, max, minLocation, maxLocation)
27 float32
(!min).[0], float32
(!max).[0]
29 let inline bin
(x
: float32
) : int =
30 let p = int ((x
- min) / (max - min) * float32 nbSamples
)
31 if p >= nbSamples
then nbSamples
- 1 else p
33 let data = Array.zeroCreate
nbSamples
35 for i
= 0 to img
.Height - 1 do
36 for j
= 0 to img
.Width - 1 do
37 let p = bin
imgData.[i
, j
, 0]
38 data.[p] <- data.[p] + 1
40 { data = data; total
= img
.Height * img
.Width; sum
= Array.sum
data; min = min; max = max }
42 let histogramMat (mat
: Matrix<float32
>) (nbSamples : int) : Histogram =
43 let matData = mat
.Data
47 let minLocation = ref <| Point()
49 let maxLocation = ref <| Point()
50 mat
.MinMax(min, max, minLocation, maxLocation)
51 float32
!min, float32
!max
53 let inline bin
(x
: float32
) : int =
54 let p = int ((x
- min) / (max - min) * float32
nbSamples)
55 if p >= nbSamples then nbSamples - 1 else p
57 let data = Array.zeroCreate
nbSamples
59 for i
= 0 to mat
.Height - 1 do
60 for j
= 0 to mat
.Width - 1 do
61 let p = bin
matData.[i
, j
]
62 data.[p] <- data.[p] + 1
64 { data = data; total
= mat
.Height * mat
.Width; sum
= Array.sum
data; min = min; max = max }
66 let histogram (values
: float32 seq
) (nbSamples : int) : Histogram =
67 let mutable min = Single.MaxValue
68 let mutable max = Single.MinValue
73 if v
< min then min <- v
74 if v
> max then max <- v
76 let inline bin
(x
: float32
) : int =
77 let p = int ((x
- min) / (max - min) * float32
nbSamples)
78 if p >= nbSamples then nbSamples - 1 else p
80 let data = Array.zeroCreate
nbSamples
84 data.[p] <- data.[p] + 1
86 { data = data; total
= n; sum
= Array.sum
data; min = min; max = max }