+ 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> =
+ use filteredGreenWithoutInfection = filteredGreen.Copy()
+ ImgTools.areaCloseF filteredGreenWithoutInfection (int config.RBCRadius.InfectionArea)
+
+ let filteredGreenWithoutStain = filteredGreenWithoutInfection.Copy()
+ ImgTools.areaCloseF filteredGreenWithoutStain (int config.RBCRadius.StainArea)
+
+ let darkStain =
+ // We use the filtered image to find the dark stain.
+ let _, mean_fg, mean_bg =
+ let hist = ImgTools.histogramImg filteredGreenWithoutInfection 300
+ ImgTools.otsu hist
+ filteredGreenWithoutInfection.Cmp(-(float mean_bg) * config.Parameters.darkStainLevel + (float mean_fg), CvEnum.CmpType.LessThan)
+
+ let marker (img: Image<Gray, float32>) (closed: Image<Gray, float32>) (level: float) : Image<Gray, byte> =
+ let diff = img.Copy()
+ diff._Mul(level)
+ CvInvoke.Subtract(closed, diff, diff)
+ diff._ThresholdBinary(Gray(0.0), Gray(255.))
+ diff.Convert<Gray, byte>()
+
+ let infectionMarker = marker filteredGreen filteredGreenWithoutInfection (1. / config.Parameters.infectionSensitivity)
+ let stainMarker = marker filteredGreenWithoutInfection filteredGreenWithoutStain (1. / config.Parameters.stainSensitivity)
+
+ // TODO: comprendre pourquoi des valeurs sont negatives!?!?
+ (*
+ let blackTopHat = filteredGreen.CopyBlank()
+ CvInvoke.Subtract(filteredGreenWithoutInfection, filteredGreen, blackTopHat)
+ ImgTools.saveImg (ImgTools.normalizeAndConvert blackTopHat) "BottomHat.png"
+ *)