-let ellipse (p1x: float) (p1y: float) (m1: float) (p2x: float) (p2y: float) (m2: float) (p3x: float) (p3y: float) : Types.Ellipse option =
- let p0 = pointFromTwoLines (Types.Line(float32 m1, float32 (p1y - m1 * p1x))) (Types.Line(float32 m2, float32(p2y - m2 * p2x)))
+let ellipse (p1x : float) (p1y : float) (m1 : float) (p2x : float) (p2y : float) (m2 : float) (p3x : float) (p3y : float) : Types.Ellipse option =
+ let p0 = pointFromTwoLines (Types.Line (float32 m1, float32 (p1y - m1 * p1x))) (Types.Line (float32 m2, float32(p2y - m2 * p2x)))
let v0 = matrix [[ 1.; p0x; p0y ]]
let v1 = matrix [[ 1.; p1x; p1y ]]
let v2 = matrix [[ 1.; p2x; p2y ]]
let v3 = matrix [[ 1.; p3x; p3y ]]
let v0 = matrix [[ 1.; p0x; p0y ]]
let v1 = matrix [[ 1.; p1x; p1y ]]
let v2 = matrix [[ 1.; p2x; p2y ]]
let v3 = matrix [[ 1.; p3x; p3y ]]
- let p = (v3.Stack(v1).Stack(v2).Determinant() * v0).Stack(v0.Stack(v3).Stack(v2).Determinant() * v1).Stack(v0.Stack(v1).Stack(v3).Determinant() * v2).Transpose()
- let conicMat = p * s.Inverse() * p.Transpose()
+ let p = (v3.Stack(v1).Stack(v2).Determinant () * v0).Stack(v0.Stack(v3).Stack(v2).Determinant () * v1).Stack(v0.Stack(v1).Stack(v3).Determinant () * v2).Transpose ()
+ let conicMat = p * s.Inverse () * p.Transpose ()
let eigenValues = eigen.EigenValues
let lambda = eigenValues.[1].Real
let mu = eigenValues.[0].Real
let eigenValues = eigen.EigenValues
let lambda = eigenValues.[1].Real
let mu = eigenValues.[0].Real
let phi' = if phi < 0. then phi + Math.PI else phi
let majorAxis, minorAxis = if r1 > r2 then r1, r2 else r2, r1
let phi' = if phi < 0. then phi + Math.PI else phi
let majorAxis, minorAxis = if r1 > r2 then r1, r2 else r2, r1
- Some (Types.Ellipse(float32 cx, float32 cy, float32 majorAxis, float32 minorAxis, float32 phi'))
+ Some (Types.Ellipse (float32 cx, float32 cy, float32 majorAxis, float32 minorAxis, float32 phi'))
-let find (edges: Matrix<byte>)
- (xGradient: Matrix<float32>)
- (yGradient: Matrix<float32>)
- (config: Config) : MatchingEllipses =
+let find (edges : Matrix<byte>)
+ (xGradient : Matrix<float32>)
+ (yGradient : Matrix<float32>)
+ (config : Config) : MatchingEllipses =
let r1, r2 = config.RBCRadius.Min, config.RBCRadius.Max
let incrementWindowDivisor = 4.f
let r1, r2 = config.RBCRadius.Min, config.RBCRadius.Max
let incrementWindowDivisor = 4.f
let edgesData = edges.Data
let xDirData = xGradient.Data
let yDirData = yGradient.Data
let edgesData = edges.Data
let xDirData = xGradient.Data
let yDirData = yGradient.Data
for window_i in -windowSize + increment .. increment .. h - increment do
for window_j in -windowSize + increment .. increment .. w - increment do
for window_i in -windowSize + increment .. increment .. h - increment do
for window_j in -windowSize + increment .. increment .. w - increment do
- let indexFirstElement = currentElements.FindIndex(fun p -> p.X >= window_j_begin)
- if indexFirstElement > 0
- then currentElements.RemoveRange(0, indexFirstElement)
+ let indexFirstElement = currentElements.FindIndex (fun p -> p.X >= window_j_begin)
+ if indexFirstElement > 0 then
+ currentElements.RemoveRange (0, indexFirstElement)
// Add the new elements.
let newElemsBegin_j = window_j + windowSize - increment
let newElemsEnd_j = window_j + windowSize - 1
// Add the new elements.
let newElemsBegin_j = window_j + windowSize - increment
let newElemsEnd_j = window_j + windowSize - 1
- for j in (if newElemsBegin_j < 0 then 0 else newElemsBegin_j) .. (if newElemsEnd_j >= w then w - 1 else newElemsEnd_j) do
- for i in window_i_begin .. window_i_end do
- if edgesData.[i, j] = 1uy
- then currentElements.Add(Point(j, i))
+ for j = (if newElemsBegin_j < 0 then 0 else newElemsBegin_j) to (if newElemsEnd_j >= w then w - 1 else newElemsEnd_j) do
+ for i = window_i_begin to window_i_end do
+ if edgesData.[i, j] = 1uy then
+ currentElements.Add (Point (j, i))
let mutable nbOfPicks = (float currentElements.Count) * factorNbMaxPick |> int
let mutable nbOfValidPicks = (float currentElements.Count) * factorNbValidPick |> int
while nbOfPicks > 0 && nbOfValidPicks > 0 do
let mutable nbOfPicks = (float currentElements.Count) * factorNbMaxPick |> int
let mutable nbOfValidPicks = (float currentElements.Count) * factorNbValidPick |> int
while nbOfPicks > 0 && nbOfValidPicks > 0 do
- let p1 = currentElements.[rng.Next(currentElements.Count)]
- let p2 = currentElements.[rng.Next(currentElements.Count)]
- let p3 = currentElements.[rng.Next(currentElements.Count)]
- if p1 <> p2 && p1 <> p3 && p2 <> p3
- then
+ let p1 = currentElements.[rng.Next currentElements.Count]
+ let p2 = currentElements.[rng.Next currentElements.Count]
+ let p3 = currentElements.[rng.Next currentElements.Count]
+ if p1 <> p2 && p1 <> p3 && p2 <> p3 then
nbOfPicks <- nbOfPicks - 1
let p1yf, p1xf = float p1.Y, float p1.X
let p2yf, p2xf = float p2.Y, float p2.X
nbOfPicks <- nbOfPicks - 1
let p1yf, p1xf = float p1.Y, float p1.X
let p2yf, p2xf = float p2.Y, float p2.X