X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FMainAnalysis.fs;h=2be9be151c4cf70b1f9240ad9de12222694df2f4;hp=9f91a6d3a143f229d4f0f38e2651980c6c0b9814;hb=807437584bdd3d7b7b33be8282472f81f8cce606;hpb=6b550c3faf4dea77738fa5c27cd9af277f45549c diff --git a/Parasitemia/Parasitemia/MainAnalysis.fs b/Parasitemia/Parasitemia/MainAnalysis.fs index 9f91a6d..2be9be1 100644 --- a/Parasitemia/Parasitemia/MainAnalysis.fs +++ b/Parasitemia/Parasitemia/MainAnalysis.fs @@ -3,6 +3,8 @@ open System open System.Drawing +open FSharp.Collections.ParallelSeq + open Emgu.CV open Emgu.CV.Structure @@ -12,16 +14,27 @@ open Config open Types -let doAnalysis (img: Image) (name: string) (config: Config) : Cell list = +let doAnalysis (img: Image) (name: string) (config: Config) (reportProgress: (int -> unit) option) : Cell list = + let inline report (percent: int) = + match reportProgress with + | Some f -> f percent + | _ -> () + use green = img.Item(1) let greenFloat = green.Convert() let filteredGreen = gaussianFilter greenFloat (float config.Parameters.preFilterSigma) logTime "areaOpen 1" (fun () -> ImgTools.areaOpenF filteredGreen config.Parameters.initialAreaOpen) + report 8 + + let r1 = logTime "Granulometry (morpho)" (fun() -> Granulometry.findRadiusByClosing (filteredGreen.Convert()) (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 + report 24 - config.RBCRadius <- logTime "Granulometry" (fun() -> Granulometry.findRadius (filteredGreen.Convert()) (10, 100) 0.3 |> float32) + let secondAreaOpen = int <| config.RBCArea * config.Parameters.ratioSecondAreaOpen - let secondAreaOpen = int <| config.RBCArea / 3.f if secondAreaOpen > config.Parameters.initialAreaOpen then logTime "areaOpen 2" (fun () -> ImgTools.areaOpenF filteredGreen secondAreaOpen) @@ -35,8 +48,10 @@ let doAnalysis (img: Image) (name: string) (config: Config) : Cell li let allEllipses, ellipses = logTime "Finding ellipses" (fun () -> let matchingEllipses = Ellipse.find edges xGradient yGradient config matchingEllipses.Ellipses, matchingEllipses.PrunedEllipses) + report 80 let cells = logTime "Classifier" (fun () -> Classifier.findCells ellipses parasites filteredGreenWhitoutStain config) + report 100 // Output pictures if debug flag is set. match config.Debug with @@ -87,3 +102,30 @@ let doAnalysis (img: Image) (name: string) (config: Config) : Cell li | _ -> () cells + + +// ID * cell radius * cell list. +let doMultipleAnalysis (imgs: (string * Image) list) (config : Config) (reportProgress: (int -> unit) option) : (string * float * Cell list) list = + let inline report (percent: int) = + match reportProgress with + | Some f -> f percent + | _ -> () + + let monitor = Object() + let mutable total = 0 + let nbImgs = List.length imgs + let reportProgressImg = + (fun progress -> + lock monitor (fun () -> total <- total + progress) + report (total / nbImgs)) + + let nbConcurrentTaskLimit = 4 + let n = Environment.ProcessorCount + + imgs + |> PSeq.map (fun (id, img) -> + let localConfig = config.Copy() + let cells = doAnalysis img id localConfig (Some reportProgressImg) + id, float localConfig.RBCRadius, cells) + |> PSeq.withDegreeOfParallelism (if n > nbConcurrentTaskLimit then nbConcurrentTaskLimit else n) + |> PSeq.toList