module ParasitesMarker open System.Drawing open Emgu.CV open Emgu.CV.Structure type Result = { darkStain: Image stain: Image infection: Image } // 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 (green: Image) (filteredGreen: Image) (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.Parameters.darkStainLevel, CvEnum.CmpType.GreaterThan) darkStain._And(filteredGreen.Cmp(median_fg, CvEnum.CmpType.LessThan)) darkStain._And(fg) let fgFloat = (fg / 255.0).Convert() use greenWithoutBg = ImgTools.gaussianFilter green 1.0 greenWithoutBg.SetValue(Gray(0.0), fg.Not()) let findSmears (sigma: float) (level: float) : Image = 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.Parameters.stainSigma config.Parameters.stainLevel infection = findSmears config.Parameters.infectionSigma config.Parameters.infectionLevel }*)