GUI (work in progress..)
[master-thesis.git] / Parasitemia / Parasitemia / MainAnalysis.fs
index 9f91a6d..5ee6886 100644 (file)
@@ -3,6 +3,8 @@
 open System
 open System.Drawing
 
+open FSharp.Collections.ParallelSeq
+
 open Emgu.CV
 open Emgu.CV.Structure
 
@@ -19,9 +21,13 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) : Cell li
 
     logTime "areaOpen 1" (fun () -> ImgTools.areaOpenF filteredGreen config.Parameters.initialAreaOpen)
 
-    config.RBCRadius <- logTime "Granulometry" (fun() -> Granulometry.findRadius (filteredGreen.Convert<Gray, byte>()) (10, 100) 0.3 |> float32)
+    let r1 = logTime "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert<Gray, byte>()) (10, 80) 0.5 |> float32)
+    // let r2 = logTime "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen (10, 80) |> float32)
+    // log (sprintf "r1: %A, r2: %A" r1 r2)
+    config.RBCRadius <- r1
 
     let secondAreaOpen = int <| config.RBCArea / 3.f
+
     if secondAreaOpen > config.Parameters.initialAreaOpen
     then
         logTime "areaOpen 2" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpen)
@@ -87,3 +93,13 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) : Cell li
     | _ -> ()
 
     cells
+
+
+let doMultipleAnalysis (imgs: (string * Image<Bgr, byte>) list) (config : Config) : (string * Cell list) list =
+    let nbConcurrentTaskLimit = 4
+    let n = Environment.ProcessorCount
+
+    imgs
+    |> PSeq.map (fun (id, img) -> id, doAnalysis img id (config.Copy()))
+    |> PSeq.withDegreeOfParallelism (if n > nbConcurrentTaskLimit then nbConcurrentTaskLimit else n)
+    |> PSeq.toList
\ No newline at end of file