extract_specific_modulo.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import argparse
  3. import glob
  4. def main():
  5. parser = argparse.ArgumentParser(description="Extract specific samples indices")
  6. parser.add_argument('--folder', type=str, help='folder with all rawls files', required=True)
  7. parser.add_argument('--modulo', type=int, help='every image to take', required=True)
  8. parser.add_argument('--output', type=str, help='folder with all png files', required=True)
  9. args = parser.parse_args()
  10. p_folder = args.folder
  11. p_output = args.output
  12. p_modulo = args.modulo
  13. images_path = glob.glob(f"{p_folder}/**/**/*.rawls")
  14. for img in sorted(images_path):
  15. # replace expected Samples value
  16. img_data = img.split('-')
  17. index_img = int(img_data[-1].split('.')[0])
  18. if (index_img % p_modulo) - 1 == 0:
  19. output_path = img.replace(p_folder, p_output)
  20. output_folder, _ = os.path.split(output_path)
  21. if not os.path.exists(output_folder):
  22. os.makedirs(output_folder)
  23. if not os.path.exists(output_path):
  24. os.system(f'cp {img} {output_path}')
  25. else:
  26. print(f'{output_path} already exists')
  27. else:
  28. print(f'Not considered: {img}')
  29. if __name__ == "__main__":
  30. main()