Project the colors to have the best contrast for RBCs and parasites analyze.
[master-thesis.git] / Parasitemia / ParasitemiaCore / MainAnalysis.fs
index 813d090..cae6427 100644 (file)
@@ -50,17 +50,14 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportPr
 
         logWithName "Starting analysis ..."
 
-        use img_RBC =
-            use imgFloat = img.Convert<Bgr, float32>()
-            let redFactor, greenFactor, blueFactor = config.Parameters.colorContribution_BG_RBC
-            blueFactor * imgFloat.[0] + greenFactor * imgFloat.[1] + redFactor * imgFloat.[2]
+        use img_float = img.Convert<Bgr, float32>()
 
+        // use img_RBC = mergeChannels img_float config.Parameters.colorContribution_BG_RBC
+        use img_RBC = mergeChannelsWithProjection img_float (94.7f, 80.7f, 99.3f) (113.3f, 135.3f, 150.3f) 255.
         let img_RBC_filtered = gaussianFilter img_RBC config.LPFStandardDeviationRBC
 
-        use img_parasites =
-            use imgFloat = img.Convert<Bgr, float32>()
-            let redFactor, greenFactor, blueFactor = config.Parameters.colorContribution_RBC_parasite
-            blueFactor * imgFloat.[0] + greenFactor * imgFloat.[1] + redFactor * imgFloat.[2]
+        //use img_parasites = mergeChannels img_float config.Parameters.colorContribution_RBC_parasite
+        use img_parasites = mergeChannelsWithProjection img_float (76.f, 58.f, 94.f) (94.7f, 80.7f, 99.3f) 255.
 
         logWithName (sprintf "Nominal erytrocyte diameter: %A" config.RBCRadiusByResolution)
 
@@ -86,7 +83,8 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportPr
             else
                 report 30
 
-        ImgTools.areaCloseF img_RBC_filtered (config.RBCRadius.Area * 0.1f |> roundInt)
+        // Removing of parasites.
+        ImgTools.areaCloseF img_RBC_filtered (roundInt <| Const.PI * config.RBCRadius.ParasiteRadius ** 2.f)
 
         let parasites, filteredGreenWhitoutStain, filteredGreenWithoutInfection = ParasitesMarker.find img_parasites config
         //let parasites, filteredGreenWhitoutInfection, filteredGreenWhitoutStain = ParasitesMarker.findMa greenFloat filteredGreenFloat config
@@ -123,7 +121,7 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportPr
                 drawEllipses imgAllEllipses matchingEllipses.Ellipses (Bgr(255.0, 255.0, 255.0)) 0.04
                 saveImg imgAllEllipses (buildFileName " - ellipses - all.png")
 
-                let imgEllipses = filteredGreenWhitoutStain.Convert<Bgr, byte>()
+                let imgEllipses = img_RBC_filtered.Convert<Bgr, byte>()
                 drawEllipses imgEllipses prunedEllipses (Bgr(0.0, 240.0, 240.0)) 1.0
                 saveImg imgEllipses (buildFileName " - ellipses.png")