1
module ParasitesMarker2
9 darkStain
: Image<Gray, byte
>
10 infection
: Image<Gray, byte
>
11 stain
: 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 (filteredGreen
: Image<Gray, byte
>) (filteredGreenFloat
: Image<Gray, float32
>) (kmediansResult
: KMedians.Result) (config
: Config.Config) : Result * Image<Gray, byte
> * Image<Gray, byte
> =
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
.Parameters.darkStainLevel
, CvEnum.CmpType.GreaterThan)
22 darkStain._And
(filteredGreenFloat
.Cmp(median_fg
, CvEnum.CmpType.LessThan))
24 let marker (area
: int) (threshold
: float) : Image<Gray, byte
> * Image<Gray, byte
> =
25 let closed = filteredGreen
.Copy()
26 ImgTools.areaClose
closed area
27 let diff = closed - filteredGreen
29 let min = ref [| 0. |]
30 let minLocation = ref <| [| Point() |]
31 let max = ref [| 0. |]
32 let maxLocation = ref <| [| Point() |]
33 diff.MinMax(min, max, minLocation, maxLocation)
35 let valueThreshold = if (!max).[0] * threshold
< 0.1 * (median_bg
- median_fg
) then 0.1 * (median_bg
- median_fg
) else (!max).[0] * threshold
37 diff._ThresholdBinary
(Gray(valueThreshold), Gray(255.))
40 let infectionMarker, filteredGreenWithoutInfection
= marker (int config.InfectionArea) config.Parameters.infectionLevel
41 let stainMarker, filteredGreenWithoutStain
= marker (int config.StainArea) config.Parameters.stainLevel
43 { darkStain = darkStain
44 infection
= infectionMarker
45 stain = stainMarker },
46 filteredGreenWithoutInfection
,
47 filteredGreenWithoutStain