1
module ParasitesMarker2
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 (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 diff._ThresholdBinary
((!max).[0] * threshold
|> Gray, Gray(255.))
38 let parasitesMarker, filteredGreenWithoutParasites
= marker (int config.ParasiteArea) config.Parameters.infectionLevel
39 let stainMarker, filteredGreenWithoutStain
= marker (int config.StainArea) config.Parameters.stainLevel
41 { darkStain = darkStain
42 stain = parasitesMarker
43 infection
= stainMarker },
44 filteredGreenWithoutParasites
,
45 filteredGreenWithoutStain