Save predefined PPI and sensor sizes in JSON files.
[master-thesis.git] / Parasitemia / ParasitemiaUI / Types.fs
1 module ParasitemiaUI.Types
2
3 open System
4 open System.Windows
5 open System.Windows.Media
6
7 open Emgu.CV
8 open Emgu.CV.Structure
9
10 open Newtonsoft.Json
11
12 open ParasitemiaCore.UnitsOfMeasure
13
14 let healthyRBColor = Color.FromRgb(255uy, 255uy, 0uy) // Yellow-green.
15 let infectedRBColor = Color.FromRgb(255uy, 0uy, 40uy) // Red with a bit of blue.
16
17 type RBC = {
18 num: int
19
20 [<JsonIgnore>]
21 mutable infected: bool
22
23 [<JsonIgnore>]
24 mutable setManually: bool
25
26 center: Point
27 size: Size
28 infectedArea: int }
29
30 type SourceImage = {
31 mutable num: int
32 mutable name: string
33
34 mutable config: ParasitemiaCore.Config.Config
35 mutable dateLastAnalysis: DateTime // UTC.
36 img: Image<Bgr, byte>
37 mutable rbcs: RBC list
38
39 mutable healthyRBCBrightness: float32
40 mutable infectedRBCBrightness: float32 } with
41
42 member this.HealthyRBCColor: SolidColorBrush =
43 let mutable color = healthyRBColor * this.healthyRBCBrightness
44 color.A <- 255uy;
45 SolidColorBrush(color)
46
47 member this.InfectedRBCColor: SolidColorBrush =
48 let mutable color = infectedRBColor * this.infectedRBCBrightness
49 color.A <- 255uy;
50 SolidColorBrush(color)
51
52 type PredefinedPPI = {
53 ppi: int<ppi>
54 label: string } with
55 override this.ToString() =
56 sprintf "%s: %d" this.label this.ppi
57
58 type SensorSize = {
59 w: float<mm>
60 h: float<mm>
61 label: string } with
62 override this.ToString () =
63 sprintf "%g mm × %g mm%s" this.w this.h (if this.label = "" then "" else " (" + this.label + ")")
64
65 let defaultPredefinedPPI = [
66 { ppi = 230000<ppi>; label = "50×" }
67 { ppi = 460000<ppi>; label = "100×" } ]
68
69 let defaultSensorSizes = [
70 { w = 3.2<mm>; h = 2.4<mm>; label = "1/4″" }
71 { w = 4.8<mm>; h = 3.6<mm>; label = "1/3″" }
72 { w = 5.76<mm>; h = 4.29<mm>; label = "1/2.5″" }
73 { w = 6.4<mm>; h = 4.8<mm>; label = "1/2″" }
74 { w = 7.18<mm>; h = 5.32<mm>; label = "1/1.8″" }
75 { w = 7.6<mm>; h = 5.7<mm>; label = "1/1.7″" }
76 { w = 8.8<mm>; h = 6.6<mm>; label = "2/3″" }
77 { w = 13.2<mm>; h = 8.8<mm>; label = "1″" } ]
78
79