/// The first call returning 'false' will cancel the analysis.
/// The 'int' parameter correspond to the progression from 0 to 100</param>
/// <returns>A list of detected cells or nothing if the process has been cancelled</returns>
-let doAnalysis (img: Image<Bgr, byte>) (name: string) (config: Config) (reportProgress: (int -> bool) option) : Cell list option =
+let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (reportProgress : (int -> bool) option) : Cell list option =
// To report the progress of this function from 0 to 100.
// Return 'None' if the process must be aborted.
- let reportWithVal (percent: int) (value: 'a) : 'a option =
+ let reportWithVal (percent : int) (value : 'a) : 'a option =
match reportProgress with
- | Some f ->
- if f percent
- then Some value
- else None
+ | Some f -> if f percent then Some value else None
| _ -> Some value
- let report (percent: int) : unit option =
+ let report (percent : int) : unit option =
reportWithVal percent ()
- let inline buildLogWithName (text: string) = sprintf "№ %s: %s" name text
- let logWithName mess = Log.User(buildLogWithName mess)
- let inline logTimeWithName (text: string) (f: unit -> 'a option) : 'a option = Log.LogWithTime((buildLogWithName text), Severity.USER, f)
+ let inline buildLogWithName (text : string) = sprintf "№ %s: %s" name text
+ let logWithName mess = Log.Info "%s" (buildLogWithName mess)
+ let inline logTimeWithName (text : string) (f : unit -> 'a option) : 'a option = Log.LogWithTime Severity.INFO f "%s" (buildLogWithName text)
// Monadic construction to be able to abort the progress when running.
maybe {
use img_parasites = img_float.[2] // Red.
use img_parasites_filtered = gaussianFilter img_parasites config.LPFStandardDeviationParasite
- logWithName (sprintf "Nominal erythrocyte diameter: %A" config.RBCRadiusByResolution)
+ logWithName (sprintf "Nominal erythrocyte diameter: %O" config.RBCRadiusByResolution)
let initialAreaOpening = int <| config.RBCRadiusByResolution.Area * config.Parameters.ratioAreaPaleCenter * 1.1f // 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.
do! logTimeWithName "First area opening" (fun () -> areaOpenF img_RBC_filtered initialAreaOpening; report 10)
//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: %A" config.RBCRadius)
+ logWithName (sprintf "Found erythrocyte diameter: %O" config.RBCRadius)
do! report 20
do!
let secondAreaOpening = int <| config.RBCRadius.Area * config.Parameters.ratioAreaPaleCenter
- if secondAreaOpening > initialAreaOpening
- then
+ if secondAreaOpening > initialAreaOpening then
logTimeWithName "Second area opening" (fun () -> areaOpenF img_RBC_filtered secondAreaOpening; report 30)
else
report 30
IO.saveImg img_float.[0] (buildFileName " - source - blue.png")
| _ -> ()
- return cells }
+ return cells
+ }
/// <summary>
/// Do multiple analyses on the same time. The number of concurrent process depends if the number of the core.
/// The first call returning 'false' will cancel the analysis.
/// The 'int' parameter correspond to the progression from 0 to 100</param>
/// <returns>'None' if the process has been cancelled or the list of result as (name * cells), 'name' corresponds to the given name<returns>
-let doMultipleAnalysis (imgs: (string * Config * Image<Bgr, byte>) list) (reportProgress: (int -> bool) option) : (string * Cell list) list option =
- let report (percent: int) : bool =
+let doMultipleAnalysis (imgs : (string * Config * Image<Bgr, byte>) list) (reportProgress : (int -> bool) option) : (string * Cell list) list option =
+ let report (percent : int) : bool =
match reportProgress with
| Some f -> f percent
| _ -> true
let progressPerAnalysis = System.Collections.Concurrent.ConcurrentDictionary<string, int>()
let nbImgs = List.length imgs
- let reportProgressImg (id: string) (progress: int) =
+ let reportProgressImg (id : string) (progress : int) =
progressPerAnalysis.AddOrUpdate(id, progress, (fun _ _ -> progress)) |> ignore
report (progressPerAnalysis.Values.Sum() / nbImgs)
| None -> None
with
| ex ->
- Log.Error("Analysis {0} failed: {1}", id, ex)
- None)
+ Log.Error "Analysis %s failed: %O" id ex
+ None
+ )
|> PSeq.withDegreeOfParallelism n
|> PSeq.toList
// If one of the analyses has been aborted we return 'None'.
- if List.length results <> List.length imgs
- then None
- else Some results
+ if List.length results <> List.length imgs then
+ None
+ else
+ Some results