From: Greg Burri Date: Sat, 30 Jan 2016 22:03:10 +0000 (+0100) Subject: Doc + cleaning. X-Git-Tag: 1.0.11~20 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=85adb74195fe7145535d3d36263aec2f7879cd60;p=master-thesis.git Doc + cleaning. --- diff --git a/Parasitemia/ParasitemiaCore/Analysis.fs b/Parasitemia/ParasitemiaCore/Analysis.fs index c894fc4..e83977a 100644 --- a/Parasitemia/ParasitemiaCore/Analysis.fs +++ b/Parasitemia/ParasitemiaCore/Analysis.fs @@ -46,6 +46,7 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr 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 @@ -53,10 +54,10 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr use img_float = img.Convert() - 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) @@ -137,10 +138,10 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr 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") @@ -182,9 +183,14 @@ let doMultipleAnalysis (imgs: (string * Config * Image) list) (report 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 diff --git a/Parasitemia/ParasitemiaCore/Ellipse.fs b/Parasitemia/ParasitemiaCore/Ellipse.fs index cf94be2..e95cf27 100644 --- a/Parasitemia/ParasitemiaCore/Ellipse.fs +++ b/Parasitemia/ParasitemiaCore/Ellipse.fs @@ -181,7 +181,7 @@ let find (edges: Matrix) 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 diff --git a/Parasitemia/ParasitemiaCore/ImgTools/Edges.fs b/Parasitemia/ParasitemiaCore/ImgTools/Edges.fs index a1b6033..3980120 100644 --- a/Parasitemia/ParasitemiaCore/ImgTools/Edges.fs +++ b/Parasitemia/ParasitemiaCore/ImgTools/Edges.fs @@ -87,9 +87,6 @@ let find (img: Image) : Matrix * Matrix * Matrix(xGradient.Size) let edgesData = edges.Data diff --git a/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs b/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs index 0510bc8..0949713 100644 --- a/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs +++ b/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs @@ -6,6 +6,12 @@ open System.Drawing open Emgu.CV open Emgu.CV.Structure +/// +/// Normalize an image between 0 and 'upperLimit'. +/// FIXME: use to many memory. +/// +/// +/// let normalize (img: Image) (upperLimit: float) : Image = let min = ref [| 0.0 |] let minLocation = ref <| [| Point() |] diff --git a/Parasitemia/ParasitemiaUI/Analysis.fs b/Parasitemia/ParasitemiaUI/Analysis.fs index 5bb3500..2ff0b1e 100644 --- a/Parasitemia/ParasitemiaUI/Analysis.fs +++ b/Parasitemia/ParasitemiaUI/Analysis.fs @@ -128,17 +128,18 @@ let showWindow (parent: Window) (state: State.State) : bool = | 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 | _ -> ()) @@ -151,5 +152,6 @@ let showWindow (parent: Window) (state: State.State) : bool = 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) diff --git a/Parasitemia/ParasitemiaUI/Program.fs b/Parasitemia/ParasitemiaUI/Program.fs index feab9ec..ce7cdd4 100644 --- a/Parasitemia/ParasitemiaUI/Program.fs +++ b/Parasitemia/ParasitemiaUI/Program.fs @@ -96,6 +96,6 @@ let main args = result with - | _ as ex -> + | ex -> Log.Fatal("Error: {0}", ex) 1 \ No newline at end of file