Change the way the dark stain is marked.
[master-thesis.git] / Parasitemia / ParasitemiaCore / ParasitesMarker.fs
index 0d7c7ae..2b70682 100644 (file)
@@ -27,7 +27,7 @@ let find (img: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gr
         let _, mean_fg, mean_bg =
             let hist = histogramImg imgWithoutNucleus 300
             otsu hist
-        imgWithoutNucleus.Cmp(-(float mean_bg) * config.Parameters.darkStainLevel + (float mean_fg), CvEnum.CmpType.LessThan)
+        imgWithoutNucleus.Cmp(float mean_fg - config.Parameters.darkStainLevel * float (mean_bg - mean_fg), CvEnum.CmpType.LessThan)
 
     let marker (img: Image<Gray, float32>) (closed: Image<Gray, float32>) (level: float) : Image<Gray, byte> =
         let diff = img.Copy()
@@ -36,11 +36,13 @@ let find (img: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gr
         diff._ThresholdBinary(Gray(0.0), Gray(255.))
         diff.Convert<Gray, byte>()
 
+    // Nucleus.
     let nucleusMarker = marker img imgWithoutNucleus (1. / config.Parameters.infectionSensitivity)
 
+    // Cytoplasm.
     let imgWithoutParasite = img.CopyBlank()
     let kernelSize =
-        let size = roundInt (config.RBCRadius.Pixel / 5.f)
+        let size = roundInt config.RBCRadius.CytoplasmSize
         if size % 2 = 0 then size + 1 else size
     use kernel =
         if kernelSize <= 3