Update coding style.
[master-thesis.git] / Parasitemia / ParasitemiaCore / Analysis.fs
index f607760..8b16c45 100644 (file)
@@ -49,7 +49,7 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
 
         logWithName "Starting analysis ..."
 
-        use img_float = img.Convert<Bgr, float32>()
+        use img_float = img.Convert<Bgr, float32> ()
 
         use img_RBC = img_float.[1] // Green.
         use img_RBC_filtered = gaussianFilter img_RBC config.LPFStandardDeviationRBC
@@ -66,8 +66,8 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
             let delta = config.Parameters.granulometryRange * config.RBCRadiusByResolution.Pixel
             int <| config.RBCRadiusByResolution.Pixel - delta, int <| config.RBCRadiusByResolution.Pixel + delta
 
-        let! radius = logTimeWithName "Granulometry (area)" (fun() -> reportWithVal 10 (Granulometry.findRadiusByAreaClosing img_RBC_filtered range |> float32))
-        //let! radius = logTimeWithName "Granulometry (morpho)" (fun() -> reportWithVal 10 (Granulometry.findRadiusByClosing img_RBC_filtered range 1. true |> float32))
+        let! radius = logTimeWithName "Granulometry (area)" (fun () -> reportWithVal 10 (Granulometry.findRadiusByAreaClosing img_RBC_filtered range |> float32))
+        //let! radius = logTimeWithName "Granulometry (morpho)" (fun () -> reportWithVal 10 (Granulometry.findRadiusByClosing img_RBC_filtered range 1. true |> float32))
         config.SetRBCRadius <| radius
 
         logWithName (sprintf "Found erythrocyte diameter: %O" config.RBCRadius)
@@ -90,10 +90,13 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
         let! parasites, imgWhitoutParasite, imgWithoutNucleus =
             logTimeWithName "Parasites segmentation" (fun () -> reportWithVal 40 (ParasitesMarker.find img_parasites_filtered config))
 
-        let! edges, xGradient, yGradient = logTimeWithName "Finding edges" (fun () ->
-            let edges, xGradient, yGradient = Edges.find img_RBC_filtered
-            removeArea edges (config.RBCRadius.Pixel ** 2.f / 50.f |> int)
-            reportWithVal 50 (edges, xGradient, yGradient))
+        let! edges, xGradient, yGradient =
+            logTimeWithName "Finding edges" (
+                fun () ->
+                    let edges, xGradient, yGradient = Edges.find img_RBC_filtered
+                    removeArea edges (config.RBCRadius.Pixel ** 2.f / 50.f |> int)
+                    reportWithVal 50 (edges, xGradient, yGradient)
+            )
 
         let! matchingEllipses = logTimeWithName "Finding ellipses" (fun () -> reportWithVal 60 (Ellipse.find edges xGradient yGradient config))
 
@@ -107,10 +110,10 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
             // Output pictures if debug flag is set.
             match config.Debug with
             | DebugOn output ->
-                let dirPath = System.IO.Path.Combine(output, name)
+                let dirPath = System.IO.Path.Combine (output, name)
                 System.IO.Directory.CreateDirectory dirPath |> ignore
 
-                let buildFileName postfix = System.IO.Path.Combine(dirPath, name + postfix)
+                let buildFileName postfix = System.IO.Path.Combine (dirPath, name + postfix)
 
                 IO.saveMat (edges * 255.0) (buildFileName " - edges.png")
 
@@ -118,19 +121,19 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
                 IO.saveImg parasites.parasite (buildFileName " - parasites - stain.png")
                 IO.saveImg parasites.nucleus (buildFileName " - parasites - infection.png")
 
-                let imgAllEllipses = img_RBC_filtered.Copy()
-                Drawing.drawEllipses imgAllEllipses matchingEllipses.Ellipses (Gray(200.0)) 0.04
+                let imgAllEllipses = img_RBC_filtered.Copy ()
+                Drawing.drawEllipses imgAllEllipses matchingEllipses.Ellipses (Gray 200.0) 0.04
                 IO.saveImg imgAllEllipses (buildFileName " - ellipses - all.png")
 
-                let imgEllipses = img_RBC_filtered.Convert<Bgr, byte>()
-                Drawing.drawEllipses imgEllipses prunedEllipses (Bgr(0.0, 240.0, 240.0)) 1.0
+                let imgEllipses = img_RBC_filtered.Convert<Bgr, byte> ()
+                Drawing.drawEllipses imgEllipses prunedEllipses (Bgr (0.0, 240.0, 240.0)) 1.0
                 IO.saveImg imgEllipses (buildFileName " - ellipses.png")
 
-                let imgCells = img.Copy()
+                let imgCells = img.Copy ()
                 Drawing.drawCells imgCells false cells
                 IO.saveImg imgCells (buildFileName " - cells.png")
 
-                let imgCells' = img.Copy()
+                let imgCells' = img.Copy ()
                 Drawing.drawCells imgCells' true cells
                 IO.saveImg imgCells' (buildFileName " - cells - full.png")
 
@@ -167,12 +170,12 @@ let doMultipleAnalysis (imgs : (string * Config * Image<Bgr, byte>) list) (repor
         | Some f -> f percent
         | _ -> true
 
-    let progressPerAnalysis = System.Collections.Concurrent.ConcurrentDictionary<string, int>()
+    let progressPerAnalysis = System.Collections.Concurrent.ConcurrentDictionary<string, int> ()
     let nbImgs = List.length imgs
 
     let reportProgressImg (id : string) (progress : int) =
-        progressPerAnalysis.AddOrUpdate(id, progress, (fun _ _ -> progress)) |> ignore
-        report (progressPerAnalysis.Values.Sum() / nbImgs)
+        progressPerAnalysis.AddOrUpdate (id, progress, (fun _ _ -> progress)) |> ignore
+        report (progressPerAnalysis.Values.Sum () / nbImgs)
 
     let n = Environment.ProcessorCount