def crop_t2_star(t2star, sc_seg, box_size=75):
    """
    Pretreatment function croping the t2star file around the spinal cord and to a 75*75 squared image

    :param t2star: t2star image to be croped

    :param sc_seg: segmentation of the spinal cord
    """
    t2star_name = sct.extract_fname(t2star)[1]
    sc_seg_name = sct.extract_fname(sc_seg)[1]
    mask_box = None

    try:
        ext = '.nii.gz'
        seg_in_name = t2star_name + '_seg_in'
        seg_in = seg_in_name + ext
        sct.run('sct_crop_image -i ' + t2star + ' -m ' + sc_seg + ' -b 0 -o ' + seg_in)

        mask_box = t2star_name + '_square_mask_from_sc_seg'+ext
        sct.run('sct_create_mask -i ' + seg_in + ' -p centerline,' + sc_seg + ' -size ' + str(box_size) + ' -o ' + mask_box + ' -f box')

        seg_in_im = Image(seg_in)
        mask_im = Image(mask_box)
        seg_in_im.crop_and_stack(mask_im, suffix='_croped', save=True)
        seg_in_name += '_croped'
        seg_in_im.setFileName(seg_in_name +ext)
        seg_in_im = set_orientation(seg_in_im, 'IRP')

        fname_seg_in_IRP = seg_in_name+'_IRP'+ext

        if t2star_name + '_square_mask_from_sc_seg_IRP.nii.gz' in os.listdir('.'):
            mask_box = t2star_name + '_square_mask_from_sc_seg_IRP.nii.gz'

    except Exception, e:
        sct.printv('WARNING: an error occured when croping ' + t2star_name + '... \n ' + str(e), 1, 'warning')
    return mask_box, fname_seg_in_IRP


# ------------------------------------------------------------------------------------------------------------------
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_gmseg_utils.py/crop_t2_star/original