1
module ParasitesMarker
9 darkStain
: Image<Gray, byte
>
10 stain
: Image<Gray, byte
>
11 infection
: Image<Gray, byte
> }
13 // Create three binary markers :
14 // * 'Dark stain' corresponds to the colored pixel, it's independent of the size of the areas.
15 // * 'Stain' corresponds to the stain around the parasites.
16 // * 'Infection' corresponds to the parasite. It shouldn't contain thrombocytes.
17 let find (green
: Image<Gray, float32
>) (filteredGreen
: Image<Gray, float32
>) (kmediansResult
: KMedians.Result) (config
: Config.Config) : Result =
19 // We use the filtered image to find the dark stain.
20 let { KMedians.fg
= fg
; KMedians.median_bg
= median_bg
; KMedians.median_fg
= median_fg
; KMedians.d_fg
= d_fg
} = kmediansResult
21 let darkStain = d_fg
.Cmp(median_bg
* config
.darkStainLevel
, CvEnum.CmpType.GreaterThan)
22 darkStain._And
(filteredGreen
.Cmp(median_fg
, CvEnum.CmpType.LessThan))
25 let fgFloat = (fg
/ 255.0).Convert<Gray, float32
>()
26 use greenWithoutBg = ImgTools.gaussianFilter green
1.0
27 greenWithoutBg.SetValue(Gray(0.0), fg
.Not())
29 let findSmears (sigma
: float) (level
: float) : Image<Gray, byte
> =
30 use greenWithoutBgSmoothed = ImgTools.gaussianFilter
greenWithoutBg sigma
31 use fgSmoothed = ImgTools.gaussianFilter
fgFloat sigma
32 let smears = (greenWithoutBg.Mul(fgSmoothed)).Cmp(greenWithoutBgSmoothed.Mul(level
), CvEnum.CmpType.LessThan)
36 { darkStain = darkStain;
37 stain = findSmears config.stainSigma
config.stainLevel
38 infection
= findSmears config.infectionSigma
config.infectionLevel
}