The images to be analyzed can be selected.
[master-thesis.git] / Parasitemia / Parasitemia / Config.fs
1 module Config
2
3 open System
4
5 open Const
6 open UnitsOfMeasure
7
8 type Debug =
9 | DebugOff
10 | DebugOn of string // Output directory.
11
12 type Parameters = {
13 rbcDiameter: float<μm>
14 resolution: float<ppi>
15
16 ratioAreaPaleCenter: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'.
17
18 granulometryRange: float32 // The radius will be seeked from radius - granulometryRange * radius to radius + granulometryRange * radius.
19
20 minRbcRadius: float32 // Factor of the mean RBC radius.
21 maxRbcRadius: float32 // Factor of the mean RBC radius.
22
23 LPFStandardDeviation: float<μm> // Sigma parameter of the gaussian to remove the high frequency noise.
24
25 // Ellipse.
26 factorNbPick: float // The number of computed ellipse per edge pixel.
27
28 // Parasites detection.
29 darkStainLevel: float // Lower -> more sensitive. Careful about illumination on the borders.
30 maxDarkStainRatio: float // When a cell must own less than this ratio to be a RBC.
31
32 stainArea: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
33 stainSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
34 maxStainRatio: float // A cell must own less than this ratio to be a RBC.
35
36 infectionArea: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
37 infectionSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
38
39 standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation
40 minimumCellAreaFactor: float32 // Factor of the mean RBC area. A cell with an area below this will be rejected.
41 }
42
43 let defaultParameters = {
44 rbcDiameter = 8.<μm>
45 resolution = 200.e3<ppi> // Correspond to 50X.
46
47 ratioAreaPaleCenter = 1.f / 3.f // The ratio between an RBC area and the area of the its pale center.
48
49 granulometryRange = 0.5f
50
51 minRbcRadius = -0.3f
52 maxRbcRadius = 0.3f
53
54 LPFStandardDeviation = 0.2<μm> // 8.5e-6<inch>.
55
56 factorNbPick = 1.0
57
58 darkStainLevel = 0.25 // 0.3
59 maxDarkStainRatio = 0.1 // 10 %
60
61 infectionArea = 0.012f // 1.2 %
62 infectionSensitivity = 0.9
63
64 stainArea = 0.08f // 8 %
65 stainSensitivity = 0.9
66 maxStainRatio = 0.12 // 12 %
67
68 standardDeviationMaxRatio = 0.5 // 0.5
69 minimumCellAreaFactor = 0.4f }
70
71 type Config (param: Parameters) =
72 let mutable parameters: Parameters = param
73
74 let initialRBCRadius : float32 =
75 let rbcRadiusInch: float<inch> = (μmToInch parameters.rbcDiameter) / 2.
76 let rbcRadiusPx: float<px> = parameters.resolution * rbcRadiusInch
77 float32 rbcRadiusPx
78
79 new () = Config(defaultParameters)
80
81 member this.Parameters with get() = parameters and set(param) = parameters <- param
82 member val Debug = DebugOff with get, set
83
84 member this.LPFStandardDeviation =
85 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviation) * param.resolution
86 float stdDeviation
87
88 // Mean RBC radius.
89 member val RBCRadius : float32 = initialRBCRadius with get, set
90
91 member this.RBCRadiusμm : float<μm> =
92 1.<px> * (float this.RBCRadius) / parameters.resolution |> inchToμm
93
94 member this.RBCMinRadius = this.RBCRadius + parameters.minRbcRadius * this.RBCRadius
95 member this.RBCMaxRadius = this.RBCRadius + parameters.maxRbcRadius * this.RBCRadius
96
97 member this.RBCArea = PI * this.RBCRadius ** 2.f
98 member this.RBCMinArea = parameters.minimumCellAreaFactor * this.RBCArea
99
100 member this.InfectionArea = parameters.infectionArea * this.RBCArea
101 member this.StainArea = parameters.stainArea * this.RBCArea
102
103 member this.FormattedRadius =
104 sprintf "%d px (%.1f μm)" (Utils.roundInt <| 2.f * this.RBCRadius) (2. * this.RBCRadiusμm)
105
106 member this.Copy () =
107 this.MemberwiseClone() :?> Config
108