Use of roman number to identify images.
authorGreg Burri <greg.burri@gmail.com>
Sat, 4 Nov 2017 19:42:21 +0000 (20:42 +0100)
committerGreg Burri <greg.burri@gmail.com>
Sat, 4 Nov 2017 19:42:21 +0000 (20:42 +0100)
.gitignore
Parasitemia/ParasitemiaUI/Analysis.fs
Parasitemia/ParasitemiaUI/GUI.fs
Parasitemia/ParasitemiaUI/SourceImage.fs
Parasitemia/ParasitemiaUI/State.fs
Parasitemia/ParasitemiaUI/Utils.fs

index 4a6c7e8..aaa6326 100644 (file)
@@ -3,4 +3,6 @@ obj/
 packages/
 .vs
 *.exe
 packages/
 .vs
 *.exe
-*.suo
\ No newline at end of file
+*.suo
+Images
+Scripts
index 13ce48b..485ddfd 100644 (file)
@@ -57,7 +57,7 @@ let showWindow (parent : Window) (state : State.State) : bool =
             let imageSourceSelection = Views.ImageSourceSelection (Tag = srcImg, Margin = Thickness 3.)
             imageSourceSelection.Tag <- srcImg
 
             let imageSourceSelection = Views.ImageSourceSelection (Tag = srcImg, Margin = Thickness 3.)
             imageSourceSelection.Tag <- srcImg
 
-            imageSourceSelection.txtImageNumber.Text <- string srcImg.Num
+            imageSourceSelection.txtImageNumber.Text <- string srcImg.RomanNum
             let height = srcImg.Img.Height * width / srcImg.Img.Width
             imageSourceSelection.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.Img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic))
             imageSourceSelection.chkSelection.IsChecked <- Nullable<bool> (srcImg.DateLastAnalysis.Ticks = 0L)
             let height = srcImg.Img.Height * width / srcImg.Img.Width
             imageSourceSelection.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.Img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic))
             imageSourceSelection.chkSelection.IsChecked <- Nullable<bool> (srcImg.DateLastAnalysis.Ticks = 0L)
@@ -125,7 +125,7 @@ let showWindow (parent : Window) (state : State.State) : bool =
                         for srcImg, selected, parameters in imagesParameters do
                             srcImg.Config.Parameters <- parameters // Save parameters.
                             if selected then
                         for srcImg, selected, parameters in imagesParameters do
                             srcImg.Config.Parameters <- parameters // Save parameters.
                             if selected then
-                                yield string srcImg.Num, srcImg.Config, srcImg.Img
+                                yield string srcImg.RomanNum, srcImg.Config, srcImg.Img
                     ]
 
                 if imagesToProcess.IsEmpty then
                     ]
 
                 if imagesToProcess.IsEmpty then
@@ -148,7 +148,7 @@ let showWindow (parent : Window) (state : State.State) : bool =
                                 match maybeResults with
                                 | Some results ->
                                     for id, cells in results do
                                 match maybeResults with
                                 | Some results ->
                                     for id, cells in results do
-                                        state.SetResult (int id) cells
+                                        state.SetResult id cells
                                     Logger.Log.Info "All analyses terminated successfully"
                                     atLeastOneAnalysisPerformed <- true
                                     analysisPerformed <- true
                                     Logger.Log.Info "All analyses terminated successfully"
                                     atLeastOneAnalysisPerformed <- true
                                     analysisPerformed <- true
index d78c202..f305687 100644 (file)
@@ -342,11 +342,11 @@ let run (defaultConfig : Config) (fileToOpen : string option) =
                 updateGlobalParasitemia ()
 
                 // Update image numbers.
                 updateGlobalParasitemia ()
 
                 // Update image numbers.
-                win.stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> |> Seq.iter (fun imgPreview -> imgPreview.txtImageNumber.Text <- (imgPreview.Tag :?> SourceImage).Num.ToString ())
+                win.stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> |> Seq.iter (fun imgPreview -> imgPreview.txtImageNumber.Text <- (imgPreview.Tag :?> SourceImage).RomanNum)
         )
 
         imgCtrl.Tag <- srcImg
         )
 
         imgCtrl.Tag <- srcImg
-        imgCtrl.txtImageNumber.Text <- string srcImg.Num
+        imgCtrl.txtImageNumber.Text <- string srcImg.RomanNum
         let width = 200
         let height = srcImg.Img.Height * width / srcImg.Img.Width
         imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.Img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic))
         let width = 200
         let height = srcImg.Img.Height * width / srcImg.Img.Width
         imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.Img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic))
