From 4147bfad3c85dcf4fe7d291abf7d356379d88b4f Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 13 Jan 2016 22:49:40 +0100 Subject: [PATCH] Use real unit (um and ppi) instead of pixel in the parameters. --- Parasitemia/Parasitemia/App.config | 2 +- Parasitemia/Parasitemia/Config.fs | 51 +++++++++++++++++++-- Parasitemia/Parasitemia/GUI/GUI.fs | 1 - Parasitemia/Parasitemia/GUI/MainWindow.xaml | 2 +- Parasitemia/Parasitemia/MainAnalysis.fs | 26 ++++++----- Parasitemia/Parasitemia/Parasitemia.fsproj | 8 ++-- Parasitemia/Parasitemia/Program.fs | 26 +---------- Parasitemia/Parasitemia/UnitsOfMeasure.fs | 18 ++++++++ 8 files changed, 87 insertions(+), 47 deletions(-) create mode 100644 Parasitemia/Parasitemia/UnitsOfMeasure.fs diff --git a/Parasitemia/Parasitemia/App.config b/Parasitemia/Parasitemia/App.config index 06fd2b0..4be2caf 100644 --- a/Parasitemia/Parasitemia/App.config +++ b/Parasitemia/Parasitemia/App.config @@ -1,7 +1,7 @@  - + diff --git a/Parasitemia/Parasitemia/Config.fs b/Parasitemia/Parasitemia/Config.fs index e583160..9c23d83 100644 --- a/Parasitemia/Parasitemia/Config.fs +++ b/Parasitemia/Parasitemia/Config.fs @@ -3,19 +3,24 @@ open System open Const +open UnitsOfMeasure type Debug = | DebugOff | DebugOn of string // Output directory. type Parameters = { - initialAreaOpen: int // Area of the first initial opening to remove the central illumination of RBC. - ratioSecondAreaOpen: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'. + rbcDiameter: float<μm> + resolution: float + + ratioAreaPaleCenter: float32 // The area of the second opening is 'ratioSecondAreaOpen' * mean RBC area. It's applied only if greater than 'initialAreaOpen'. + + granulometryRange: float32 // The radius will be seeked from radius - granulometryRange * radius to radius + granulometryRange * radius. minRbcRadius: float32 // Factor of the mean RBC radius. maxRbcRadius: float32 // Factor of the mean RBC radius. - preFilterSigma: float // To remove the high frequency noise. + LPFStandardDeviation: float<μm> // Sigma parameter of the gaussian to remove the high frequency noise. // Ellipse. factorNbPick: float // The number of computed ellipse per edge pixel. @@ -35,12 +40,49 @@ type Parameters = { minimumCellAreaFactor: float32 // Factor of the mean RBC area. } +let defaultParameters = { + rbcDiameter = 8.<μm> + resolution = 200.e3 // Correspond to 50X. + + ratioAreaPaleCenter = 1.f / 3.f // The ratio between an RBC area and the area of the its pale center. + + granulometryRange = 0.5f + + minRbcRadius = -0.3f + maxRbcRadius = 0.3f + + LPFStandardDeviation = 0.2<μm> // 8.5e-6. + + factorNbPick = 1.0 + + darkStainLevel = 0.25 // 0.3 + maxDarkStainRatio = 0.1 // 10 % + + infectionArea = 0.012f // 1.2 % + infectionLevel = 1.12 // Lower -> more sensitive. + + stainArea = 0.08f // 8 % + stainLevel = 1.1 // Lower -> more sensitive. + maxStainRatio = 0.12 // 12 % + + standardDeviationMaxRatio = 0.5 // 0.5 + minimumCellAreaFactor = 0.4f } + type Config (param: Parameters) = + let initialRBCRadius : float32 = + let rbcRadiusInch: float = μm.ConvertToInch(param.rbcDiameter) / 2. + let rbcRadiusPx: float = param.resolution * rbcRadiusInch + float32 rbcRadiusPx + member this.Parameters = param member val Debug = DebugOff with get, set + member this.LPFStandardDeviation = + let stdDeviation: float = μm.ConvertToInch(param.LPFStandardDeviation) * param.resolution + float stdDeviation + // Mean RBC radius. - member val RBCRadius = 30.f with get, set + member val RBCRadius : float32 = initialRBCRadius with get, set member this.RBCMinRadius = this.RBCRadius + param.minRbcRadius * this.RBCRadius member this.RBCMaxRadius = this.RBCRadius + param.maxRbcRadius * this.RBCRadius @@ -53,3 +95,4 @@ type Config (param: Parameters) = member this.Copy () = this.MemberwiseClone() :?> Config + diff --git a/Parasitemia/Parasitemia/GUI/GUI.fs b/Parasitemia/Parasitemia/GUI/GUI.fs index 62670e6..a7bed54 100644 --- a/Parasitemia/Parasitemia/GUI/GUI.fs +++ b/Parasitemia/Parasitemia/GUI/GUI.fs @@ -61,7 +61,6 @@ let run (defaultConfig: Config) = let y = rbc.center.Y - rbcHeight / 2. |> Utils.roundInt let w = Utils.roundInt rbcWidth let h = Utils.roundInt rbcHeight - //Utils.dprintfn "w: %A, h: %A, cx: %A, cy: %A, img.w: %A, img.h: %A" w h x y img.Width img.Height img.GetSubRect(System.Drawing.Rectangle(System.Drawing.Point((if x < 0 then 0 else x), (if y < 0 then 0 else y)), System.Drawing.Size((if x + w >= img.Width then img.Width - x else w), (if y + h >= img.Height then img.Height - y else h)))) diff --git a/Parasitemia/Parasitemia/GUI/MainWindow.xaml b/Parasitemia/Parasitemia/GUI/MainWindow.xaml index 49203c6..b24b48c 100644 --- a/Parasitemia/Parasitemia/GUI/MainWindow.xaml +++ b/Parasitemia/Parasitemia/GUI/MainWindow.xaml @@ -17,7 +17,7 @@ - + diff --git a/Parasitemia/Parasitemia/MainAnalysis.fs b/Parasitemia/Parasitemia/MainAnalysis.fs index 2be9be1..7f55c7c 100644 --- a/Parasitemia/Parasitemia/MainAnalysis.fs +++ b/Parasitemia/Parasitemia/MainAnalysis.fs @@ -13,8 +13,8 @@ open ImgTools open Config open Types - let doAnalysis (img: Image) (name: string) (config: Config) (reportProgress: (int -> unit) option) : Cell list = + // To report the progress of this function from 0 to 100. let inline report (percent: int) = match reportProgress with | Some f -> f percent @@ -22,22 +22,25 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr use green = img.Item(1) let greenFloat = green.Convert() - let filteredGreen = gaussianFilter greenFloat (float config.Parameters.preFilterSigma) + let filteredGreen = gaussianFilter greenFloat config.LPFStandardDeviation - logTime "areaOpen 1" (fun () -> ImgTools.areaOpenF filteredGreen config.Parameters.initialAreaOpen) + let initialAreaOpening = int<| config.RBCArea * config.Parameters.ratioAreaPaleCenter + logTime "Area opening number one" (fun () -> ImgTools.areaOpenF filteredGreen initialAreaOpening) report 8 - let r1 = logTime "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert()) (10, 80) 0.5 |> float32) - // let r2 = logTime "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen (10, 80) |> float32) + let range = + let delta = config.Parameters.granulometryRange * config.RBCRadius + int <| config.RBCRadius - delta, int <| config.RBCRadius + delta + //let r1 = logTime "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert()) range 1.0 |> float32) + let r2 = logTime "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen range |> float32) // log (sprintf "r1: %A, r2: %A" r1 r2) - config.RBCRadius <- r1 + config.RBCRadius <- r2 report 24 - let secondAreaOpen = int <| config.RBCArea * config.Parameters.ratioSecondAreaOpen - - if secondAreaOpen > config.Parameters.initialAreaOpen + let secondAreaOpening = int <| config.RBCArea * config.Parameters.ratioAreaPaleCenter + if secondAreaOpening > initialAreaOpening then - logTime "areaOpen 2" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpen) + logTime "Area opening number two" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpening) let parasites, filteredGreenWhitoutStain = ParasitesMarker.find filteredGreen config //let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker.findMa greenFloat filteredGreenFloat config @@ -83,7 +86,7 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr drawCells imgCells' true cells saveImg imgCells' (buildFileName " - cells - full.png") - let filteredGreenMaxima = gaussianFilter greenFloat config.Parameters.preFilterSigma + let filteredGreenMaxima = gaussianFilter greenFloat config.LPFStandardDeviation for m in ImgTools.findMaxima filteredGreenMaxima do ImgTools.drawPoints filteredGreenMaxima m 255.f saveImg filteredGreenMaxima (buildFileName " - filtered - maxima.png") @@ -103,7 +106,6 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr cells - // ID * cell radius * cell list. let doMultipleAnalysis (imgs: (string * Image) list) (config : Config) (reportProgress: (int -> unit) option) : (string * float * Cell list) list = let inline report (percent: int) = diff --git a/Parasitemia/Parasitemia/Parasitemia.fsproj b/Parasitemia/Parasitemia/Parasitemia.fsproj index 865840f..590c8ea 100644 --- a/Parasitemia/Parasitemia/Parasitemia.fsproj +++ b/Parasitemia/Parasitemia/Parasitemia.fsproj @@ -9,7 +9,7 @@ WinExe Parasitemia Parasitemia - v4.6.1 + v4.5.2 true 4.4.0.0 Parasitemia @@ -51,7 +51,7 @@ bin\Release\ TRACE 3 - x64 + AnyCPU bin\Release\Parasitemia.XML false --folder "../../../Images/release" --output "../../../Images/output" --debug @@ -75,6 +75,7 @@ + @@ -187,7 +188,8 @@ - xcopy "D:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x64" "$(TargetDir)x64" /Y /D /I + xcopy "D:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x64" "$(TargetDir)x64" /Y /D /I +xcopy "D:\Emgu\emgucv-windows-universal 3.0.0.2157\bin\x86" "$(TargetDir)x86" /Y /D /I