1
module Parasitemia.Main
17 | CmdLine of Input * string
20 type Arguments = RunningMode * bool
22 let parseArgs (args
: string[]) : Arguments =
24 let output = Array.tryFindIndex
((=) "--output") args
27 match Array.tryFindIndex
((=) "--folder") args
, output with
28 | Some i
, Some i_output when i
< args
.Length - 2 && i_output < args
.Length - 2 ->
29 CmdLine ((Dir args
.[i
+1]), args
.[i_output + 1])
31 match Array.tryFindIndex
((=) "--file") args
, output with
32 | Some i
, Some i_output when i
< args
.Length - 2 && i_output < args
.Length - 2 ->
33 CmdLine ((File args.[i
+1]), args.[i_output + 1])
37 runningMode, Array.exists
((=) "--debug") args
43 match parseArgs args with
48 initialAreaOpen
= 2000
53 preFilterSigma
= 1.7 // 1.5
57 darkStainLevel
= 0.25 // 0.3
58 maxDarkStainRatio
= 0.1 // 10 %
60 infectionArea
= 0.012f // 1.2 %
61 infectionLevel
= 1.12 // Lower -> more sensitive.
63 stainArea
= 0.08f // 8 %
64 stainLevel
= 1.1 // Lower -> more sensitive.
65 maxStainRatio
= 0.12 // 12 %
67 standardDeviationMaxRatio
= 0.5 // 0.55
68 minimumCellArea
= 0.5f })
71 | CmdLine (input
, output) ->
74 config.Debug <- DebugOn output
76 Directory.CreateDirectory output |> ignore
78 use logFile = new StreamWriter(new FileStream(Path.Combine(output, "log.txt"), FileMode.Append, FileAccess.Write))
79 Utils.log
<- (fun m
-> logFile.WriteLine(m
))
80 Utils.log
(sprintf
"=== New run : %A %A ===" DateTime.Now (if debug
then "[DEBUG]" else "[RELEASE]"))
82 let files = match input
with
83 | File file
-> [ file
]
84 | Dir dir
-> Directory.EnumerateFiles dir |> List.ofSeq
86 use resultFile = new StreamWriter(new FileStream(Path.Combine(output, "results.txt"), FileMode.Append, FileAccess.Write))
89 let images = [ for file
in files -> Path.GetFileNameWithoutExtension(FileInfo(file
).Name), new Image<Bgr, byte
>(file
) ]
92 Utils.logTime
"Whole analyze" (fun () ->
93 let results = ImageAnalysis.doMultipleAnalysis
images config
95 for id
, cells
in results do
96 let total, infected
= Utils.countCells
cells
97 fprintf
resultFile "File: %s %d %d %.2f\n" id
total infected (100. * (float infected) / (float total)))
99 //Utils.log (sprintf "== File: %A" file)
101 //| :? IOException as ex -> Utils.log (sprintf "Unable to open the image '%A': %A" file ex)
105 (*let display (window : Views.MainWindow) (img : IImage) =
106 let imgControl = window.Root.FindName("img") :?> Controls.Image
107 imgControl.Source <- BitmapSourceConvert.ToBitmapSource(img)
109 let log (window : Views.MainWindow) (mess : string) =
110 let txtLog = window.Root.FindName("txtLog") :?> Controls.TextBlock
111 txtLog.Text <- txtLog.Text + mess + "\n"*)
113 if debug
then config.Debug <- DebugOn "."