Remove the parasite detection function from Ma.
[master-thesis.git] / Parasitemia / ParasitemiaCore / Config.fs
1 module ParasitemiaCore.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 averageColor_BG: float32 * float32 * float32 // R * G * B.
17 averageColor_RBC: float32 * float32 * float32 // R * G * B.
18 averageColor_Parasite: float32 * float32 * float32 // R * G * B.
19
20 ratioAreaPaleCenter: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'.
21
22 granulometryRange: float32 // The radius will be seeked from radius - granulometryRange * radius to radius + granulometryRange * radius.
23
24 minRbcRadius: float32 // Factor of the mean RBC radius.
25 maxRbcRadius: float32 // Factor of the mean RBC radius.
26
27 LPFStandardDeviationParasite: float<μm> // Sigma parameter of the gaussian to remove the high frequency noise.
28 LPFStandardDeviationRBC: float<μm>
29
30 // Ellipse.
31 factorNbPick: float // The number of computed ellipse per edge pixel.
32
33 // Parasites detection.
34 darkStainLevel: float // Lower -> more sensitive. Careful about illumination on the borders.
35 maxDarkStainRatio: float // When a cell must own less than this ratio to be a RBC.
36
37 parasiteRadiusRatio: float32 // The ratio of the parasite radius of the RBC radius.
38 minimumParasiteAreaRatio: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
39
40 cytoplasmSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
41
42 nucleusAreaRatio: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
43 infectionSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
44
45 standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation
46 minimumCellAreaFactor: float32 // Factor of the mean RBC area. A cell with an area below this will be rejected.
47 }
48
49 let defaultParameters = {
50 rbcDiameter = 8.<μm>
51 resolution = 220.e3<ppi> // 220.e3<ppi> Correspond to 50X.
52
53 averageColor_BG = 113.3f, 135.3f, 150.3f
54 averageColor_RBC = 94.7f, 80.7f, 99.3f
55 averageColor_Parasite = 76.f, 58.f, 94.f
56
57 (*averageColor_BG = 179.f, 148.f, 121.f
58 averageColor_RBC = 141.f, 96.f, 83.f
59 averageColor_Parasite = 123.f, 89.f, 83.f*)
60
61 ratioAreaPaleCenter = 2.f / 5.f // The ratio between an RBC area and the area of the its pale center.
62
63 granulometryRange = 0.5f
64
65 minRbcRadius = -0.3f
66 maxRbcRadius = 0.3f
67
68 LPFStandardDeviationParasite = 0.15<μm>
69 LPFStandardDeviationRBC = 0.2<μm>
70
71 factorNbPick = 1.0
72
73 darkStainLevel = 0.25
74 maxDarkStainRatio = 0.1 // 10 %
75
76 parasiteRadiusRatio = 0.5f // 40 %
77
78 minimumParasiteAreaRatio = 0.02f // 2 %
79 cytoplasmSensitivity = 0.96 // 1) 0.91, 2) 0.92
80
81 nucleusAreaRatio = 0.01f // 1.0 %
82 infectionSensitivity = 0.9 // 1) 0.93, 2) 0.94
83
84 standardDeviationMaxRatio = 0.5 // 0.5
85 minimumCellAreaFactor = 0.4f }
86
87 type RBCRadius (radius: float32, parameters: Parameters) =
88 member this.Pixel = radius
89 member this.μm : float<μm> =
90 1.<px> * (float radius) / parameters.resolution |> inchToμm
91
92 member this.Min = radius + parameters.minRbcRadius * radius
93 member this.Max = radius + parameters.maxRbcRadius * radius
94
95 member this.Area = PI * radius ** 2.f
96 member this.MinArea = parameters.minimumCellAreaFactor * this.Area
97
98 member this.ParasiteRadius = parameters.parasiteRadiusRatio * radius
99
100 member this.NucleusArea = parameters.nucleusAreaRatio * this.Area
101 member this.MinimumParasiteArea = parameters.minimumParasiteAreaRatio * this.Area
102
103 override this.ToString() =
104 sprintf "%d px (%.1f μm)" (Utils.roundInt <| 2.f * radius) (2. * this.μm)
105
106 type Config (param: Parameters) =
107 let RBCadiusInPixels (rbcDiameter: float<μm>) (resolution: float<ppi>) : float32 =
108 let rbcRadiusInch: float<inch> = (μmToInch rbcDiameter) / 2.
109 let rbcRadiusPx: float<px> = resolution * rbcRadiusInch
110 float32 rbcRadiusPx
111
112 let mutable parameters: Parameters = param
113 let mutable rbcRadiusByResolution = RBCRadius(RBCadiusInPixels parameters.rbcDiameter parameters.resolution, parameters)
114 let mutable rbcRadius = RBCRadius(0.f, parameters)
115
116 new () = Config(defaultParameters)
117
118 member this.Parameters
119 with get() = parameters
120 and set(param) =
121 parameters <- param
122 rbcRadiusByResolution <- RBCRadius(RBCadiusInPixels parameters.rbcDiameter parameters.resolution, param)
123 rbcRadius <- RBCRadius(rbcRadius.Pixel, param)
124
125 member val Debug = DebugOff with get, set
126
127 member this.LPFStandardDeviationParasite =
128 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationParasite) * parameters.resolution
129 float stdDeviation
130
131 member this.LPFStandardDeviationRBC =
132 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationRBC) * parameters.resolution
133 float stdDeviation
134
135 member this.RBCRadiusByResolution = rbcRadiusByResolution
136 member this.RBCRadius = rbcRadius
137
138 member this.SetRBCRadius (radiusPixel: float32) =
139 rbcRadius <- RBCRadius(radiusPixel, parameters)
140
141 member this.Copy () =
142 this.MemberwiseClone() :?> Config
143