Parcourir la source

extract estimators from scene

Jérôme BUISINE il y a 3 ans
Parent
commit
8e350e6ecb
2 fichiers modifiés avec 86 ajouts et 1 suppressions
  1. 44 1
      main/extract_stats_images.cpp
  2. 42 0
      run/run_all_estimators.py

+ 44 - 1
main/extract_stats_images.cpp

@@ -7,7 +7,7 @@
 #include <tuple>
 #include <cmath>
 #include <numeric>  
-
+#include <map>
 #include <algorithm>
 #include <filesystem>
 
@@ -116,6 +116,49 @@ float getEstimator(std::string estimator, std::vector<float> values) {
         float order2 = std::accumulate(values.begin(), values.end(), 0.0, order2_func);
 
         return size * (order4 / order2);
+
+    } else if (estimator == "mode") {
+
+        std::vector<float> pvalues;
+
+        for (unsigned i = 0; i < values.size(); i++){
+            pvalues.push_back(roundf(values.at(i) * 100) / 100.0);
+        }
+
+        typedef std::map<float,unsigned int> CounterMap;
+        CounterMap counts;
+        for (int i = 0; i < pvalues.size(); ++i)
+        {
+            CounterMap::iterator it(counts.find(pvalues[i]));
+            if (it != counts.end()){
+                it->second++;   
+            } else {
+                counts[pvalues[i]] = 1;
+            }
+        }
+
+        // Create a map iterator and point to beginning of map
+        std::map<float, unsigned int>::iterator it = counts.begin();
+        unsigned noccurences = 0;
+        float modeValue = 0.;
+        // Iterate over the map using Iterator till end.
+        while (it != counts.end())
+        {
+            // Accessing KEY from element pointed by it.
+            float potentialMode = it->first;
+            // Accessing VALUE from element pointed by it.
+            unsigned count = it->second;
+
+            if (count > noccurences) {
+                noccurences = count;
+                modeValue = potentialMode;
+            }
+
+            // Increment the Iterator to point to next entry
+            it++;
+        }
+
+        return modeValue;
     }
 
     // by default

+ 42 - 0
run/run_all_estimators.py

@@ -0,0 +1,42 @@
+import os
+import argparse
+
+def main():
+
+    estimators = ["median", "variance", "std", "skewness", "kurtosis", "mode"]
+
+    parser = argparse.ArgumentParser("Run estimators reconstruction")
+    parser.add_argument('--folder', type=str, help='folder with rawls scene data', required=True)
+    parser.add_argument('--nfiles', type=int, help='expected number of rawls files', required=True)
+    parser.add_argument('--tiles', type=str, help='tiles size: 100,100', default="100,100")
+    parser.add_argument('--output', type=str, help='output folder', required=True)
+
+    args = parser.parse_args()
+
+    p_folder = args.folder
+    p_nfiles = args.nfiles
+    x_tile, y_tile   = list(map(int, args.tiles.split(',')))
+    p_output = args.output
+
+    scenes = sorted(os.listdir(p_folder))
+
+    for est in estimators:
+        for scene in scenes:
+            scene_path = os.path.join(p_folder, scene)
+            nelements = len(os.listdir(scene_path))
+
+            if nelements == p_nfiles:
+                print('Extraction of {0} estimator for {1} scene'.format(est, scene))
+
+                output_folder = os.path.join(p_output, est, scene)
+
+                if not os.path.exists(output_folder):
+                    os.makedirs(output_folder)
+
+                outfilename = os.path.join(output_folder, scene + '_10000.rawls')
+                os.system('./build/main/extract_stats_images --folder {0} --bwidth {1} --bheight {2} --outfile {3} --estimator {4}'.format(scene_path, x_tile, y_tile, est, outfilename))
+
+
+
+if __name__ == "__main__":
+    main()