1
module Parasitemia.Main
17 | CmdLine of Input * string // A file or a directory to process and the output directory.
18 | Window of string option // An optional path to a file to open can be given in window mode.
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])
35 Window (if args.Length > 0 && not
(args.[0].StartsWith("--")) then Some args.[0] else None)
37 runningMode, Array.exists
((=) "--debug") args
43 let e = Ellipse.ellipse2
-11.4 -7.8 -0.169811 -23.75 0.8 -3.885714 -19. 1.5
45 match parseArgs args with
47 let config = Config(defaultParameters
)
50 | CmdLine (input
, output) ->
53 config.Debug <- DebugOn output
55 Directory.CreateDirectory output |> ignore
57 use logFile = new StreamWriter(new FileStream(Path.Combine(output, "log.txt"), FileMode.Append, FileAccess.Write))
58 Utils.log
<- (fun m
-> logFile.WriteLine(m
))
59 Utils.log
(sprintf
"=== New run : %A %A ===" DateTime.Now (if debug
then "[DEBUG]" else "[RELEASE]"))
61 let files = match input
with
62 | File file
-> [ file
]
63 | Dir dir
-> Directory.EnumerateFiles dir |> List.ofSeq
65 use resultFile = new StreamWriter(new FileStream(Path.Combine(output, "results.txt"), FileMode.Append, FileAccess.Write))
68 let images = [ for file
in files -> Path.GetFileNameWithoutExtension(FileInfo(file
).Name), config.Copy(), new Image<Bgr, byte
>(file
) ]
71 Utils.logTime
"Whole analyze" (fun () ->
72 let results = ImageAnalysis.doMultipleAnalysis
images None
74 for id
, cells
in results do
75 let config = images |> List.pick
(fun (id
', config', _) -> if id
' = id then Some config' else None)
76 let total, infected
= Utils.countCells
cells
77 fprintf
resultFile "File: %s %d %d %.2f (diameter: %A)\n" id
total infected (100. * (float infected) / (float total)) config.RBCRadius)
79 //Utils.log (sprintf "== File: %A" file)
81 //| :? IOException as ex -> Utils.log (sprintf "Unable to open the image '%A': %A" file ex)
84 | Window fileToOpen
->
85 (*let display (window : Views.MainWindow) (img : IImage) =
86 let imgControl = window.Root.FindName("img") :?> Controls.Image
87 imgControl.Source <- BitmapSourceConvert.ToBitmapSource(img)
89 let log (window : Views.MainWindow) (mess : string) =
90 let txtLog = window.Root.FindName("txtLog") :?> Controls.TextBlock
91 txtLog.Text <- txtLog.Text + mess + "\n"*)
93 if debug
then config.Debug <- DebugOn "."
94 GUI.Main.run
config fileToOpen