member this.Y = this.Cy
-let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker2.Result) (img: Image<Gray, byte>) (config: Config.Config) : Cell list =
+let findCells (ellipses: Ellipse list) (parasites: ParasitesMarker.Result) (img: Image<Gray, byte>) (config: Config.Config) : Cell list =
if ellipses.IsEmpty
then
[]
sqrt (((float sumCoords_x) / (float nbElement) - e.Cx) ** 2.0 + ((float sumCoords_y) / (float nbElement) - e.Cy) ** 2.0) > e.A * config.maxOffcenter *)
then
Peculiar
- elif infectedPixels.Count > config.Parameters.parasitePixelsRequired
+ elif infectedPixels.Count >= 1
then
let infectionToRemove = ImgTools.connectedComponents parasites.stain infectedPixels
for p in infectionToRemove do
maxDarkStainRatio: float
stainArea: float // Factor of a RBC area. 0.5 means the half of RBC area.
- stainLevel: float // [0, 2]
+ stainLevel: float // > 1
maxStainRatio: float // [0, 1]
infectionArea: float // Factor of a RBC area. 0.5 means the half of RBC area.
- infectionLevel: float // [0, 2]
- parasitePixelsRequired: int
+ infectionLevel: float // > 1
standardDeviationMaxRatio: float // The standard deviation of the pixel values of a cell can't be greater than standardDeviationMaxRatio * global standard deviation
minimumCellArea: float // Factor of RBC area.
let filteredGreenFloat = filteredGreen.Convert<Gray, float32>() // Is it neccessary?
- let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker2.find filteredGreen filteredGreenFloat config
+ let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker.find filteredGreen filteredGreenFloat config
+ //let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker.findMa greenFloat filteredGreenFloat config
let filteredGreenWhitoutInfectionFloat = filteredGreenWhitoutInfection.Convert<Gray, float32>()
let filteredGreenWhitoutStainFloat = filteredGreenWhitoutStain.Convert<Gray, float32>()
<Compile Include="Config.fs" />
<Compile Include="KMedians.fs" />
<Compile Include="EEOver.fs" />
- <Compile Include="ParasitesMarker2.fs" />
<Compile Include="ParasitesMarker.fs" />
<Compile Include="KdTree.fs" />
<Compile Include="MatchingEllipses.fs" />
module ParasitesMarker
open System.Drawing
+open System.Linq
open Emgu.CV
open Emgu.CV.Structure
+open Utils
type Result = {
darkStain: Image<Gray, byte>
- stain: Image<Gray, byte>
- infection: Image<Gray, byte> }
+ infection: Image<Gray, byte>
+ stain: Image<Gray, byte> }
+
// Create three binary markers :
// * 'Dark stain' corresponds to the colored pixel, it's independent of the size of the areas.
// * 'Stain' corresponds to the stain around the parasites.
// * 'Infection' corresponds to the parasite. It shouldn't contain thrombocytes.
-(*let find (green: Image<Gray, float32>) (filteredGreen: Image<Gray, float32>) (kmediansResult: KMedians.Result) (config: Config.Config) : Result =
+let findMa (green: Image<Gray, float32>) (filteredGreen: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gray, byte> * Image<Gray, byte> =
// We use the filtered image to find the dark stain.
- let { KMedians.fg = fg; KMedians.median_bg = median_bg; KMedians.median_fg = median_fg; KMedians.d_fg = d_fg } = kmediansResult
+ let kmediansResults = logTime "Finding fg/bg (k-medians)" (fun () -> KMedians.kmedians filteredGreen 1.0)
+ let { KMedians.fg = fg; KMedians.median_bg = median_bg; KMedians.median_fg = median_fg; KMedians.d_fg = d_fg } = kmediansResults
let darkStain = d_fg.Cmp(median_bg * config.Parameters.darkStainLevel, CvEnum.CmpType.GreaterThan)
darkStain._And(filteredGreen.Cmp(median_fg, CvEnum.CmpType.LessThan))
darkStain._And(fg)
smears._And(fg)
smears
+ let tmp = filteredGreen.Convert<Gray, byte>()
+
{ darkStain = darkStain;
- stain = findSmears config.Parameters.stainSigma config.Parameters.stainLevel
- infection = findSmears config.Parameters.infectionSigma config.Parameters.infectionLevel }*)
+ stain = findSmears 10. 0.9
+ infection = findSmears 2.2 0.87 },
+ tmp,
+ tmp
+
+
+// Create three binary markers :
+// * 'Dark stain' corresponds to the colored pixel, it's independent of the size of the areas.
+// * 'Stain' corresponds to the stain around the parasites.
+// * 'Infection' corresponds to the parasite. It shouldn't contain thrombocytes.
+let find (filteredGreen: Image<Gray, byte>) (filteredGreenFloat: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gray, byte> * Image<Gray, byte> =
+
+ let filteredGreenWithoutInfection = filteredGreen.Copy()
+ ImgTools.areaClose filteredGreenWithoutInfection (int config.InfectionArea)
+
+ let filteredGreenWithoutStain = filteredGreenWithoutInfection.Copy()
+ ImgTools.areaClose filteredGreenWithoutStain (int config.StainArea)
+
+ // We use the filtered image to find the dark stain.
+ let kmediansResults = logTime "Finding fg/bg (k-medians)" (fun () -> KMedians.kmedians (filteredGreenWithoutInfection.Convert<Gray, float32>()) 1.0) // FIXME: avoid converting again this in MainAnalysis
+ let { KMedians.fg = fg; KMedians.median_bg = median_bg; KMedians.median_fg = median_fg; KMedians.d_fg = d_fg } = kmediansResults
+ let darkStain = d_fg.Cmp(median_bg * config.Parameters.darkStainLevel, CvEnum.CmpType.GreaterThan)
+ darkStain._And(filteredGreenWithoutInfection.Cmp(median_fg, CvEnum.CmpType.LessThan))
+
+ let marker (img: Image<Gray, byte>) (closed: Image<Gray, byte>) (level: float) : Image<Gray, byte> =
+ let diff = closed - (img * level)
+ diff._ThresholdBinary(Gray(0.0), Gray(255.))
+ diff
+
+ let infectionMarker = marker filteredGreen filteredGreenWithoutInfection config.Parameters.infectionLevel
+ let stainMarker = marker filteredGreenWithoutInfection filteredGreenWithoutStain config.Parameters.stainLevel
+
+ { darkStain = darkStain
+ infection = infectionMarker
+ stain = stainMarker },
+ filteredGreenWithoutInfection,
+ filteredGreenWithoutStain
+
+
+
+
+++ /dev/null
-module ParasitesMarker2
-
-open System.Drawing
-open System.Linq
-
-open Emgu.CV
-open Emgu.CV.Structure
-
-open Utils
-
-type Result = {
- darkStain: Image<Gray, byte>
- infection: Image<Gray, byte>
- stain: Image<Gray, byte> }
-
-// Create three binary markers :
-// * 'Dark stain' corresponds to the colored pixel, it's independent of the size of the areas.
-// * 'Stain' corresponds to the stain around the parasites.
-// * 'Infection' corresponds to the parasite. It shouldn't contain thrombocytes.
-let find (filteredGreen: Image<Gray, byte>) (filteredGreenFloat: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gray, byte> * Image<Gray, byte> =
-
- let filteredGreenWithoutInfection = filteredGreen.Copy()
- ImgTools.areaClose filteredGreenWithoutInfection (int config.InfectionArea)
-
- let filteredGreenWithoutStain = filteredGreenWithoutInfection.Copy()
- ImgTools.areaClose filteredGreenWithoutStain (int config.StainArea)
-
- // We use the filtered image to find the dark stain.
- let kmediansResults = logTime "Finding fg/bg (k-medians)" (fun () -> KMedians.kmedians (filteredGreenWithoutInfection.Convert<Gray, float32>()) 1.0) // FIXME: avoid converting again this in MainAnalysis
- let { KMedians.fg = fg; KMedians.median_bg = median_bg; KMedians.median_fg = median_fg; KMedians.d_fg = d_fg } = kmediansResults
- let darkStain = d_fg.Cmp(median_bg * config.Parameters.darkStainLevel, CvEnum.CmpType.GreaterThan)
- darkStain._And(filteredGreenWithoutInfection.Cmp(median_fg, CvEnum.CmpType.LessThan))
-
- let marker (img: Image<Gray, byte>) (closed: Image<Gray, byte>) (level: float) : Image<Gray, byte> =
- let diff = closed - img
-
- let min = ref [| 0. |]
- let minLocation = ref <| [| Point() |]
- let max = ref [| 0. |]
- let maxLocation = ref <| [| Point() |]
- diff.MinMax(min, max, minLocation, maxLocation)
- let max = (!max).[0]
-
- let threshold = 0.2 * max
- let diff' = diff - threshold
-
- let m = MathNet.Numerics.Statistics.StreamingStatistics.Mean(seq {
- for m in ImgTools.findMaxima diff' do
- let p = m.First()
- yield diff'.Data.[p.Y, p.X, 0] |> float }) + threshold
-
- let valueThreshold = m * level
-
- diff._ThresholdBinary(Gray(valueThreshold), Gray(255.))
- diff
-
- let infectionMarker = marker filteredGreen filteredGreenWithoutInfection config.Parameters.infectionLevel
- let stainMarker = marker filteredGreenWithoutInfection filteredGreenWithoutStain config.Parameters.stainLevel
-
- { darkStain = darkStain
- infection = infectionMarker
- stain = stainMarker },
- filteredGreenWithoutInfection,
- filteredGreenWithoutStain
-
-
-
-
-
maxDarkStainRatio = 0.1
infectionArea = 0.012 // 1.2 %
- infectionLevel = 0.85
- parasitePixelsRequired = 1
+ infectionLevel = 1.12 // Lower -> more sensitive.
- stainArea = 0.08
- stainLevel = 0.85
+ stainArea = 0.08 // 8 %
+ stainLevel = 1.1 // Lower -> more sensitive.
maxStainRatio = 0.12 // 12 %
standardDeviationMaxRatio = 0.55