- let sameLevelToCheck = Stack<Point>()
- let betterLevelToCheck = Stack<Point>()
- betterLevelToCheck.Push(start)
+ let sameLevelToCheck = Stack<Point> ()
+ let betterLevelToCheck = Stack<Point> ()
+ betterLevelToCheck.Push start
if not suppress.[p.Y, p.X] then
suppress.[p.Y, p.X] <- true
if not suppress.[p.Y, p.X] then
suppress.[p.Y, p.X] <- true
if notSuppressed && level = currentLevel then
suppress.[ni, nj] <- true
if notSuppressed && level = currentLevel then
suppress.[ni, nj] <- true
let inline findMaxima (img : Image<Gray, 'TDepth>) : IEnumerable<Points> when 'TDepth : unmanaged =
findExtremum img ExtremumType.Maxima
let inline findMaxima (img : Image<Gray, 'TDepth>) : IEnumerable<Points> when 'TDepth : unmanaged =
findExtremum img ExtremumType.Maxima
let imgData = img.Data
let se = [| -1, 0; 0, -1; 1, 0; 0, 1 |]
let imgData = img.Data
let se = [| -1, 0; 0, -1; 1, 0; 0, 1 |]
queue.Add (imgData.[ni, nj, 0]) p'
// Reverse order is quicker.
for i = areas.Count - 1 downto 0 do
let m = areas.[i]
if m.Elements.Count <= area && m.State <> AreaState.Removed then
queue.Add (imgData.[ni, nj, 0]) p'
// Reverse order is quicker.
for i = areas.Count - 1 downto 0 do
let m = areas.[i]
if m.Elements.Count <= area && m.State <> AreaState.Removed then
addEdgeToQueue m.Elements
let mutable intensity = if op = AreaOperation.Opening then queue.Max else queue.Min
addEdgeToQueue m.Elements
let mutable intensity = if op = AreaOperation.Opening then queue.Max else queue.Min
pixels.[e.Y, e.X] <- m
queue.Remove imgData.[e.Y, e.X, 0] e
addEdgeToQueue m'.Elements
pixels.[e.Y, e.X] <- m
queue.Remove imgData.[e.Y, e.X, 0] e
addEdgeToQueue m'.Elements
let intensityMax = if op = AreaOperation.Opening then queue.Max else queue.Min
if intensityMax <> intensity then
intensity <- intensityMax
let intensityMax = if op = AreaOperation.Opening then queue.Max else queue.Min
if intensityMax <> intensity then
intensity <- intensityMax
if ni < 0 || ni >= h || nj < 0 || nj >= w then
m.State <- AreaState.Validated
m.Intensity <- Some (intensity)
stop <- true
if ni < 0 || ni >= h || nj < 0 || nj >= w then
m.State <- AreaState.Validated
m.Intensity <- Some (intensity)
stop <- true
queue.Add (imgData.[ni, nj, 0]) p'
if queue.IsEmpty then
if m.Elements.Count + nextElements.Count <= area then
m.State <- AreaState.Validated
m.Intensity <- Some intensity'
queue.Add (imgData.[ni, nj, 0]) p'
if queue.IsEmpty then
if m.Elements.Count + nextElements.Count <= area then
m.State <- AreaState.Validated
m.Intensity <- Some intensity'
for j = 0 to w - 1 do
if not flooded.[i, j] && imgData.[i, j, 0] = byte level then
let mutable maxNeighborValue = 0uy
for j = 0 to w - 1 do
if not flooded.[i, j] && imgData.[i, j, 0] = byte level then
let mutable maxNeighborValue = 0uy
if p.X >= 0 && p.X < w && p.Y >= 0 && p.Y < h then
let v = imgData.[p.Y, p.X, 0]
if v = byte level then
if p.X >= 0 && p.X < w && p.Y >= 0 && p.Y < h then
let v = imgData.[p.Y, p.X, 0]
if v = byte level then
member val Level = 0.f with get, set
member val Surface = 0 with get, set
member this.IsInfinite = this.Surface = Int32.MaxValue
member val Level = 0.f with get, set
member val Surface = 0 with get, set
member this.IsInfinite = this.Surface = Int32.MaxValue
let ownership : Island[,] = Array2D.create h w null
// Initialize islands with their shore.
let ownership : Island[,] = Array2D.create h w null
// Initialize islands with their shore.
- let p = e.First()
- Island(comparer, Level = earth.[p.Y, p.X, 0], Surface = e.Count)
- islands.Add(island)
- let shorePoints = Points()
+ let p = e.First ()
+ Island (comparer, Level = earth.[p.Y, p.X, 0], Surface = e.Count)
+ islands.Add island
+ let shorePoints = Points ()
- let neighbor = Point(nj, ni)
- if ni >= 0 && ni < h && nj >= 0 && nj < w && Object.ReferenceEquals(ownership.[ni, nj], null) && not (shorePoints.Contains(neighbor)) then
- shorePoints.Add(neighbor) |> ignore
+ let neighbor = Point (nj, ni)
+ if ni >= 0 && ni < h && nj >= 0 && nj < w && Object.ReferenceEquals (ownership.[ni, nj], null) && not (shorePoints.Contains neighbor) then
+ shorePoints.Add neighbor |> ignore
island.Shore.Add earth.[ni, nj, 0] neighbor
for area, obj in areas do
island.Shore.Add earth.[ni, nj, 0] neighbor
for area, obj in areas do
if other = island then // During merging, some points on the shore may be owned by the island itself -> ignored.
island.Shore.RemoveNext ()
else
if other = island then // During merging, some points on the shore may be owned by the island itself -> ignored.
island.Shore.RemoveNext ()
else
stop <- true
else // We can merge 'other' into 'surface'.
island.Surface <- island.Surface + other.Surface
island.Level <- other.Level
stop <- true
else // We can merge 'other' into 'surface'.
island.Surface <- island.Surface + other.Surface
island.Level <- other.Level
for l, p in other.Shore do
let mutable currentY = p.Y + 1
while currentY < h && ownership.[currentY, p.X] = other do
ownership.[currentY, p.X] <- island
currentY <- currentY + 1
island.Shore.Add l p
for l, p in other.Shore do
let mutable currentY = p.Y + 1
while currentY < h && ownership.[currentY, p.X] = other do
ownership.[currentY, p.X] <- island
currentY <- currentY + 1
island.Shore.Add l p
if not <| ownedOrAdjacent neighbor then
island.Shore.Add earth.[ni, nj, 0] neighbor
if not stop then
if not <| ownedOrAdjacent neighbor then
island.Shore.Add earth.[ni, nj, 0] neighbor
if not stop then
- let neighborhood = List<Point>()
- let neighborsToCheck = Stack<Point>()
- neighborsToCheck.Push(Point(j, i))
+ let neighborhood = List<Point> ()
+ let neighborsToCheck = Stack<Point> ()
+ neighborsToCheck.Push (Point (j, i))
for (ni, nj) in neighbors do
let pi = n.Y + ni
let pj = n.X + nj
if pi >= 0 && pi < h && pj >= 0 && pj < w && data'.[pi, pj] = 1uy then
for (ni, nj) in neighbors do
let pi = n.Y + ni
let pj = n.X + nj
if pi >= 0 && pi < h && pj >= 0 && pj < w && data'.[pi, pj] = 1uy then
if p.X >= 0 && p.X < w && p.Y >= 0 && p.Y < h && data.[p.Y, p.X, 0] > 0uy && not (pointChecked.Contains p) then
if p.X >= 0 && p.X < w && p.Y >= 0 && p.Y < h && data.[p.Y, p.X, 0] > 0uy && not (pointChecked.Contains p) then