Cleaning + renaming.
[master-thesis.git] / Parasitemia / ParasitemiaCore / ParasitesMarker.fs
index e3c3ca2..6c25d04 100644 (file)
@@ -7,25 +7,24 @@ open Emgu.CV
 open Emgu.CV.Structure
 
 open Utils
+open ImgTools
 
 type Result = {
     darkStain: Image<Gray, byte> // Colored pixel, it's independent of the size of the areas. It corresponds to white cells, schizontes, gametocytes, throphozoites.
     nucleus: Image<Gray, byte> // Parasite nucleus. It may contain some debris. It shouldn't contain thrombocytes or larger elements.
-    cytoplasm: Image<Gray, byte> } // Parasite cytoplasm.
+    parasite: Image<Gray, byte> } // The whole parasites.
 
 let find (img: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gray, float32> * Image<Gray, float32> =
 
-    let imgFilteredParasite = ImgTools.gaussianFilter img config.LPFStandardDeviationParasite
-
-    let filteredGreenWithoutNucleus = imgFilteredParasite.Copy()
-    ImgTools.areaCloseF filteredGreenWithoutNucleus (roundInt config.RBCRadius.NucleusArea)
+    let imgWithoutNucleus = img.Copy()
+    areaCloseF imgWithoutNucleus (roundInt config.RBCRadius.NucleusArea)
 
     let darkStain =
         // We use the filtered image to find the dark stain.
         let _, mean_fg, mean_bg =
-            let hist = ImgTools.histogramImg filteredGreenWithoutNucleus 300
-            ImgTools.otsu hist
-        filteredGreenWithoutNucleus.Cmp(-(float mean_bg) * config.Parameters.darkStainLevel + (float mean_fg), CvEnum.CmpType.LessThan)
+            let hist = histogramImg imgWithoutNucleus 300
+            otsu hist
+        imgWithoutNucleus.Cmp(-(float mean_bg) * config.Parameters.darkStainLevel + (float mean_fg), CvEnum.CmpType.LessThan)
 
     let marker (img: Image<Gray, float32>) (closed: Image<Gray, float32>) (level: float) : Image<Gray, byte> =
         let diff = img.Copy()
@@ -34,9 +33,9 @@ let find (img: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gr
         diff._ThresholdBinary(Gray(0.0), Gray(255.))
         diff.Convert<Gray, byte>()
 
-    let nucleusMarker = marker imgFilteredParasite filteredGreenWithoutNucleus (1. / config.Parameters.infectionSensitivity)
+    let nucleusMarker = marker img imgWithoutNucleus (1. / config.Parameters.infectionSensitivity)
 
-    let filteredGreenWithoutCytoplasm = imgFilteredParasite.CopyBlank()
+    let imgWithoutParasite = img.CopyBlank()
     let kernelSize =
         let size = roundInt (config.RBCRadius.Pixel / 5.f)
         if size % 2 = 0 then size + 1 else size
@@ -47,13 +46,13 @@ let find (img: Image<Gray, float32>) (config: Config.Config) : Result * Image<Gr
         else
             CvInvoke.GetStructuringElement(CvEnum.ElementShape.Ellipse, Size(kernelSize, kernelSize), Point(-1, -1))
 
-    CvInvoke.MorphologyEx(imgFilteredParasite, filteredGreenWithoutCytoplasm, CvEnum.MorphOp.Close, kernel, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar())
-    let cytoplasmMarker = marker imgFilteredParasite filteredGreenWithoutCytoplasm (1. / config.Parameters.cytoplasmSensitivity)
+    CvInvoke.MorphologyEx(img, imgWithoutParasite, CvEnum.MorphOp.Close, kernel, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar())
+    let parasiteMarker = marker img imgWithoutParasite (1. / config.Parameters.cytoplasmSensitivity)
 
     { darkStain = darkStain
       nucleus = nucleusMarker
-      cytoplasm = cytoplasmMarker },
-    filteredGreenWithoutCytoplasm,
-    filteredGreenWithoutNucleus
+      parasite = parasiteMarker },
+    imgWithoutParasite,
+    imgWithoutNucleus