7b3de18ed1f15f7d238993daed6f104fa6eecdee
[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 if List.isEmpty rbcs |> not then
29 averageRBCSize <-
30 rbcs
31 |> List.collect (fun rbc -> [ rbc.size.Width; rbc.size.Height ])
32 |> List.average
33
34 do
35 updateAverageRBCSize ()
36
37 member this.Num with get () = num and set value = num <- value
38
39 member this.RomanNum = Utils.toRomanNumber this.Num
40
41 member this.Name with get () = name and set value = name <- value
42
43 member this.Config = config
44
45 member this.DateLastAnalysis with get () = dateLastAnalysis and set value = dateLastAnalysis <- value
46
47 member this.Img = img
48
49 member this.RBCs
50 with get () = rbcs
51 and set value =
52 rbcs <- value
53 updateAverageRBCSize ()
54
55 member this.ImageParasitemia : int * int =
56 List.length rbcs,
57 rbcs |> List.fold (fun nbInfected rbc -> if rbc.infected then nbInfected + 1 else nbInfected) 0
58
59 member this.ImageNbManuallyChangedRBC (setAsInfected : bool) : int * int =
60 List.length rbcs,
61 rbcs |> List.fold (fun nb rbc -> if rbc.setManually && rbc.infected = setAsInfected then nb + 1 else nb) 0
62
63 member this.ImageNbManuallyChangedRBCStr (setAsInfected : bool) : string =
64 Utils.percentText (this.ImageNbManuallyChangedRBC setAsInfected)
65
66 member this.ImageManuallyChangedRBC (setAsInfected : bool) : int seq =
67 query {
68 for rbc in rbcs do
69 where (rbc.setManually && rbc.infected = setAsInfected)
70 select rbc.num
71 }
72
73 member this.ImageManuallyChangedRBCStr (setAsInfected : bool) : string =
74 let listStr = Utils.listAsStr <| this.ImageManuallyChangedRBC setAsInfected
75 if listStr = "" then
76 ""
77 else
78 "[" + listStr + "]"
79
80 member this.HealthyRBCBrightness with get () = healthyRBCBrightness and set value = healthyRBCBrightness <- value
81 member this.InfectedRBCBrightness with get () = infectedRBCBrightness and set value = infectedRBCBrightness <- value
82
83 member this.HealthyRBCColor : SolidColorBrush =
84 let mutable color = healthyRBColor * healthyRBCBrightness
85 color.A <- 255uy
86 SolidColorBrush (color)
87
88 member this.InfectedRBCColor : SolidColorBrush =
89 let mutable color = infectedRBColor * infectedRBCBrightness
90 color.A <- 255uy
91 SolidColorBrush (color)
92
93 member this.AverageRBCSize = averageRBCSize