Peculiar elements overlap RBC now.
[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 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 LPFStandardDeviationParasite: float<μm> // Sigma parameter of the gaussian to remove the high frequency noise.
24 LPFStandardDeviationRBC: float<μm>
25
26 // Ellipse.
27 nbPickElementsMin: int
28 factorNbValidPick: float // The number of computed ellipse per edge pixel.
29 factorNbMaxPick: float
30
31 // Parasites detection.
32 darkStainLevel: float // Lower -> more sensitive. Careful about illumination on the borders.
33 maxDarkStainRatio: float // When a cell must own less than this ratio to be a RBC.
34
35 parasiteRadiusRatio: float32 // The ratio of the parasite radius of the RBC radius.
36 minimumParasiteAreaRatio: float32 // Factor of a RBC area. 0.5 means the half of RBC area.
37
38 cytoplasmSizeRatio: float32
39 cytoplasmSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive).
40
41 nucleusAreaRatio: 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 // [<Obsolete>] 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 let defaultParameters = {
48 rbcDiameter = 7.5<μm>
49 resolution = 230.e3<ppi> // 230.e3<ppi> Correspond to 50X.
50
51 ratioAreaPaleCenter = 2.f / 5.f // The ratio between an RBC area and the area of the its pale center.
52
53 granulometryRange = 0.5f
54
55 minRbcRadius = -0.23f
56 maxRbcRadius = 0.23f
57
58 LPFStandardDeviationParasite = 0.15<μm>
59 LPFStandardDeviationRBC = 0.22<μm>
60
61 nbPickElementsMin = 10
62 factorNbValidPick = 0.06 //1.0
63 factorNbMaxPick = 4.
64
65 darkStainLevel = 1.
66 maxDarkStainRatio = 0.1 // 10 %
67
68 parasiteRadiusRatio = 0.5f // 50 %
69 minimumParasiteAreaRatio = 0.02f // 2 %
70
71 cytoplasmSizeRatio = 1.f / 5.f
72 cytoplasmSensitivity = 0.96
73
74 nucleusAreaRatio = 0.01f // 1.0 %
75 infectionSensitivity = 0.92
76
77 // standardDeviationMaxRatio = 0.6 // Obsolete.
78 minimumCellAreaFactor = 0.4f }
79
80 type RBCRadius (radius: float32, parameters: Parameters) =
81 member this.Pixel = radius
82 member this.μm : float<μm> =
83 1.<px> * (float radius) / parameters.resolution |> inchToμm
84
85 member this.Min = radius + parameters.minRbcRadius * radius
86 member this.Max = radius + parameters.maxRbcRadius * radius
87
88 member this.Area = PI * radius ** 2.f
89 member this.MinArea = parameters.minimumCellAreaFactor * this.Area
90
91 member this.ParasiteRadius = parameters.parasiteRadiusRatio * radius
92 member this.CytoplasmSize = parameters.cytoplasmSizeRatio * radius
93
94 member this.NucleusArea = parameters.nucleusAreaRatio * this.Area
95 member this.MinimumParasiteArea = parameters.minimumParasiteAreaRatio * this.Area
96
97 override this.ToString() =
98 sprintf "%d px (%.1f μm)" (Utils.roundInt <| 2.f * radius) (2. * this.μm)
99
100 type Config (param: Parameters) =
101 let RBCadiusInPixels (rbcDiameter: float<μm>) (resolution: float<ppi>) : float32 =
102 let rbcRadiusInch: float<inch> = (μmToInch rbcDiameter) / 2.
103 let rbcRadiusPx: float<px> = resolution * rbcRadiusInch
104 float32 rbcRadiusPx
105
106 let mutable parameters: Parameters = param
107 let mutable rbcRadiusByResolution = RBCRadius(RBCadiusInPixels parameters.rbcDiameter parameters.resolution, parameters)
108 let mutable rbcRadius = RBCRadius(0.f, parameters)
109
110 new () = Config(defaultParameters)
111
112 member this.Parameters
113 with get() = parameters
114 and set(param) =
115 parameters <- param
116 rbcRadiusByResolution <- RBCRadius(RBCadiusInPixels parameters.rbcDiameter parameters.resolution, param)
117 rbcRadius <- RBCRadius(rbcRadius.Pixel, param)
118
119 member val Debug = DebugOff with get, set
120
121 member this.LPFStandardDeviationParasite =
122 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationParasite) * parameters.resolution
123 float stdDeviation
124
125 member this.LPFStandardDeviationRBC =
126 let stdDeviation: float<px> = (μmToInch parameters.LPFStandardDeviationRBC) * parameters.resolution
127 float stdDeviation
128
129 member this.RBCRadiusByResolution = rbcRadiusByResolution
130 member this.RBCRadius = rbcRadius
131
132 member this.SetRBCRadius (radiusPixel: float32) =
133 rbcRadius <- RBCRadius(radiusPixel, parameters)
134
135 member this.Copy () =
136 this.MemberwiseClone() :?> Config
137