From: Greg Burri Date: Fri, 11 Dec 2015 20:40:51 +0000 (+0100) Subject: Remove ellipses touching the edges. X-Git-Tag: 1.0.11~83 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=d9a6e072ecf299db691c05bb559a71265f812ba3;p=master-thesis.git Remove ellipses touching the edges. --- diff --git a/Parasitemia/Parasitemia/Classifier.fs b/Parasitemia/Parasitemia/Classifier.fs index 6441635..24ea4a7 100644 --- a/Parasitemia/Parasitemia/Classifier.fs +++ b/Parasitemia/Parasitemia/Classifier.fs @@ -14,5 +14,18 @@ type Cell = { center: Point elements: Matrix } +type KdEllipse (e: Types.Ellipse) = + inherit Types.Ellipse (e.Cx, e.Cy, e.A, e.B, e.Alpha) + + interface KdTree.I2DCoords with + member this.X = this.Cx + member this.Y = this.Cy + + let findCells (ellipses: Types.Ellipse list) (parasites: ParasitesMarker.Result) (fg: Image) : Cell list = - [] \ No newline at end of file + if ellipses.IsEmpty + then + [] + else + let tree = KdTree.Tree.buildTree (ellipses |> List.map KdEllipse) + [] \ No newline at end of file diff --git a/Parasitemia/Parasitemia/EEOver.fs b/Parasitemia/Parasitemia/EEOver.fs index 81bdbf8..640d752 100644 --- a/Parasitemia/Parasitemia/EEOver.fs +++ b/Parasitemia/Parasitemia/EEOver.fs @@ -716,4 +716,6 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float * float[] * f | 3 -> threeintpts xint yint a1 b1 phi_1 a2 b2 h2_tr k2_tr phi_2 aa bb cc dd ee ff | 4 -> fourintpts xint yint a1 b1 phi_1 a2 b2 h2_tr k2_tr phi_2 aa bb cc dd ee ff | _ -> -1.0 - Some (area, xint.[..nintpts-1], yint.[..nintpts-1]) \ No newline at end of file + if nintpts = 0 + then Some (area, [||], [||]) + else Some (area, xint.[..nintpts-1], yint.[..nintpts-1]) \ No newline at end of file diff --git a/Parasitemia/Parasitemia/ImageAnalysis.fs b/Parasitemia/Parasitemia/ImageAnalysis.fs index 21616af..feb427d 100644 --- a/Parasitemia/Parasitemia/ImageAnalysis.fs +++ b/Parasitemia/Parasitemia/ImageAnalysis.fs @@ -98,7 +98,10 @@ let doAnalysis (img: Image) (config: Config) : Classifier.Cell list = let windowSize = roundInt (1.6 * (snd radiusRange)) let factorNbPick = 1.5 let ellipses = logTime "Finding ellipses" (fun () -> - Ellipse.find edges xEdges yEdges radiusRange windowSize factorNbPick) + Ellipse.find edges xEdges yEdges radiusRange windowSize factorNbPick) |> List.filter (fun e -> not (e.CutAVericalLine 0.0) && + not (e.CutAVericalLine (float img.Width)) && + not (e.CutAnHorizontalLine 0.0) && + not (e.CutAnHorizontalLine (float img.Height))) drawEllipses img ellipses (Bgr(0.0, 255.0, 255.0)) //saveImg img "ellipses.png" diff --git a/Parasitemia/Parasitemia/MatchingEllipses.fs b/Parasitemia/Parasitemia/MatchingEllipses.fs index 9b870dc..0964953 100644 --- a/Parasitemia/Parasitemia/MatchingEllipses.fs +++ b/Parasitemia/Parasitemia/MatchingEllipses.fs @@ -89,8 +89,6 @@ type MatchingEllipses (radiusMin: float) = other.Removed <- true ellipses.RemoveAll(fun e -> e.Removed) |> ignore - dprintfn "Number of ellipse: %A" ellipses.Count - List.ofSeq ellipses |> List.map (fun e -> e.Ellipse) diff --git a/Parasitemia/Parasitemia/Program.fs b/Parasitemia/Parasitemia/Program.fs index 46e870f..b44c65f 100644 --- a/Parasitemia/Parasitemia/Program.fs +++ b/Parasitemia/Parasitemia/Program.fs @@ -55,16 +55,17 @@ do //use img = new Image("../../../../src/Tests_hough/images/rbc_single_oblong_4.png") //use img = new Image("../../../../src/Tests_hough/images/strange_rbc_1.png") //use img = new Image("../../../../src/Tests_hough/images/rbc_single_blurred.png") - //use img = new Image("../../../../src/Tests_hough/images/lot.png") + use img = new Image("../../../../src/Tests_hough/images/lot.png") ///// PARASITES ///// - use img = new Image("../../../../src/Parasites/images/1.png") + //use img = new Image("../../../../src/Parasites/images/1.png") // KdTree.test3 () // Utils.dprintfn "area: %A" area - let result = ImageAnalysis.doAnalysis img config + let result = Utils.logTime "Total" (fun () -> + ImageAnalysis.doAnalysis img config ) display mainWindow img mainWindow.Root.Show() diff --git a/Parasitemia/Parasitemia/Types.fs b/Parasitemia/Parasitemia/Types.fs index 589a735..f96573d 100644 --- a/Parasitemia/Parasitemia/Types.fs +++ b/Parasitemia/Parasitemia/Types.fs @@ -12,4 +12,16 @@ type Ellipse (cx: float, cy: float, a: float, b: float, alpha: float) = // Does the ellipse contain the point (x, y)?. member this.Contains x y = - ((x - cx) * cos alpha + (y - cy) * sin alpha) ** 2.0 / a ** 2.0 + ((x - cx) * sin alpha - (y - cy) * cos alpha) ** 2.0 / b ** 2.0 <= 1.0 \ No newline at end of file + ((x - cx) * cos alpha + (y - cy) * sin alpha) ** 2.0 / a ** 2.0 + ((x - cx) * sin alpha - (y - cy) * cos alpha) ** 2.0 / b ** 2.0 <= 1.0 + + // A line is defined as : y = mx + l + member this.CutALine (m: float) (l: float) : bool = + -2.0 * l ** 2.0 + a ** 2.0 + m ** 2.0 * a ** 2.0 + b ** 2.0 + m ** 2.0 * b ** 2.0 - + 4.0 * m * l * cx - 2.0 * m ** 2.0 * cx ** 2.0 + 4.0 * l * cy + 4.0 * m * cx * cy - + 2.0 * cy ** 2.0 + (-1.0 + m ** 2.0) * (a ** 2.0 - b ** 2.0) * cos (2.0 * alpha) - 2.0 * m * (a ** 2.0 - b ** 2.0) * sin (2.0 * alpha) > 0.0 + + member this.CutAVericalLine (y: float) : bool = + a ** 2.0 + b ** 2.0 - 2.0 * y ** 2.0 + 4.0 * y * cx - 2.0 * cx ** 2.0 + a ** 2.0 * cos (2.0 * alpha) - b ** 2.0 * cos (2.0 * alpha) > 0.0 + + member this.CutAnHorizontalLine (x: float) : bool = + a ** 2.0 + b ** 2.0 - 2.0 * x ** 2.0 + 4.0 * x * cy - 2.0 * cy ** 2.0 - a ** 2.0 * cos (2.0 * alpha) + b ** 2.0 * cos (2.0 * alpha) > 0.0 \ No newline at end of file