2330227295a005c82a54f83d991d6a793c8ecc3c
[master-thesis.git] / Parasitemia / ParasitemiaUI / SourceImage.fs
1 namespace ParasitemiaUI
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 Types
11
12 type SourceImage (num : int, name : string, config : ParasitemiaCore.Config.Config, dateLastAnalysis : DateTime, img : Image<Bgr, byte>, rbcs : RBC list) =
13 let mutable num = num
14 let mutable name = name
15 let mutable config = config
16 let mutable dateLastAnalysis = dateLastAnalysis // UTC.
17 let img = img
18 let mutable rbcs = rbcs
19 let mutable healthyRBCBrightness = 1.f
20 let mutable infectedRBCBrightness = 1.f
21
22 let mutable averageRBCSize = 1.
23
24 let healthyRBColor = Color.FromRgb (255uy, 255uy, 0uy) // Yellow-green.
25 let infectedRBColor = Color.FromRgb (255uy, 0uy, 40uy) // Red with a bit of blue.
26
27 let updateAverageRBCSize () =
28 averageRBCSize <-
29 rbcs
30 |> List.collect (fun rbc -> [ rbc.size.Width; rbc.size.Height ])
31 |> List.average
32
33 do
34 updateAverageRBCSize ()
35
36 member this.Num with get () = num and set value = num <- value
37
38 member this.Name with get () = name and set value = name <- value
39
40 member this.Config = config
41
42 member this.DateLastAnalysis with get () = dateLastAnalysis and set value = dateLastAnalysis <- value
43
44 member this.Img = img
45
46 member this.RBCs
47 with get () = rbcs
48 and set value = rbcs <- value
49
50 member this.ImageParasitemia : int * int =
51 List.length rbcs,
52 rbcs |> List.fold (fun nbInfected rbc -> if rbc.infected then nbInfected + 1 else nbInfected) 0
53
54 member this.ImageNbManuallyChangedRBC (setAsInfected : bool) : int * int =
55 List.length rbcs,
56 rbcs |> List.fold (fun nb rbc -> if rbc.setManually && rbc.infected = setAsInfected then nb + 1 else nb) 0
57
58 member this.ImageNbManuallyChangedRBCStr (setAsInfected : bool) : string =
59 Utils.percentText (this.ImageNbManuallyChangedRBC setAsInfected)
60
61 member this.ImageManuallyChangedRBC (setAsInfected : bool) : int seq =
62 query {
63 for rbc in rbcs do
64 where (rbc.setManually && rbc.infected = setAsInfected)
65 select rbc.num
66 }
67
68 member this.ImageManuallyChangedRBCStr (setAsInfected : bool) : string =
69 let listStr = Utils.listAsStr <| this.ImageManuallyChangedRBC setAsInfected
70 if listStr = "" then
71 ""
72 else
73 "[" + listStr + "]"
74
75 member this.HealthyRBCBrightness with get () = healthyRBCBrightness and set value = healthyRBCBrightness <- value
76 member this.InfectedRBCBrightness with get () = infectedRBCBrightness and set value = infectedRBCBrightness <- value
77
78 member this.HealthyRBCColor : SolidColorBrush =
79 let mutable color = healthyRBColor * healthyRBCBrightness
80 color.A <- 255uy
81 SolidColorBrush (color)
82
83 member this.InfectedRBCColor : SolidColorBrush =
84 let mutable color = infectedRBColor * infectedRBCBrightness
85 color.A <- 255uy
86 SolidColorBrush (color)
87
88 member this.AverageRBCSize = averageRBCSize