Cleaning.
[master-thesis.git] / Parasitemia / Parasitemia / ParasitesMarker2.fs
index 03af2b6..17a032d 100644 (file)
@@ -7,8 +7,8 @@ open Emgu.CV.Structure
 
 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.
@@ -32,16 +32,18 @@ let find (filteredGreen: Image<Gray, byte>) (filteredGreenFloat: Image<Gray, flo
         let maxLocation = ref <| [| Point() |]
         diff.MinMax(min, max, minLocation, maxLocation)
 
-        diff._ThresholdBinary((!max).[0] * threshold |> Gray, Gray(255.))
+        let valueThreshold = if (!max).[0] * threshold < 0.1 * (median_bg - median_fg) then 0.1 * (median_bg - median_fg) else (!max).[0] * threshold
+
+        diff._ThresholdBinary(Gray(valueThreshold), Gray(255.))
         diff, closed
 
-    let parasitesMarker, filteredGreenWithoutParasites  = marker (int config.ParasiteArea) config.Parameters.infectionLevel
+    let infectionMarker, filteredGreenWithoutInfection  = marker (int config.InfectionArea) config.Parameters.infectionLevel
     let stainMarker, filteredGreenWithoutStain = marker (int config.StainArea) config.Parameters.stainLevel
 
     { darkStain = darkStain
-      stain = parasitesMarker
-      infection = stainMarker },
-    filteredGreenWithoutParasites,
+      infection = infectionMarker
+      stain = stainMarker },
+    filteredGreenWithoutInfection,
     filteredGreenWithoutStain