+ 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, float32>) (config: Config.Config) : Result * Image<Gray, float32> * Image<Gray, float32> =
+
+ let filteredGreenWithoutInfection = filteredGreen.Copy()
+ ImgTools.areaCloseF filteredGreenWithoutInfection (int config.InfectionArea)
+
+ let filteredGreenWithoutStain = filteredGreenWithoutInfection.Copy()
+ ImgTools.areaCloseF filteredGreenWithoutStain (int config.StainArea)
+
+ // We use the filtered image to find the dark stain.
+
+ // With K-Means.
+ let kmeansResults = logTime "Finding fg/bg (k-means)" (fun () -> KMeans.kmeans (filteredGreenWithoutInfection) 1.0)
+ let { KMeans.mean_bg = value_bg; KMeans.mean_fg = value_fg; KMeans.d_fg = d_fg } = kmeansResults
+
+ // With K-Medians.
+ (* let kmediansResults = logTime "Finding fg/bg (k-medians)" (fun () -> KMedians.kmedians (filteredGreenWithoutInfection) 1.0) // FIXME: avoid converting this again in MainAnalysis
+ let { KMedians.median_bg = value_bg; KMedians.median_fg = value_fg; KMedians.d_fg = d_fg } = kmediansResults *)
+
+ let darkStain = d_fg.Cmp(value_bg * config.Parameters.darkStainLevel, CvEnum.CmpType.GreaterThan)
+ darkStain._And(filteredGreenWithoutInfection.Cmp(value_fg, CvEnum.CmpType.LessThan))
+
+ let marker (img: Image<Gray, float32>) (closed: Image<Gray, float32>) (level: float) : Image<Gray, byte> =
+ let diff = closed - (img * level)
+ diff._ThresholdBinary(Gray(0.0), Gray(255.))
+ diff.Convert<Gray, byte>()