FIX #279
[master-thesis.git] / Parasitemia / ParasitemiaCore / Analysis.fs
index 8b16c45..ed908e2 100644 (file)
@@ -17,6 +17,8 @@ open ImgTools
 open Config
 open Types
 
+let warningRatioDifferenceRBCDiameter = 1.2
+
 /// <summary>
 /// Analyze the given image and detect reb blood cell (RBC) in it.
 /// </summary>
@@ -27,7 +29,7 @@ open Types
 ///     The first call returning 'false' will cancel the analysis.
 ///     The 'int' parameter correspond to the progression from 0 to 100</param>
 /// <returns>A list of detected cells or nothing if the process has been cancelled</returns>
-let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (reportProgress : (int -> bool) option) : Cell list option =
+let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (reportProgress : (int -> bool) option) : AnalysisResult option =
 
     // To report the progress of this function from 0 to 100.
     // Return 'None' if the process must be aborted.
@@ -104,6 +106,12 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
 
         let! cells = logTimeWithName "Classifier" (fun () -> reportWithVal 100 (Classifier.findCells prunedEllipses parasites img.Width img.Height config))
 
+        do
+            if config.RBCRadiusByResolution.μm / config.RBCRadius.μm > warningRatioDifferenceRBCDiameter then
+                logWithName (sprintf "Warning: erythrocyte diameter found is too low compared to the nominal erythrocyte diameter, maybe the PPI image resolution is lesser than %.0f ppi" config.Parameters.resolution)
+            elif config.RBCRadius.μm / config.RBCRadiusByResolution.μm > warningRatioDifferenceRBCDiameter then
+                logWithName (sprintf "Warning: erythrocyte diameter found is too high compared to the nominal erythrocyte diameter, maybe the PPI image resolution is higher than %.0f" config.Parameters.resolution)
+
         logWithName "Analysis finished"
 
         do
@@ -153,7 +161,14 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
                 IO.saveImg img_float.[0] (buildFileName " - source - blue.png")
             | _ -> ()
 
-        return cells
+        return
+            {
+                Cells = cells
+                RBCSize_μm = config.RBCRadius.μm
+                RBCSize_px = config.RBCRadius.Pixel
+            }
+
+        //return cells
     }
 
 /// <summary>
@@ -164,7 +179,7 @@ let doAnalysis (img : Image<Bgr, byte>) (name : string) (config : Config) (repor
 ///     The first call returning 'false' will cancel the analysis.
 ///     The 'int' parameter correspond to the progression from 0 to 100</param>
 /// <returns>'None' if the process has been cancelled or the list of result as (name * cells), 'name' corresponds to the given name<returns>
-let doMultipleAnalysis (imgs : (string * Config * Image<Bgr, byte>) list) (reportProgress : (int -> bool) option) : (string * Cell list) list option =
+let doMultipleAnalysis (imgs : (string * Config * Image<Bgr, byte>) list) (reportProgress : (int -> bool) option) : (string * AnalysisResult) list option =
     let report (percent : int) : bool =
         match reportProgress with
         | Some f -> f percent