e4eae8dc192c30218aba070feabfda573e5af379
[master-thesis.git] / Parasitemia / Parasitemia / MatchingEllipses.fs
1 module MatchingEllipses
2
3 open System
4 open System.Linq
5 open System.Collections.Generic
6
7 open Types
8 open Utils
9
10
11 type EllipseScore = { mutable matchingScore: float; e: Ellipse }
12
13 let matchingScoreThreshold1 = 0.5
14 let matchingScoreThreshold2 = 2.0
15
16 let ellipseArea e = e.a * e.b * Math.PI
17
18 type MatchingEllipses () =
19 let ellipses = List<EllipseScore>()
20
21 member this.Add (e: Ellipse) =
22
23 // dprintfn "new ellipse: %A, nb: %A" e ellipses.Count
24
25 let areaE = ellipseArea e
26
27 let mutable matchingScoreE = 0.0
28
29 for other in ellipses do
30 let areaOther = ellipseArea other.e
31 let commonArea = EEOver.EEOverlapArea e other.e
32 let matchingScore = (2.0 * commonArea / (areaE + areaOther)) ** 2.0
33 if matchingScore >= matchingScoreThreshold1
34 then
35 other.matchingScore <- other.matchingScore + matchingScore
36 matchingScoreE <- matchingScoreE + matchingScore
37 printfn "Score"
38
39 ellipses.Add({ matchingScore = matchingScoreE; e = e })
40
41 member this.Ellipses : Ellipse list =
42 dprintfn "Number of ellipse: %A" ellipses.Count
43
44 (*let sortedEllipses =
45 List.filter (fun e -> e.matchingScore >= matchingScoreThreshold2) (List.ofSeq ellipses)
46 |> List.sortWith (fun e1 e2 -> e2.matchingScore.CompareTo(e1.matchingScore))*)
47
48 List.filter (fun e -> e.matchingScore >= matchingScoreThreshold2) (List.ofSeq ellipses)
49 |> List.sortWith (fun e1 e2 -> e2.matchingScore.CompareTo(e1.matchingScore))
50 |> List.map (fun { e = e } -> e)
51
52 // ellipses.Where(fun e -> e.matchingScore >= matchingScoreThreshold2)
53 // ([], fun acc { matchingScore = score; e = e } -> if score >= matchingScoreThreshold2 then e :: acc else acc)
54
55
56
57