Cleaning and some little tweaks.
[master-thesis.git] / Parasitemia / ParasitemiaCore / Ellipse.fs
index 4e48230..db23ece 100644 (file)
@@ -14,6 +14,9 @@ open Config
 open MatchingEllipses
 open Const
 
+// This is a ratio of the biggest radius.
+let minimumDistanceBetweenDrawnPoints = 0.6
+
 /// <summary>
 /// Try to build an ellipse from three points and two tangents passing by the first and the second point.
 /// 'Ellipse.A' is always equal or greater than Ellipse.B.
@@ -76,28 +79,17 @@ let ellipse (p1x: float) (p1y: float) (m1: float) (p2x: float) (p2y: float) (m2:
 
 
 let private vectorRotation (p1x: float32) (p1y: float32) (v1x: float32) (v1y: float32) (px: float32) (py: float32) : float32 =
-    let mutable rotation = 1.f
     if p1y > py
     then
-        if v1x > 0.f
-        then
-            rotation <- -1.f
+        if v1x > 0.f then -1.f else 1.f
     elif p1y < py
     then
-        if v1x < 0.f
-        then
-            rotation <- -1.f
+        if v1x < 0.f then -1.f else 1.f
     elif p1x > px
     then
-        if v1y < 0.f
-        then
-            rotation <- -1.f
-    elif p1x < px
-    then
-        if v1y > 0.f
-        then
-            rotation <- -1.f
-    rotation
+        if v1y < 0.f then -1.f else 1.f
+    else // p1x < px
+        if v1y > 0.f then -1.f else 1.f
 
 let private areVectorsValid (p1x: float32) (p1y: float32) (p2x: float32) (p2y: float32) (v1x: float32) (v1y: float32) (v2x: float32) (v2y: float32) : (float32 * float32) option =
     let m1 = -v1x / v1y
@@ -125,9 +117,9 @@ let private areVectorsValid (p1x: float32) (p1y: float32) (p2x: float32) (p2y: f
 
         if diff > PI || (diff < 0.f && diff > -PI)
         then
-            None
+            Some (m1, m2)
         else
-        Some (m1, m2)
+            None
 
 let find (edges: Matrix<byte>)
          (xGradient: Matrix<float32>)
@@ -145,7 +137,7 @@ let find (edges: Matrix<byte>)
 
     let radiusTolerance = (r2 - r1) * 0.2f
 
-    let squaredMinimumDistance = (float r2 / 1.5) ** 2.
+    let squaredMinimumDistance = (float config.RBCRadius.Pixel * minimumDistanceBetweenDrawnPoints) ** 2.
     let inline squaredDistance x1 y1 x2 y2 = (x1 - x2) ** 2. + (y1 - y2) ** 2.
 
     let h = edges.Height