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)
+ // Monadic construction to be able to abort the progress when running.
maybe {
do! report 0
use img_float = img.Convert<Bgr, float32>()
- use img_RBC = img_float.[1] // mergeChannelsWithProjection img_float config.Parameters.averageColor_RBC config.Parameters.averageColor_BG 255.
+ use img_RBC = img_float.[1] // Green.
use img_RBC_filtered = gaussianFilter img_RBC config.LPFStandardDeviationRBC
- use img_parasites = img_float.[2] // mergeChannelsWithProjection img_float config.Parameters.averageColor_Parasite config.Parameters.averageColor_RBC 255.
+ use img_parasites = img_float.[2] // Red.
use img_parasites_filtered = gaussianFilter img_parasites config.LPFStandardDeviationParasite
logWithName (sprintf "Nominal erythrocyte diameter: %A" config.RBCRadiusByResolution)
Drawing.drawCells imgCells' true cells
IO.saveImg imgCells' (buildFileName " - cells - full.png")
- let filteredGreenMaxima = gaussianFilter img_RBC config.LPFStandardDeviationRBC
- for m in findMaxima filteredGreenMaxima do
- Drawing.drawPoints filteredGreenMaxima m 255.f
- IO.saveImg filteredGreenMaxima (buildFileName " - filtered - maxima.png")
+ let filteredRBCMaxima = gaussianFilter img_RBC config.LPFStandardDeviationRBC
+ for m in findMaxima filteredRBCMaxima do
+ Drawing.drawPoints filteredRBCMaxima m 255.f
+ IO.saveImg filteredRBCMaxima (buildFileName " - filtered - maxima.png")
IO.saveImg imgWhitoutParasite (buildFileName " - filtered closed stain.png")
IO.saveImg imgWithoutNucleus (buildFileName " - filtered closed infection.png")
imgs
|> PSeq.choose (
fun (id, config, img) ->
- match doAnalysis img id config (Some (fun p -> reportProgressImg id p)) with
- | Some result -> Some (id, result)
- | None -> None)
+ try
+ match doAnalysis img id config (Some (fun p -> reportProgressImg id p)) with
+ | Some result -> Some (id, result)
+ | None -> None
+ with
+ | ex ->
+ Log.Error("Analysis {0} failed: {1}", id, ex)
+ None)
|> PSeq.withDegreeOfParallelism n
|> PSeq.toList
if edgesData.[i, j] = 1uy
then currentElements.Add(Point(j, i))
- if currentElements.Count >= 10
+ if currentElements.Count >= nbPickElementsMin
then
let mutable nbOfPicks = (float currentElements.Count) * factorNbMaxPick |> int
let mutable nbOfValidPicks = (float currentElements.Count) * factorNbValidPick |> int
open Emgu.CV
open Emgu.CV.Structure
+/// <summary>
+/// Normalize an image between 0 and 'upperLimit'.
+/// FIXME: use to many memory.
+/// </summary>
+/// <param name="img"></param>
+/// <param name="upperLimit"></param>
let normalize (img: Image<Gray, float32>) (upperLimit: float) : Image<Gray, float32> =
let min = ref [| 0.0 |]
let minLocation = ref <| [| Point() |]
| Some results ->
for id, cells in results do
state.SetResult (int id) cells
-
- win.Root.Dispatcher.Invoke(fun () ->
- win.stackSourceImagesSelection.IsEnabled <- true
- win.butStart.IsEnabled <- true
- win.butClose.Content <- "Close"
- updateSourceImages ())
-
Logger.Log.User("All analyses terminated successfully")
atLeastOneAnalysisPerformed <- true
analysisPerformed <- true
- | None -> ())
+ | None ->
+ Logger.Log.User("Analysis aborted")
+
+ win.Root.Dispatcher.Invoke(fun () ->
+ win.progress.Value <- if maybeResults.IsSome then 100. else 0.
+ win.stackSourceImagesSelection.IsEnabled <- true
+ win.butStart.IsEnabled <- true
+ win.butClose.Content <- "Close"
+ updateSourceImages ()))
} |> Async.Start
| _ -> ())
lock monitor (fun () ->
if not analysisPerformed
then
+ // To cancel the current analysis if one is running on the next call to the progress function.
analysisCancelled <- true
atLeastOneAnalysisPerformed)