44da9011d3b17ab2a458bf030ff2938aeb5466d8
1
module ParasitesMarker
9 darkStain
: Image<Gray, byte
>
10 stain
: Image<Gray, byte
>
11 infection
: Image<Gray, byte
> }
13 let find (green
: Image<Gray, float32
>) (filteredGreen
: Image<Gray, float32
>) (config
: Config.Config) : Result =
15 // We use the filtered image to find the dark stain.
16 let { KMedians.fg
= fg
; KMedians.median_bg
= median_bg
; KMedians.median_fg
= median_fg
; KMedians.d_fg
= d_fg
} = KMedians.kmedians
filteredGreen 1.0
17 let darkStain = d_fg
.Cmp(median_bg
* config
.darkStainLevel
, CvEnum.CmpType.GreaterThan)
18 darkStain._And
(filteredGreen.Cmp(median_fg
, CvEnum.CmpType.LessThan))
21 let fgFloat = (fg
/ 255.0).Convert<Gray, float32
>()
22 let greenWithoutBg = green
.Copy()
23 greenWithoutBg.SetValue(Gray(0.0), fg
.Not())
25 let findSmears (sigma
: float) (level
: float) : Image<Gray, byte
> =
26 let greenWithoutBgSmoothed = ImgTools.gaussianFilter
greenWithoutBg sigma
27 let fgSmoothed = ImgTools.gaussianFilter
fgFloat sigma
29 let smears = (greenWithoutBg.Mul(fgSmoothed)).Cmp(greenWithoutBgSmoothed.Mul(level
), CvEnum.CmpType.LessThan)
33 { darkStain = darkStain;
34 stain
= findSmears config.stainSigma
config.stainLevel
35 infection
= findSmears config.infectionSigma
config.infectionLevel
}