<jupyter_start><jupyter_text>Jupyter Notebook to generate corrected axon+myelin image after correcting the myelin mask.Instructions:-Enter the paths of the following inputs:    - path of the prediction: image of axon+myelin segmentation (output of AxonDeepSeg)    - path of corrected myelin by the user: myelin mask (uint8 type with myelin=255, background=0)-Run all the cells one by one.-The corrected axon-myelin image will be generated and saved in the same folder as the inputs.<jupyter_code>import numpy as np
from skimage import io
from scipy.misc import imread, imsave
import os
import imageio
%matplotlib inline
def generate_axons_from_myelin(path_prediction,path_myelin_corrected):

    # read output from axondeepseg and myelin mask corrected by user
    prediction = imageio.imread(path_prediction)
    myelin_corrected = imageio.imread(path_myelin_corrected)

    # compute the axon mask from axondeepseg (axon=255, myelin=127, background=0)
    axon_ads = prediction > 200
    
    # get the myelin mask corrected by user (myelin=255, background=0)
    myelin_corrected = myelin_corrected > 200
    
    # compute logical OR between axondeepseg axon mask and myelin corrected mask
    fused = np.logical_or(axon_ads, myelin_corrected)   
    
    # compute new axon mask by logical XOR between corrected myelin mask and fused
    new_axon_mask = np.logical_xor(myelin_corrected, fused)
    
    # merge corrected myelin mask and generated axon mask
    both = new_axon_mask*255 + myelin_corrected*127
    
    # get main path to save images
    path_folder, file_name = os.path.split(path_prediction)

    # save the corrected axon+myelin image
    imageio.imwrite(os.path.join(path_folder,'axon_myelin_mask_corrected.png'),both)

    return both

# Change the paths here:

path_prediction = '/Users/alzaia/Documents/test_mask/axon_myelin_mask.png'
path_myelin_corrected = '/Users/alzaia/Documents/test_mask/myelin_corrected.png'
both = generate_axons_from_myelin(path_prediction,path_myelin_corrected)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06259168704156479, 'fraction_numerical': 0.013691931540342298, 'mean_word_length': 4.6991643454039, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '311160', 'license': 'MIT', 'n_tokens_mistral': 681, 'n_tokens_neox': 611, 'n_words': 190, 'path': 'notebooks/generate_axons_from_myelin.ipynb', 'repo_name': 'sagoyal2/edit_axondeepseg', 'size': '2045'}