Change the parasite detection method.
[master-thesis.git] / Parasitemia / Parasitemia / ParasitesMarker.fs
index e422b04..d1a51fa 100644 (file)
@@ -14,31 +14,28 @@ type Result = {
 // * '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 green = ImgTools.gaussianFilter green 1.0
+(*let find (green: Image<Gray, float32>) (filteredGreen: Image<Gray, float32>) (kmediansResult: KMedians.Result) (config: Config.Config) : Result =
 
     // 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 darkStain = d_fg.Cmp(median_bg * config.darkStainLevel, CvEnum.CmpType.GreaterThan)
+    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)
 
     let fgFloat = (fg / 255.0).Convert<Gray, float32>()
-    let greenWithoutBg = green.Copy()
+    use greenWithoutBg = ImgTools.gaussianFilter green 1.0
     greenWithoutBg.SetValue(Gray(0.0), fg.Not())
 
     let findSmears (sigma: float) (level: float) : Image<Gray, byte> =
-        let greenWithoutBgSmoothed = ImgTools.gaussianFilter greenWithoutBg sigma
-        let fgSmoothed = ImgTools.gaussianFilter fgFloat sigma
-
+        use greenWithoutBgSmoothed = ImgTools.gaussianFilter greenWithoutBg sigma
+        use fgSmoothed = ImgTools.gaussianFilter fgFloat sigma
         let smears = (greenWithoutBg.Mul(fgSmoothed)).Cmp(greenWithoutBgSmoothed.Mul(level), CvEnum.CmpType.LessThan)
         smears._And(fg)
         smears
 
     { darkStain = darkStain;
-      stain = findSmears config.stainSigma config.stainLevel
-      infection = findSmears config.infectionSigma config.infectionLevel }
+      stain = findSmears config.Parameters.stainSigma config.Parameters.stainLevel
+      infection = findSmears config.Parameters.infectionSigma config.Parameters.infectionLevel }*)