X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FEllipse.fs;h=33333bf57d91dd7408e00d942fa63ad83d6127cc;hp=128c823180838f6a5de2538d9d8fbb7c52ef744c;hb=84fdf7404133803fdf0dc867a4da68a144975191;hpb=10afa9a402eb88c8e073fe8b0d607faa25230eef diff --git a/Parasitemia/Parasitemia/Ellipse.fs b/Parasitemia/Parasitemia/Ellipse.fs index 128c823..33333bf 100644 --- a/Parasitemia/Parasitemia/Ellipse.fs +++ b/Parasitemia/Parasitemia/Ellipse.fs @@ -46,8 +46,8 @@ let private goldenSectionSearch (f: float -> float) (nbIter: int) (xmin: float) // Ellipse.A is always equal or greater than Ellipse.B. // Ellipse.Alpha is between 0 and Pi. let ellipse (p1x: float) (p1y: float) (m1: float) (p2x: float) (p2y: float) (m2: float) (p3x: float) (p3y: float) : Types.Ellipse option = - let accuracy_extremum_search_1 = 4 - let accuracy_extremum_search_2 = 3 + let accuracy_extremum_search_1 = 8 // 3 + let accuracy_extremum_search_2 = 8 // 4 // p3 as the referencial. let p1x = p1x - p3x @@ -178,26 +178,39 @@ let private areVectorsValid (p1x: float) (p1y: float) (p2x: float) (p2y: float) let b1 = -m1 * p1x + p1y let b2 = -m2 * p2x + p2y - let px = -((b1 - b2)/(m1 - m2)) - let py = -((m2 * b1 - m1 * b2)/(m1 - m2)) + let px = -((b1 - b2) / (m1 - m2)) + let py = -((m2 * b1 - m1 * b2) / (m1 - m2)) let rot1 = vectorRotation p1x p1y v1x v1y px py let rot2 = vectorRotation p2x p2y v2x v2y px py - if rot1 = rot2 || rot1 * atan2 (p1y - py) (p1x - px) + rot2 * atan2 (p2y - py) (p2x - px) <= 0.0 + if rot1 = rot2 then None else + let alpha1 = atan2 (p1y - py) (p1x - px) + let alpha2 = atan2 (p2y - py) (p2x - px) + + let alpha1' = if alpha1 < 0.0 then 2.0 * Math.PI + alpha1 else alpha1 + let alpha2' = if alpha2 < 0.0 then 2.0 * Math.PI + alpha2 else alpha2 + + let diff = rot1 * alpha1' + rot2 * alpha2' + + if diff > Math.PI || (diff < 0.0 && diff > -Math.PI) + then + None + else Some (m1, m2) + let find (edges: Matrix) (xDir: Image) (yDir: Image) (config: Config) : MatchingEllipses = - let r1, r2 = config.scale * config.minRBCSize, config.scale * config.maxRBCSize - let windowSize = roundInt (config.factorWindowSize * r2) - let factorNbPick = config.factorNbPick + let r1, r2 = config.Parameters.scale * config.RBCMin, config.Parameters.scale * config.RBCMax // FIXME: scale factor should be applied in Config!? + let windowSize = roundInt (config.Parameters.factorWindowSize * r2) + let factorNbPick = config.Parameters.factorNbPick let increment = windowSize / 4 @@ -262,6 +275,8 @@ let find (edges: Matrix) match ellipse p1xf p1yf m1 p2xf p2yf m2 p3xf p3yf with | Some e when e.Cx > 0.0 && e.Cx < (float w) - 1.0 && e.Cy > 0.0 && e.Cy < (float h) - 1.0 && e.A >= r1 - radiusTolerance && e.A <= r2 + radiusTolerance && e.B >= r1 - radiusTolerance && e.B <= r2 + radiusTolerance -> + + let prout = areVectorsValid p1xf p1yf p2xf p2yf -xDirData.[p1y, p1x, 0] -yDirData.[p1y, p1x, 0] -xDirData.[p2y, p2x, 0] -yDirData.[p2y, p2x, 0] ellipses.Add e | _ -> () | _ -> ()