From: Greg Burri Date: Fri, 29 Jan 2016 23:44:49 +0000 (+0100) Subject: More homogeneous ellipse density. X-Git-Tag: 1.0.11~24 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=bb642da712542095d8c5ead2d0d036470eb040b9;p=master-thesis.git More homogeneous ellipse density. --- diff --git a/Parasitemia/ParasitemiaCore/Config.fs b/Parasitemia/ParasitemiaCore/Config.fs index 5e3280c..b721b70 100644 --- a/Parasitemia/ParasitemiaCore/Config.fs +++ b/Parasitemia/ParasitemiaCore/Config.fs @@ -24,7 +24,9 @@ type Parameters = { LPFStandardDeviationRBC: float<μm> // Ellipse. - factorNbPick: float // The number of computed ellipse per edge pixel. + nbPickElementsMin: int + factorNbValidPick: float // The number of computed ellipse per edge pixel. + factorNbMaxPick: float // Parasites detection. darkStainLevel: float // Lower -> more sensitive. Careful about illumination on the borders. @@ -55,7 +57,9 @@ let defaultParameters = { LPFStandardDeviationParasite = 0.15<μm> LPFStandardDeviationRBC = 0.22<μm> - factorNbPick = 1.0 + nbPickElementsMin = 10 + factorNbValidPick = 0.05 //1.0 + factorNbMaxPick = 2. darkStainLevel = 0.25 maxDarkStainRatio = 0.1 // 10 % diff --git a/Parasitemia/ParasitemiaCore/Ellipse.fs b/Parasitemia/ParasitemiaCore/Ellipse.fs index db23ece..cf55a8e 100644 --- a/Parasitemia/ParasitemiaCore/Ellipse.fs +++ b/Parasitemia/ParasitemiaCore/Ellipse.fs @@ -131,7 +131,9 @@ let find (edges: Matrix) // We choose a window size for which the biggest ellipse can always be fitted in. let windowSize = roundInt (2.f * r2) - let factorNbPick = config.Parameters.factorNbPick + let factorNbValidPick = config.Parameters.factorNbValidPick + let factorNbMaxPick = config.Parameters.factorNbMaxPick + let nbPickElementsMin = config.Parameters.nbPickElementsMin let increment = windowSize / (int incrementWindowDivisor) @@ -180,8 +182,9 @@ let find (edges: Matrix) if currentElements.Count >= 10 then - let mutable nbOfPicks = (float currentElements.Count) * factorNbPick |> int - while nbOfPicks > 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)] @@ -200,7 +203,8 @@ let find (edges: Matrix) match ellipse p1xf p1yf (float m1) p2xf p2yf (float m2) p3xf p3yf with | Some e when e.Cx > 0.f && e.Cx < w_f - 1.f && e.Cy > 0.f && e.Cy < h_f - 1.f && e.A >= r1 - radiusTolerance && e.A <= r2 + radiusTolerance && e.B >= r1 - radiusTolerance && e.B <= r2 + radiusTolerance -> - ellipses.Add e + nbOfValidPicks <- nbOfValidPicks - 1 + ellipses.Add e | _ -> () | _ -> () diff --git a/Parasitemia/ParasitemiaCore/KdTree.fs b/Parasitemia/ParasitemiaCore/KdTree.fs index 4513208..3a60977 100644 --- a/Parasitemia/ParasitemiaCore/KdTree.fs +++ b/Parasitemia/ParasitemiaCore/KdTree.fs @@ -65,10 +65,10 @@ type Tree<'a when 'a :> I2DCoords> = buildTreeFromSortedArray xSorted ySorted 1 member this.Search (searchRegion: Region) : 'a list = - let rec valuesFrom (tree: Tree<'a>) : 'a list = + let rec valuesFrom (tree: Tree<'a>) (acc: 'a list) : 'a list = match tree with - | Node (_, part1, part2) -> (valuesFrom part1) @ (valuesFrom part2) - | Leaf v -> [v] + | Node (_, left, right) -> (valuesFrom right (valuesFrom left acc)) + | Leaf v -> v :: acc let rec searchWithRegion (tree: Tree<'a>) (currentRegion: Region) (depth: int) : 'a list = match tree with @@ -77,7 +77,7 @@ type Tree<'a when 'a :> I2DCoords> = let valuesInRegion (region: Region) (treeRegion: Tree<'a>) = if region.IsSub searchRegion then - valuesFrom treeRegion + valuesFrom treeRegion [] elif region.Intersects searchRegion then searchWithRegion treeRegion region (depth + 1) diff --git a/Parasitemia/ParasitemiaCore/UnitsOfMeasure.fs b/Parasitemia/ParasitemiaCore/UnitsOfMeasure.fs index 637f49e..ec343ea 100644 --- a/Parasitemia/ParasitemiaCore/UnitsOfMeasure.fs +++ b/Parasitemia/ParasitemiaCore/UnitsOfMeasure.fs @@ -6,12 +6,12 @@ [] type inch [] type ppi = px / inch // Pixel per inch. -let μmInchRatio = 25.4e3<μm/inch> -let mmInchRatio = 25.4 +let μmPerInch = 25.4e3<μm/inch> +let mmPerInch = 25.4 -let μmToInch(x: float<μm>) : float = x / μmInchRatio -let inchToμm(x: float) : float<μm> = x * μmInchRatio +let μmToInch(x: float<μm>) : float = x / μmPerInch +let inchToμm(x: float) : float<μm> = x * μmPerInch -let mmToInch(x: float) : float = x / mmInchRatio -let inchTomm(x: float) : float = x * mmInchRatio +let mmToInch(x: float) : float = x / mmPerInch +let inchTomm(x: float) : float = x * mmPerInch