X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FMatchingEllipses.fs;fp=Parasitemia%2FParasitemia%2FMatchingEllipses.fs;h=e4eae8dc192c30218aba070feabfda573e5af379;hb=ba64921fb9a0c36cd8cf802cbf1b2c0f79bc25f6;hp=0000000000000000000000000000000000000000;hpb=0ff8fb82457bd5a858b2218ab07f69c81323537e;p=master-thesis.git diff --git a/Parasitemia/Parasitemia/MatchingEllipses.fs b/Parasitemia/Parasitemia/MatchingEllipses.fs new file mode 100644 index 0000000..e4eae8d --- /dev/null +++ b/Parasitemia/Parasitemia/MatchingEllipses.fs @@ -0,0 +1,57 @@ +module MatchingEllipses + +open System +open System.Linq +open System.Collections.Generic + +open Types +open Utils + + +type EllipseScore = { mutable matchingScore: float; e: Ellipse } + +let matchingScoreThreshold1 = 0.5 +let matchingScoreThreshold2 = 2.0 + +let ellipseArea e = e.a * e.b * Math.PI + +type MatchingEllipses () = + let ellipses = List() + + member this.Add (e: Ellipse) = + + // dprintfn "new ellipse: %A, nb: %A" e ellipses.Count + + let areaE = ellipseArea e + + let mutable matchingScoreE = 0.0 + + for other in ellipses do + let areaOther = ellipseArea other.e + let commonArea = EEOver.EEOverlapArea e other.e + let matchingScore = (2.0 * commonArea / (areaE + areaOther)) ** 2.0 + if matchingScore >= matchingScoreThreshold1 + then + other.matchingScore <- other.matchingScore + matchingScore + matchingScoreE <- matchingScoreE + matchingScore + printfn "Score" + + ellipses.Add({ matchingScore = matchingScoreE; e = e }) + + member this.Ellipses : Ellipse list = + dprintfn "Number of ellipse: %A" ellipses.Count + + (*let sortedEllipses = + List.filter (fun e -> e.matchingScore >= matchingScoreThreshold2) (List.ofSeq ellipses) + |> List.sortWith (fun e1 e2 -> e2.matchingScore.CompareTo(e1.matchingScore))*) + + List.filter (fun e -> e.matchingScore >= matchingScoreThreshold2) (List.ofSeq ellipses) + |> List.sortWith (fun e1 e2 -> e2.matchingScore.CompareTo(e1.matchingScore)) + |> List.map (fun { e = e } -> e) + + // ellipses.Where(fun e -> e.matchingScore >= matchingScoreThreshold2) + // ([], fun acc { matchingScore = score; e = e } -> if score >= matchingScoreThreshold2 then e :: acc else acc) + + + +