Use two radius in the configuration, one computed with the image resolution and one...
[master-thesis.git] / Parasitemia / Parasitemia / MainAnalysis.fs
index a7fdf71..8f59514 100644 (file)
@@ -31,26 +31,25 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportPr
     let greenFloat = green.Convert<Gray, float32>()
     let filteredGreen = gaussianFilter greenFloat config.LPFStandardDeviation
 
-    logWithName (sprintf "Nominal erytrocyte diameter: %s" config.FormattedRadius)
+    logWithName (sprintf "Nominal erytrocyte diameter: %A" config.RBCRadiusByResolution)
 
-    let initialAreaOpening = int<| config.RBCArea * config.Parameters.ratioAreaPaleCenter * 1.2f // We do an area opening a little larger to avoid to do a second one in the case the radius found is near the initial one.
+    let initialAreaOpening = int <| config.RBCRadiusByResolution.Area * config.Parameters.ratioAreaPaleCenter * 1.2f // We do an area opening a little larger to avoid to do a second one in the case the radius found is near the initial one.
     logTimeWithName "Area opening number one" (fun () -> ImgTools.areaOpenF filteredGreen initialAreaOpening)
 
     report 8
 
     let range =
-        let delta = config.Parameters.granulometryRange * config.RBCRadius
-        int <| config.RBCRadius - delta, int <| config.RBCRadius + delta
+        let delta = config.Parameters.granulometryRange * config.RBCRadiusByResolution.Pixel
+        int <| config.RBCRadiusByResolution.Pixel - delta, int <| config.RBCRadiusByResolution.Pixel + delta
     //let r1 = log "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert<Gray, byte>()) range 1.0 |> float32)
-    let r2 = logTimeWithName "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen range |> float32)
+    config.SetRBCRadius <| logTimeWithName "Granulometry (area)" (fun() -> Granulometry.findRadiusByAreaClosing filteredGreen range |> float32)
     // log (sprintf "r1: %A, r2: %A" r1 r2)
-    config.RBCRadius <- r2
 
-    logWithName (sprintf "Found erytrocyte diameter: %s" config.FormattedRadius)
+    logWithName (sprintf "Found erytrocyte diameter: %A" config.RBCRadius)
 
     report 24
 
-    let secondAreaOpening = int <| config.RBCArea * config.Parameters.ratioAreaPaleCenter
+    let secondAreaOpening = int <| config.RBCRadius.Area * config.Parameters.ratioAreaPaleCenter
     if secondAreaOpening > initialAreaOpening
     then
         logTimeWithName "Area opening number two" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpening)
@@ -60,7 +59,7 @@ let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportPr
 
     let edges, xGradient, yGradient = logTimeWithName "Finding edges" (fun () ->
         let edges, xGradient, yGradient = ImgTools.findEdges filteredGreenWhitoutStain
-        removeArea edges (config.RBCRadius ** 2.f / 50.f |> int)
+        removeArea edges (config.RBCRadius.Pixel ** 2.f / 50.f |> int)
         edges, xGradient, yGradient)
 
     let allEllipses, ellipses = logTimeWithName "Finding ellipses" (fun () ->
@@ -139,7 +138,7 @@ let doMultipleAnalysis (imgs: (string * Config * Image<Bgr, byte>) list) (report
         progressPerAnalysis.AddOrUpdate(id, progress, (fun _ _ -> progress)) |> ignore
         report (progressPerAnalysis.Values.Sum() / nbImgs)
 
-    let nbConcurrentTaskLimit = 4
+    let nbConcurrentTaskLimit = 4 // To reduce the memory taken.
     let n = Environment.ProcessorCount
 
     imgs