cx - a, cy - a, cx + a, cy + a
// 1) Remove ellipses touching the edges.
- let ellipsesInside = ellipses |> List.map (fun e ->
- EllipseFlaggedKd (e, Removed = e.isOutside (float fg.Width) (float fg.Height)))
+ let w = float fg.Width
+ let h = float fg.Height
+ let ellipsesInside = ellipses |> List.map (fun e -> EllipseFlaggedKd (e, Removed = e.isOutside w h))
// 2) Associate touching ellipses with each ellipses.
let tree = KdTree.Tree.BuildTree ellipsesInside
let ellipsesWithNeigbors = ellipsesInside |> List.choose (fun e -> if e.Removed then None else Some (e, neighbors e))
// 3) Remove ellipse with a lower percentage of foreground.
- let fgData = fg.Data
for e, neighbors in ellipsesWithNeigbors do
let minX, minY, maxX, maxY = ellipseWindow e
if e.Contains xf yf && neighbors |> List.forall (fun (otherE, _, _) -> not <| otherE.Contains xf yf)
then
totalElement <- totalElement + 1
- if fgData.[y, x, 0] > 0uy
+ if fg.Data.[y, x, 0] > 0uy
then
fgElement <- fgElement + 1
yield sign (c.X - p.X) <> sign (c.X - p'.X) || Utils.squaredDistanceTwoPoints c p' > Utils.squaredDistanceTwoPoints c p // 'false' -> the point is owned by another ellipse.
} |> Seq.forall id
-
ellipsesWithNeigbors
|> List.choose (fun (e, neighbors) ->
if e.Removed