1
module ParasitemiaCore.ParasitesMarker
12 darkStain
: Image<Gray, byte
> // Colored pixel, it's independent of the size of the areas. It corresponds to white cells, schizontes, gametocytes, throphozoites.
13 nucleus
: Image<Gray, byte
> // Parasite nucleus. It may contain some debris. It shouldn't contain thrombocytes or larger elements.
14 cytoplasm
: Image<Gray, byte
> } // Parasite cytoplasm.
16 let find (img
: Image<Gray, float32
>) (config
: Config.Config) : Result * Image<Gray, float32
> * Image<Gray, float32
> =
18 let imgFilteredParasite = ImgTools.gaussianFilter img config
.LPFStandardDeviationParasite
20 let filteredGreenWithoutNucleus = imgFilteredParasite.Copy()
21 ImgTools.areaCloseF
filteredGreenWithoutNucleus (roundInt
config.RBCRadius.NucleusArea)
24 // We use the filtered image to find the dark stain.
25 let _, mean_fg
, mean_bg
=
26 let hist = ImgTools.histogramImg
filteredGreenWithoutNucleus 300
28 filteredGreenWithoutNucleus.Cmp(-(float mean_bg) * config.Parameters.darkStainLevel
+ (float mean_fg), CvEnum.CmpType.LessThan)
30 let marker (img
: Image<Gray, float32
>) (closed
: Image<Gray, float32
>) (level
: float) : Image<Gray, byte
> =
33 CvInvoke.Subtract(closed
, diff, diff)
34 diff._ThresholdBinary
(Gray(0.0), Gray(255.))
35 diff.Convert<Gray, byte
>()
37 let nucleusMarker = marker imgFilteredParasite filteredGreenWithoutNucleus (1. / config.Parameters.infectionSensitivity
)
39 let filteredGreenWithoutCytoplasm = imgFilteredParasite.CopyBlank()
41 let size = roundInt
(config.RBCRadius.Pixel / 5.f
)
42 if size % 2 = 0 then size + 1 else size
46 CvInvoke.GetStructuringElement(CvEnum.ElementShape.Rectangle, Size(3, 3), Point(-1, -1))
48 CvInvoke.GetStructuringElement(CvEnum.ElementShape.Ellipse, Size(kernelSize, kernelSize), Point(-1, -1))
50 CvInvoke.MorphologyEx(imgFilteredParasite, filteredGreenWithoutCytoplasm, CvEnum.MorphOp.Close, kernel, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar())
51 let cytoplasmMarker = marker imgFilteredParasite filteredGreenWithoutCytoplasm (1. / config.Parameters.cytoplasmSensitivity
)
53 { darkStain = darkStain
54 nucleus = nucleusMarker
55 cytoplasm = cytoplasmMarker },
56 filteredGreenWithoutCytoplasm,
57 filteredGreenWithoutNucleus