Parcourir la source

Merge branch 'release/v1.1.7'

Jérôme BUISINE il y a 3 ans
Parent
commit
f783efb7b6
3 fichiers modifiés avec 100 ajouts et 1 suppressions
  1. 5 1
      run/convert_all_rawls.py
  2. 40 0
      run/extract_specific_modulo.py
  3. 55 0
      run/extract_specific_png.py

+ 5 - 1
run/convert_all_rawls.py

@@ -2,6 +2,7 @@ import os
 import argparse
 import glob
 
+
 def main():
 
     parser = argparse.ArgumentParser(description="Convert rawls file into png")
@@ -26,7 +27,10 @@ def main():
         if not os.path.exists(output_folder):
             os.makedirs(output_folder)
         
-        os.system(f'./build/main/rawls_convert --image {img} --outfile {output_path}')
+        if not os.path.exists(output_path):
+            os.system(f'./build/main/rawls_convert --image {img} --outfile {output_path}')
+        else:
+            print(f'{output_path} already exists')
     
 
 if __name__ == "__main__":

+ 40 - 0
run/extract_specific_modulo.py

@@ -0,0 +1,40 @@
+import os
+import argparse
+import glob
+
+
+def main():
+
+    parser = argparse.ArgumentParser(description="Extract specific samples indices")
+
+    parser.add_argument('--folder', type=str, help='folder with all rawls files', required=True)
+    parser.add_argument('--modulo', type=int, help='every image to take', required=True)
+    parser.add_argument('--output', type=str, help='folder with all png files', required=True)
+
+    args = parser.parse_args()
+
+    p_folder = args.folder
+    p_output = args.output
+    p_modulo = args.modulo
+
+    images_path = glob.glob(f"{p_folder}/**/**/*.rawls")
+
+    for i, img in enumerate(sorted(images_path)):
+
+        if ((i + 1) % p_modulo) == 0:
+
+            output_path = img.replace(p_folder, p_output)
+            output_folder, _ = os.path.split(output_path)
+
+            if not os.path.exists(output_folder):
+                os.makedirs(output_folder)
+            
+            if not os.path.exists(output_path):
+                os.system(f'cp {img} {output_path}')
+                print(f'Copy of {img}')
+            else:
+                print(f'{output_path} already exists')
+    
+
+if __name__ == "__main__":
+    main()

+ 55 - 0
run/extract_specific_png.py

@@ -0,0 +1,55 @@
+import os
+import argparse
+import glob
+
+
+def main():
+
+    parser = argparse.ArgumentParser(description="Extract specific samples indices")
+
+    parser.add_argument('--folder', type=str, help='folder with all rawls files', required=True)
+    parser.add_argument('--index', type=str, help='current rawls image index', required=True)
+    parser.add_argument('--nsamples', type=str, help='expected nsamples for image', required=True)
+    parser.add_argument('--output', type=str, help='folder with all png files', required=True)
+
+    args = parser.parse_args()
+
+    p_folder = args.folder
+    p_output = args.output
+    p_index = args.index
+    p_samples = args.nsamples
+
+    expected_index = str(p_index)
+
+    while len(expected_index) < 6:
+        expected_index = "0" + expected_index
+
+    output_index = ""
+    while len(output_index) < 6:
+        output_index = "0" + output_index
+
+    images_path = glob.glob(f"{p_folder}/**/**/*{expected_index}.png")
+
+    for img in sorted(images_path):
+
+        # replace expected Samples value
+        img_data = img.split('-')
+        img_data[-2] = "S" + p_samples
+        img_data[-1] = output_index + ".png"
+
+        output_path = '-'.join(img_data)
+
+        output_path = output_path.replace(p_folder, p_output)
+        output_folder, _ = os.path.split(output_path)
+
+        if not os.path.exists(output_folder):
+            os.makedirs(output_folder)
+        
+        if not os.path.exists(output_path):
+            os.system(f'cp {img} {output_path}')
+        else:
+            print(f'{output_path} already exists')
+    
+
+if __name__ == "__main__":
+    main()