e422b04d92fa4fbd92ea56b1d3b382cad4fc36f0
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 let green = ImgTools.gaussianFilter
green 1.0
21 // We use the filtered image to find the dark stain.
22 let { KMedians.fg
= fg
; KMedians.median_bg
= median_bg
; KMedians.median_fg
= median_fg
; KMedians.d_fg
= d_fg
} = kmediansResult
23 let darkStain = d_fg
.Cmp(median_bg
* config
.darkStainLevel
, CvEnum.CmpType.GreaterThan)
24 darkStain._And
(filteredGreen
.Cmp(median_fg
, CvEnum.CmpType.LessThan))
27 let fgFloat = (fg
/ 255.0).Convert<Gray, float32
>()
28 let greenWithoutBg = green.Copy()
29 greenWithoutBg.SetValue(Gray(0.0), fg
.Not())
31 let findSmears (sigma
: float) (level
: float) : Image<Gray, byte
> =
32 let greenWithoutBgSmoothed = ImgTools.gaussianFilter
greenWithoutBg sigma
33 let fgSmoothed = ImgTools.gaussianFilter
fgFloat sigma
35 let smears = (greenWithoutBg.Mul(fgSmoothed)).Cmp(greenWithoutBgSmoothed.Mul(level
), CvEnum.CmpType.LessThan)
39 { darkStain = darkStain;
40 stain = findSmears config.stainSigma
config.stainLevel
41 infection
= findSmears config.infectionSigma
config.infectionLevel
}