X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FAnalysis.fs;h=f7e7b1c90bc1ff0553fe6df3228f2334b385b11d;hb=ec96e4c38dd6beaf22b4e2a2ebb87248fea6f209;hp=7f58463110cb4d3becb2474623a7c53cc21b4421;hpb=04d4504e7b248a82ddfc1a41d325e59d24146590;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/Analysis.fs b/Parasitemia/ParasitemiaCore/Analysis.fs index 7f58463..f7e7b1c 100644 --- a/Parasitemia/ParasitemiaCore/Analysis.fs +++ b/Parasitemia/ParasitemiaCore/Analysis.fs @@ -42,10 +42,11 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr let report (percent: int) : unit option = reportWithVal percent () - let inline buildLogWithName (text: string) = sprintf "(%s) %s" name text + 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) + // 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) @@ -102,7 +103,7 @@ let doAnalysis (img: Image) (name: string) (config: Config) (reportPr let! prunedEllipses = logTimeWithName "Ellipses pruning" (fun () -> reportWithVal 80 (matchingEllipses.PrunedEllipses)) - let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites img_RBC_filtered config)) + let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites img.Width img.Height config)) logWithName "Analysis finished" @@ -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