e3a9950290f2d5af14a91ea9ba439adcb06c52fe
1
module ParasitemiaCore.Histogram
11 total
: int // Number of elements.
12 sum
: int // Sum of all intensity.
16 let histogramImg (img
: Image<Gray, float32
>) (nbSamples
: int) : Histogram =
17 let imgData = img
.Data
20 let min = ref [| 0.0
|]
21 let minLocation = ref <| [| Point() |]
22 let max = ref [| 0.0
|]
23 let maxLocation = ref <| [| Point() |]
24 img
.MinMax(min, max, minLocation, maxLocation)
25 float32
(!min).[0], float32
(!max).[0]
27 let inline bin
(x
: float32
) : int =
28 let p = int ((x
- min) / (max - min) * float32 nbSamples
)
29 if p >= nbSamples
then nbSamples
- 1 else p
31 let data = Array.zeroCreate
nbSamples
33 for i
= 0 to img
.Height - 1 do
34 for j
= 0 to img
.Width - 1 do
35 let p = bin
imgData.[i
, j
, 0]
36 data.[p] <- data.[p] + 1
38 { data = data; total
= img
.Height * img
.Width; sum
= Array.sum
data; min = min; max = max }
40 let histogramMat (mat
: Matrix<float32
>) (nbSamples: int) : Histogram =
41 let matData = mat
.Data
45 let minLocation = ref <| Point()
47 let maxLocation = ref <| Point()
48 mat
.MinMax(min, max, minLocation, maxLocation)
49 float32
!min, float32
!max
51 let inline bin
(x
: float32
) : int =
52 let p = int ((x
- min) / (max - min) * float32
nbSamples)
53 if p >= nbSamples then nbSamples - 1 else p
55 let data = Array.zeroCreate
nbSamples
57 for i
= 0 to mat
.Height - 1 do
58 for j
= 0 to mat
.Width - 1 do
59 let p = bin
matData.[i
, j
]
60 data.[p] <- data.[p] + 1
62 { data = data; total
= mat
.Height * mat
.Width; sum
= Array.sum
data; min = min; max = max }
64 let histogram (values
: float32 seq
) (nbSamples: int) : Histogram =
65 let mutable min = Single.MaxValue
66 let mutable max = Single.MinValue
71 if v
< min then min <- v
72 if v
> max then max <- v
74 let inline bin
(x
: float32
) : int =
75 let p = int ((x
- min) / (max - min) * float32
nbSamples)
76 if p >= nbSamples then nbSamples - 1 else p
78 let data = Array.zeroCreate
nbSamples
82 data.[p] <- data.[p] + 1
84 { data = data; total
= n; sum
= Array.sum
data; min = min; max = max }