From: Greg Burri Date: Mon, 1 Feb 2016 16:07:06 +0000 (+0100) Subject: Remove the removing of cells bases on standard deviation. X-Git-Tag: 1.0.11~18 X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=commitdiff_plain;h=ec96e4c38dd6beaf22b4e2a2ebb87248fea6f209 Remove the removing of cells bases on standard deviation. --- diff --git a/Parasitemia/ParasitemiaCore/Analysis.fs b/Parasitemia/ParasitemiaCore/Analysis.fs index e83977a..f7e7b1c 100644 --- a/Parasitemia/ParasitemiaCore/Analysis.fs +++ b/Parasitemia/ParasitemiaCore/Analysis.fs @@ -103,7 +103,7 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr let! prunedEllipses = logTimeWithName "Ellipses pruning" (fun () -> reportWithVal 80 (matchingEllipses.PrunedEllipses)) - let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites img_RBC_filtered config)) + let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites img.Width img.Height config)) logWithName "Analysis finished" diff --git a/Parasitemia/ParasitemiaCore/Classifier.fs b/Parasitemia/ParasitemiaCore/Classifier.fs index f4b0844..0012a4f 100644 --- a/Parasitemia/ParasitemiaCore/Classifier.fs +++ b/Parasitemia/ParasitemiaCore/Classifier.fs @@ -19,7 +19,7 @@ type private EllipseFlaggedKd (e: Ellipse) = member this.X = this.Cx member this.Y = this.Cy -let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: Image) (config: Config.Config) : Cell list = +let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (width: int) (height: int) (config: Config.Config) : Cell list = if ellipses.IsEmpty then [] @@ -36,11 +36,6 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: let a = int (e.A + 0.5f) cx - a, cy - a, cx + a, cy + a - let w = img.Width - let w_f = float32 w - let h = img.Height - let h_f = float32 h - // Return 'true' if the point 'p' is owned by e. // The lines represents all intersections with other ellipses. let pixelOwnedByE (p: PointF) (e: Ellipse) (others: (Ellipse * Line) list) = @@ -100,11 +95,13 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: let ellipsesWithNeigbors = ellipses |> List.map (fun e -> e, neighbors e) |> List.rev // 2) Remove ellipses touching the edges. + let widthF, heightF = float32 width, float32 height for e in ellipses do - if e.isOutside w_f h_f then e.Removed <- true + if e.isOutside widthF heightF then e.Removed <- true // 3) Remove ellipses with a high standard deviation (high contrast). - let imgData = img.Data + // Obsolete. It was useful when the ellipses result quality wasn't good. + (* let imgData = img.Data let globalStdDeviation = MathNet.Numerics.Statistics.Statistics.PopulationStandardDeviation(seq { for y in 0 .. h - 1 do for x in 0 .. w - 1 do @@ -124,7 +121,7 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: yield float imgData.[y, x, 0] }) if stdDeviation > globalStdDeviation * config.Parameters.standardDeviationMaxRatio then - e.Removed <- true + e.Removed <- true *) // 4) Remove ellipses with little area. let minArea = config.RBCRadius.MinArea @@ -134,8 +131,8 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: let minX, minY, maxX, maxY = ellipseWindow e let mutable area = 0 - for y in (if minY < 0 then 0 else minY) .. (if maxY >= h then h - 1 else maxY) do - for x in (if minX < 0 then 0 else minX) .. (if maxX >= w then w - 1 else maxX) do + for y in (if minY < 0 then 0 else minY) .. (if maxY >= height then height - 1 else maxY) do + for x in (if minX < 0 then 0 else minX) .. (if maxX >= width then width - 1 else maxX) do let p = PointF(float32 x, float32 y) if pixelOwnedByE p e (neighbors |> List.choose (fun (otherE, p1, p2) -> if otherE.Removed then None else Some (otherE :> Ellipse, Utils.lineFromTwoPoints p1 p2))) then @@ -146,7 +143,7 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: e.Removed <- true // 5) Define pixels associated to each ellipse and create the cells. - let perimeterParasiteSquared = (2.f * config.RBCRadius.ParasiteRadius) ** 2.f |> roundInt + let diameterParasiteSquared = (2.f * config.RBCRadius.ParasiteRadius) ** 2.f |> roundInt let minimumParasiteArea = config.RBCRadius.MinimumParasiteArea |> roundInt let nucleusData = parasites.nucleus.Copy().Data // Will be modified thus the copy. @@ -192,7 +189,7 @@ let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: if nucleusPixels.Count > 0 then for parasitePixel in parasitePixels do - if nucleusPixels.Exists(fun p -> pown (p.X - parasitePixel.X) 2 + pown (p.Y - parasitePixel.Y) 2 <= perimeterParasiteSquared) + if nucleusPixels.Exists(fun p -> pown (p.X - parasitePixel.X) 2 + pown (p.Y - parasitePixel.Y) 2 <= diameterParasiteSquared) then parasiteArea <- parasiteArea + 1 diff --git a/Parasitemia/ParasitemiaCore/Config.fs b/Parasitemia/ParasitemiaCore/Config.fs index 21a36f9..18c64cc 100644 --- a/Parasitemia/ParasitemiaCore/Config.fs +++ b/Parasitemia/ParasitemiaCore/Config.fs @@ -41,7 +41,7 @@ type Parameters = { nucleusAreaRatio: float32 // Factor of a RBC area. 0.5 means the half of RBC area. infectionSensitivity: float // between 0 (the least sensitive) and 1 (the most sensitive). - standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation + // [] standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation minimumCellAreaFactor: float32 } // Factor of the mean RBC area. A cell with an area below this will be rejected. let defaultParameters = { @@ -74,7 +74,7 @@ let defaultParameters = { nucleusAreaRatio = 0.01f // 1.0 % infectionSensitivity = 0.92 - standardDeviationMaxRatio = 0.6 + // standardDeviationMaxRatio = 0.6 // Obsolete. minimumCellAreaFactor = 0.4f } type RBCRadius (radius: float32, parameters: Parameters) = diff --git a/Parasitemia/ParasitemiaCore/Ellipse.fs b/Parasitemia/ParasitemiaCore/Ellipse.fs index e95cf27..01e1bec 100644 --- a/Parasitemia/ParasitemiaCore/Ellipse.fs +++ b/Parasitemia/ParasitemiaCore/Ellipse.fs @@ -122,6 +122,9 @@ let private areVectorsValid (p1x: float32) (p1y: float32) (p2x: float32) (p2y: f else None +/// +/// Build a set of ellipses as a 'MatchingEllipses' object by finding ellipses with the given edges and gradient. +/// let find (edges: Matrix) (xGradient: Matrix) (yGradient: Matrix)