Add a way to detect the membrane of a parasite in the ring stage.
[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 colorContribution_BG_RBC: float * float * float // (R, G, B).
17 colorContribution_RBC_parasite: float * float * float // (R, G, B).
18
19 ratioAreaPaleCenter: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'.
20
21 granulometryRange: float32 // The radius will be seeked from radius - granulometryRange * radius to radius + granulometryRange * radius.
22
23 minRbcRadius: float32 // Factor of the mean RBC radius.
24 maxRbcRadius: float32 // Factor of the mean RBC radius.
25
26 LPFStandardDeviationParasite: float<μm> // Sigma parameter of the gaussian to remove the high frequency noise.
27 LPFStandardDeviationStain: float<μm>
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 stainArea: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
38 stainSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
39 maxStainRatio: float // A cell must own less than this ratio to be a RBC.
40
41 infectionArea: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
42 infectionSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
43
44 standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation
45 minimumCellAreaFactor: float32 // Factor of the mean RBC area. A cell with an area below this will be rejected.
46 }
47
48 let defaultParameters = {
49 rbcDiameter = 8.<μm>
50 resolution = 220.e3<ppi> // 220.e3<ppi> Correspond to 50X.
51
52 colorContribution_BG_RBC = 0.16, 0.44, 0.4
53 colorContribution_RBC_parasite = 0.54, 0.41, 0.05
54
55 ratioAreaPaleCenter = 2.f / 5.f // The ratio between an RBC area and the area of the its pale center.
56
57 granulometryRange = 0.5f
58
59 minRbcRadius = -0.3f
60 maxRbcRadius = 0.3f
61
62 LPFStandardDeviationParasite = 0.15<μm>
63 LPFStandardDeviationStain = 0.15<μm> // 0.12
64 LPFStandardDeviationRBC = 0.2<μm> // 8.5e-6<inch>. // 0.2<μm>
65
66 factorNbPick = 1.0
67
68 darkStainLevel = 0.25 // 0.3
69 maxDarkStainRatio = 0.1 // 10 %
70
71 infectionArea = 0.01f // 0.8 % // 0.012f
72 infectionSensitivity = 0.9 // 1) 0.93, 2) 0.94
73
74 stainArea = 0.08f // 6 % // 0.08f
75 stainSensitivity = 0.96 // 1) 0.91, 2) 0.92
76 maxStainRatio = 0.12 // 12 %
77
78 standardDeviationMaxRatio = 0.5 // 0.5
79 minimumCellAreaFactor = 0.4f }
80
81 type RBCRadius (radius: float32, parameters: Parameters) =
82 member this.Pixel = radius
83 member this.μm : float<μm> =
84 1.<px> * (float radius) / parameters.resolution |> inchToμm
85
86 member this.Min = radius + parameters.minRbcRadius * radius
87 member this.Max = radius + parameters.maxRbcRadius * radius
88
89 member this.Area = PI * radius ** 2.f
90 member this.MinArea = parameters.minimumCellAreaFactor * this.Area
91
92 member this.InfectionArea = parameters.infectionArea * this.Area
93 member this.StainArea = parameters.stainArea * this.Area
94
95 override this.ToString() =
96 sprintf "%d px (%.1f μm)" (Utils.roundInt <| 2.f * radius) (2. * this.μm)
97
98 type Config (param: Parameters) =
99 let RBCadiusInPixels (rbcDiameter: float<μm>) (resolution: float<ppi>) : float32 =
100 let rbcRadiusInch: float<inch> = (μmToInch rbcDiameter) / 2.
101 let rbcRadiusPx: float<px> = resolution * rbcRadiusInch
102 float32 rbcRadiusPx
103
104 let mutable parameters: Parameters = param
105 let mutable rbcRadiusByResolution = RBCRadius(RBCadiusInPixels parameters.rbcDiameter parameters.resolution, parameters)
106 let mutable rbcRadius = RBCRadius(0.f, parameters)
107
108 new () = Config(defaultParameters)
109
110 member this.Parameters
111 with get() = parameters
112 and set(param) =
113 parameters <- param
114 rbcRadiusByResolution <- RBCRadius(RBCadiusInPixels parameters.rbcDiameter parameters.resolution, param)
115 rbcRadius <- RBCRadius(rbcRadius.Pixel, param)
116
117 member val Debug = DebugOff with get, set
118
119 member this.LPFStandardDeviationParasite =
120 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationParasite) * parameters.resolution
121 float stdDeviation
122
123 member this.LPFStandardDeviationStain =
124 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationStain) * parameters.resolution
125 float stdDeviation
126
127 member this.LPFStandardDeviationRBC =
128 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationRBC) * parameters.resolution
129 float stdDeviation
130
131 member this.RBCRadiusByResolution = rbcRadiusByResolution
132 member this.RBCRadius = rbcRadius
133
134 member this.SetRBCRadius (radiusPixel: float32) =
135 rbcRadius <- RBCRadius(radiusPixel, parameters)
136
137 member this.Copy () =
138 this.MemberwiseClone() :?> Config
139