Skip to content
Snippets Groups Projects
data_convert_and_add_separate_masks.py 2.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • Khyati Sethia's avatar
    Khyati Sethia committed
    import subprocess
    import time
    import os
    import json
    from scripts.utils import *
    
    # Start measuring script execution time
    start_time = time.time()
    
    # --------------------------------------------------------------------------
    root_dir = "C:/Users/set0013/Downloads/Fraunhofer/git/segment_sem_images"
    layers_mask_path = os.path.join(root_dir, "data/real_test_data/unprocessed/real_masks_test_layers/")
    pores_mask_path = os.path.join(root_dir, "data/real_test_data/unprocessed/real_masks_test_pores/")
    crpr_mask_path = os.path.join(root_dir, "data/real_test_data/unprocessed/real_masks_test_crpr/")
    
    layers_numbers_path = os.path.join(root_dir, "data/real_test_data/unprocessed/real_masks_test_layers_numbers/")
    layers_pores_numbers_path = os.path.join(root_dir, "data/real_test_data/unprocessed/real_masks_test_layers_numbers_pores/")
    layers_pores_crpr_numbers_path = os.path.join(root_dir, "data/real_test_data/real_masks_test/")
    # layers_pores_crpr_cracks_numbers_path # add this as well
    
    color_dict = {
        0: [198, 118, 255], # purple # Bg1
        1: [255, 255, 10], # yello  w # Bg2
        2: [255, 0, 0], # red # Fe2Al5
        5: [79, 255, 130], # green # Fe2Al
    }
    
    num_colors = len(color_dict)
    
    num_colors_str = str(num_colors)
    color_dict_str = json.dumps(color_dict)
    
    # --------------------------------------------------------------------------
    script_path = "scripts/convert_color_to_number_mask.py"
    subprocess.run(["python", script_path, "--input_path", layers_mask_path, "--output_path", layers_numbers_path, "--num_colors", num_colors_str, "--color_dict", color_dict_str])
    
    # --------------------------------------------------------------------------
    add_mask_to_image(layers_numbers_path, pores_mask_path, layers_pores_numbers_path, 255, 3) # pores
    add_mask_to_image(layers_pores_numbers_path, crpr_mask_path, layers_pores_crpr_numbers_path, 255, 4) # crpr
    
    # --------------------------------------------------------------------------
    # Calculate and print the total time taken
    end_time = time.time()
    execution_time = end_time - start_time
    minutes = int(execution_time / 60)
    seconds = int(execution_time % 60)
    print(f"Total time taken: {minutes} minutes and {seconds} seconds")
    
    # --------------------------------------------------------------------------