Fix a bug during area opening/closing when the area value may become negative.
[master-thesis.git] / Parasitemia / ParasitemiaCore / ImgTools.fs
index dd06649..abc8714 100644 (file)
@@ -612,6 +612,7 @@ type Island (cmp: IComparer<float32>) =
     member val Shore = Heap.Heap<float32, Point>(cmp) with get
     member val Level = 0.f with get, set
     member val Surface = 0 with get, set
+    member this.IsInfinite = this.Surface = Int32.MaxValue
 
 let private areaOperationF (img: Image<Gray, float32>) (areas: (int * 'a) list) (f: ('a -> float32 -> unit) option) (op: AreaOperation) =
     let w = img.Width
@@ -666,7 +667,7 @@ let private areaOperationF (img: Image<Gray, float32>) (areas: (int * 'a) list)
                 else
                     if not <| Object.ReferenceEquals(other, null)
                     then // We touching another island.
-                        if island.Surface + other.Surface >= area
+                        if island.IsInfinite || other.IsInfinite || island.Surface + other.Surface >= area
                         then
                             stop <- true
                         else // We can merge 'other' into 'surface'.