+ // 3) Remove ellipses touching the edges.
+ for e in ellipses do
+ if e.isOutside w h then e.Removed <- true
+
+ // 4) Remove ellipses with little area.
+ for e, neighbors in ellipsesWithNeigbors do
+ if not e.Removed
+ then
+ let minX, minY, maxX, maxY = ellipseWindow e
+
+ let mutable area = 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 fg.Data.[y, x, 0] > 0uy &&
+ e.Contains xf yf &&
+ neighbors |> List.forall (fun (otherE, _, _) -> otherE.Removed || not <| otherE.Contains xf yf)
+ then
+ area <- area + 1
+
+ if area < config.minimumCellArea
+ then
+ e.Removed <- true
+
+ // 5) Define pixels associated to each ellipse and create the cells.