- let neighbors (e: Ellipse) : (EllipseFlaggedKd * PointD * PointD) list =
- tree.Search (searchRegion e)
- // We only keep the ellipses touching 'e'.
- |> List.choose (fun otherE ->
- match EEOver.EEOverlapArea e otherE with
- | Some (area, px, py) when area > 0.0 && px.Length >= 2 && py.Length >= 2 ->
- Some (otherE, PointD(px.[0], py.[0]), PointD(px.[1], py.[1]))
- | _ ->
- None )
-
- let ellipsesWithNeigbors = ellipses |> List.choose (fun e -> if e.Removed then None else Some (e, neighbors e))
-
- // 2) Remove ellipses with a lower percentage of foreground. (taken from the lower score to the highest).
- for e, neighbors in List.rev ellipsesWithNeigbors do
- let minX, minY, maxX, maxY = ellipseWindow e
-
- let mutable totalElement = 0
- let mutable fgElement = 0
- for y in (if minY < 0 then 0 else minY) .. (if maxY >= fg.Height then fg.Height - 1 else maxY) do
- for x in (if minX < 0 then 0 else minX) .. (if maxX >= fg.Width then fg.Width - 1 else maxX) do
- let yf, xf = float y, float x
- if e.Contains xf yf && neighbors |> List.forall (fun (otherE, _, _) -> otherE.Removed || not <| otherE.Contains xf yf)
- then
- totalElement <- totalElement + 1
- if fg.Data.[y, x, 0] > 0uy
- then
- fgElement <- fgElement + 1
-
- if (float fgElement) / (float totalElement) < config.percentageOfFgValidCell