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