index 2330227..7b3de18 100644 (file)
@@ -25,16 +25,19 @@ type SourceImage (num : int, name : string, config : ParasitemiaCore.Config.Conf
     let infectedRBColor = Color.FromRgb (255uy, 0uy, 40uy) // Red with a bit of blue.
 
     let updateAverageRBCSize () =
     let infectedRBColor = Color.FromRgb (255uy, 0uy, 40uy) // Red with a bit of blue.
 
     let updateAverageRBCSize () =
-        averageRBCSize <-
-            rbcs
-            |> List.collect (fun rbc -> [ rbc.size.Width; rbc.size.Height ])
-            |> List.average
+        if List.isEmpty rbcs |> not then
+            averageRBCSize <-
+                rbcs
+                |> List.collect (fun rbc -> [ rbc.size.Width; rbc.size.Height ])
+                |> List.average
 
     do
         updateAverageRBCSize ()
 
     member this.Num with get () = num and set value = num <- value
 
 
     do
         updateAverageRBCSize ()
 
     member this.Num with get () = num and set value = num <- value
 
+    member this.RomanNum = Utils.toRomanNumber this.Num
+
     member this.Name with get () = name and set value = name <- value
 
     member this.Config = config
     member this.Name with get () = name and set value = name <- value
 
     member this.Config = config
@@ -45,7 +48,9 @@ type SourceImage (num : int, name : string, config : ParasitemiaCore.Config.Conf
 
     member this.RBCs
         with get () = rbcs
 
     member this.RBCs
         with get () = rbcs
-        and set value = rbcs <- value
+        and set value =
+            rbcs <- value
+            updateAverageRBCSize ()
 
     member this.ImageParasitemia : int * int =
         List.length rbcs,
 
     member this.ImageParasitemia : int * int =
         List.length rbcs,
index 129e6a6..befbdec 100644 (file)
@@ -89,8 +89,8 @@ type State (defaultConfig : ParasitemiaCore.Config.Config) =
             srcImg.Name <- name
             alteredSinceLastSave <- true
 
             srcImg.Name <- name
             alteredSinceLastSave <- true
 
-    member this.SetResult (imgNum : int) (result : ParasitemiaCore.Types.AnalysisResult) =
-        let sourceImage = sourceImages.Find (fun srcImg -> srcImg.Num = imgNum)
+    member this.SetResult (imgId : string) (result : ParasitemiaCore.Types.AnalysisResult) =
+        let sourceImage = sourceImages.Find (fun srcImg -> srcImg.RomanNum = imgId)
 
         let w = sourceImage.Img.Width
         let h = sourceImage.Img.Height
 
         let w = sourceImage.Img.Width
         let h = sourceImage.Img.Height
index e7c9784..9f51436 100644 (file)
@@ -61,6 +61,38 @@ let sensorSizes : SensorSize list =
         saveSensorSizesToFile defaultSensorSizes
         defaultSensorSizes
 
         saveSensorSizesToFile defaultSensorSizes
         defaultSensorSizes
 
+let toRomanNumber (v : int) : string =
+    let rec decompose (v : int) : string =
+        if v >= 1000 then
+           "M" + decompose (v - 1000)
+        elif v >= 900 then
+           "CM" + decompose (v - 900)
+        elif v >= 500 then
+            "D" + decompose (v - 500)
+        elif v >= 400 then
+            "CD" + decompose (v - 400)
+        elif v >= 100 then
+            "C" + decompose (v - 100)
+        elif v >= 90 then
+            "XC" + decompose (v - 90)
+        elif v >= 50 then
+            "L" + decompose (v - 50)
+        elif v >= 40 then
+            "XL" + decompose (v - 40)
+        elif v >= 10 then
+            "X" + decompose (v - 10)
+        elif v >= 9 then
+            "IX" + decompose (v - 9)
+        elif v >= 5 then
+            "V" + decompose (v - 5)
+        elif v >= 4 then
+            "IV" + decompose (v - 4)
+        elif v >= 1 then
+            "I" + decompose (v - 1)
+        else
+            ""
+    decompose v
+
 let argsHelp =
     let programName = System.AppDomain.CurrentDomain.FriendlyName
     "Usage of Parasitemia:\n" +
 let argsHelp =
     let programName = System.AppDomain.CurrentDomain.FriendlyName
     "Usage of Parasitemia:\n" +