<commit_before>#!/usr/bin/env python
#
# multi-label registration of spinal cord internal structure
#
# ---------------------------------------------------------------------------------------
# Copyright (c) 2013 Polytechnique Montreal <www.neuro.polymtl.ca>
# Authors: <NAME>
# Modified: 2015-05-20
#
# About the license: see the file LICENSE.TXT
#########################################################################################
import sys, os, time
from msct_parser import Parser
from msct_image import Image
import sct_utils as sct

class Param:
    def __init__(self):
        self.thr = 0.5
        self.gap = (100, 200)
        self.smooth = 0.8

        self.param_reg = 'step=1,algo=slicereg,metric=MeanSquares:step=2,algo=syn,metric=MeanSquares,iter=10,smooth=0,shrink=2:step=3,algo=bsplinesyn,metric=MeanSquares,iter=5,smooth=0'
        # Previous default param (less efficient): 'step=1,algo=slicereg,metric=MeanSquares:step=2,algo=bsplinesyn,metric=MeanSquares,iter=5,smooth=1'

        self.output_folder = './'
        self.verbose = 1
        self.remove_tmp = 1
        self.qc = 1


class MultiLabelRegistration:
    def __init__(self, fname_gm, fname_wm, path_template, fname_warp_template2target, param=None, fname_warp_target2template=None, apply_warp_template=0):
        if param is None:
            self.param = Param()
        else:
            self.param = param
        self.im_gm = Image(fname_gm)
        self.im_wm = Image(fname_wm)
        self.path_template = sct.slash_at_the_end(path_template, 1)
        self.im_template_gm = Image(self.path_template+'template/MNI-Poly-AMU_GM.nii.gz')
        self.im_template_wm = Image(self.path_template+'template/MNI-Poly-AMU_WM.nii.gz')

        # Previous warping fields:
        self.fname_warp_template2target = fname_warp_template2target
        self.fname_warp_target2template = fname_warp_target2template

        # new warping fields:
        self.fname_warp_template2gm = ''
        self.fname_wwarp_gm2template = ''
        
        # temporary fix - related to issue #871
        self.apply_warp_template = apply_warp_template

    def register(self):
        # accentuate separation WM/GM
        self.im_gm = thr_im(self.im_gm, 0.01, self.param.thr)
        self.im_wm = thr_im(self.im_wm, 0.01, self.param.thr)
        self.im_template_gm = thr_im(self.im_template_gm, 0.01, self.param.thr)
        self.im_template_wm = thr_im(self.im_template_wm, 0.01, self.param.thr)

        # create multilabel images
        im_automatic_ml = self.im_gm.copy()
        im_template_ml = self.im_template_gm.copy()

        im_automatic_ml.data = self.param.gap[1]*self.im_gm.data + self.param.gap[0]*self.im_wm.data
        im_template_ml.data = self.param.gap[1]*self.im_template_gm.data + self.param.gap[0]*self.im_template_wm.data

        fname_automatic_ml = 'multilabel_automatic_seg.nii.gz'
        fname_template_ml = 'multilabel_template_seg.nii.gz'

        path_automatic_ml, file_automatic_ml, ext_automatic_ml = sct.extract_fname(fname_automatic_ml)
        path_template_ml, file_template_ml, ext_template_ml = sct.extract_fname(fname_template_ml)
        path_gm, file_gm, ext_gm = sct.extract_fname(fname_gm)
        path_warp_template2target, file_warp_template2target, ext_warp_template2target = sct.extract_fname(self.fname_warp_template2target)

        im_automatic_ml.setFileName(fname_automatic_ml)
        im_template_ml.setFileName(fname_template_ml)

        # Create temporary folder and put files in it
        tmp_dir = sct.tmp_create()

        from sct_convert import convert
        convert(fname_gm, tmp_dir+file_gm+ext_gm)
        convert(fname_warp_template, tmp_dir+file_warp_template2target+ext_warp_template2target, squeeze_data=0)
        if self.fname_warp_target2template is not None:
            path_warp_target2template, file_warp_target2template, ext_warp_target2template = sct.extract_fname(self.fname_warp_target2template)
            convert(self.fname_warp_target2template, tmp_dir+file_warp_target2template+ext_warp_target2template)

        os.chdir(tmp_dir)
        # TODO assert RPI, if not, change orientation
        im_automatic_ml.save()
        im_template_ml.save()
        
        # apply template2image warping field
        if self.apply_warp_template == 1:
            fname_template_ml_new = sct.add_suffix(fname_template_ml, '_r')
            sct.run('sct_apply_transfo -i '+fname_template_ml+' -d '+fname_automatic_ml+' -w '+file_warp_template2target+ext_warp_template2target + ' -o ' + fname_template_ml_new)
            fname_template_ml = fname_template_ml_new

        nx, ny, nz, nt, px, py, pz, pt = im_automatic_ml.dim
        size_mask = int(22.5/px)
        fname_mask = 'square_mask.nii.gz'
        sct.run('sct_create_mask -i '+fname_automatic_ml+' -p centerline,'+fname_automatic_ml+' -f box -size '+str(size_mask)+' -o '+fname_mask)

        fname_automatic_ml, xi, xf, yi, yf, zi, zf = crop_im(fname_automatic_ml, fname_mask)
        fname_template_ml, xi, xf, yi, yf, zi, zf = crop_im(fname_template_ml, fname_mask)

#        fname_automatic_ml_smooth = sct.add_suffix(fname_automatic_ml, '_smooth')
#        sct.run('sct_maths -i '+fname_automatic_ml+' -smooth '+str(self.param.smooth)+','+str(self.param.smooth)+',0 -o '+fname_automatic_ml_smooth)
#        fname_automatic_ml = fname_automatic_ml_smooth

        path_automatic_ml, file_automatic_ml, ext_automatic_ml = sct.extract_fname(fname_automatic_ml)
        path_template_ml, file_template_ml, ext_template_ml = sct.extract_fname(fname_template_ml)

        # Register multilabel images together
        cmd_reg = 'sct_register_multimodal -i '+fname_template_ml+' -d '+fname_automatic_ml+' -iseg '+fname_template_ml+' -dseg '+fname_automatic_ml+' -param '+self.param.param_reg
        if 'centermass' in self.param.param_reg:
            fname_template_ml_seg = sct.add_suffix(fname_template_ml, '_bin')
            sct.run('sct_maths -i '+fname_template_ml+' -bin -o '+fname_template_ml_seg)

            fname_automatic_ml_seg = sct.add_suffix(fname_automatic_ml, '_bin')
            sct.run('sct_maths -i '+fname_automatic_ml+' -thr 50 -o '+fname_automatic_ml_seg)
            sct.run('sct_maths -i '+fname_automatic_ml_seg+' -bin -o '+fname_automatic_ml_seg)

            cmd_reg += ' -iseg '+fname_template_ml_seg+' -dseg '+fname_automatic_ml_seg

        sct.run(cmd_reg)
        fname_warp_multilabel_template2auto = 'warp_'+file_template_ml+'2'+file_automatic_ml+'.nii.gz'
        fname_warp_multilabel_auto2template = 'warp_'+file_automatic_ml+'2'+file_template_ml+'.nii.gz'

        self.fname_warp_template2gm = 'warp_template2'+file_gm+'.nii.gz'
        # fname_warp_multilabel_template2auto = pad_im(fname_warp_multilabel_template2auto, nx, ny, nz, xi, xf, yi, yf, zi, zf)
        # fname_warp_multilabel_auto2template = pad_im(fname_warp_multilabel_auto2template, nx, ny, nz, xi, xf, yi, yf, zi, zf)

        sct.run('sct_concat_transfo -w '+file_warp_template2target+ext_warp_template2target+','+fname_warp_multilabel_template2auto+' -d '+file_gm+ext_gm+' -o '+self.fname_warp_template2gm)

        if self.fname_warp_target2template is not None:
            path_script = os.path.dirname(__file__)
            path_sct = os.path.dirname(path_script)
            fname_dest = path_sct+'/data/template/MNI-Poly-AMU_T2.nii.gz'
            self.fname_warp_gm2template = 'warp_'+file_gm+'_gm2template.nii.gz'
            sct.run('sct_concat_transfo -w '+fname_warp_multilabel_auto2template+','+file_warp_target2template+ext_warp_target2template+' -d '+fname_dest+' -o '+self.fname_warp_gm2template)

        os.chdir('..')

        # sct.generate_output_file(tmp_dir+fname_warp_multilabel_template2auto, self.param.output_folder+'warp_template_multilabel2automatic_seg_multilabel.nii.gz')
        # sct.generate_output_file(tmp_dir+fname_warp_multilabel_auto2template, self.param.output_folder+'warp_automatic_seg_multilabel2template_multilabel.nii.gz')

        sct.generate_output_file(tmp_dir+self.fname_warp_template2gm, self.param.output_folder+self.fname_warp_template2gm)
        if self.fname_warp_target2template is not None:
            sct.generate_output_file(tmp_dir+self.fname_warp_gm2template, self.param.output_folder+self.fname_warp_gm2template)

        if self.param.qc:
            fname_grid_warped = visualize_warp(tmp_dir+fname_warp_multilabel_template2auto, rm_tmp=self.param.remove_tmp)
            path_grid_warped, file_grid_warped, ext_grid_warped = sct.extract_fname(fname_grid_warped)
            sct.generate_output_file(fname_grid_warped, self.param.output_folder+file_grid_warped+ext_grid_warped)

        if self.param.remove_tmp:
            sct.run('rm -rf '+tmp_dir, error_exit='warning')

    def validation(self, fname_manual_gmseg, fname_sc_seg):
        path_manual_gmseg, file_manual_gmseg, ext_manual_gmseg = sct.extract_fname(fname_manual_gmseg)
        path_sc_seg, file_sc_seg, ext_sc_seg = sct.extract_fname(fname_sc_seg)

        # Create tmp folder and copy files in it
        tmp_dir = sct.tmp_create()
        sct.run('cp '+fname_manual_gmseg+' '+tmp_dir+file_manual_gmseg+ext_manual_gmseg)
        sct.run('cp '+fname_sc_seg+' '+tmp_dir+file_sc_seg+ext_sc_seg)
        sct.run('cp '+self.param.output_folder+self.fname_warp_template2gm+' '+tmp_dir+self.fname_warp_template2gm)
        os.chdir(tmp_dir)

        sct.run('sct_warp_template -d '+fname_manual_gmseg+' -w '+self.fname_warp_template2gm+' -qc 0 -a 0')

        im_new_template_gm = Image('label/template/MNI-Poly-AMU_GM.nii.gz')
        im_new_template_wm = Image('label/template/MNI-Poly-AMU_WM.nii.gz')

        im_new_template_gm = thr_im(im_new_template_gm, self.param.thr, self.param.thr)
        im_new_template_wm = thr_im(im_new_template_wm, self.param.thr, self.param.thr)

        self.im_template_gm = thr_im(self.im_template_gm, self.param.thr, self.param.thr)
        self.im_template_wm = thr_im(self.im_template_wm, self.param.thr, self.param.thr)

        fname_new_template_gm = 'new_template_gm.nii.gz'
        im_new_template_gm.setFileName(fname_new_template_gm)
        im_new_template_gm.save()

        fname_new_template_wm = 'new_template_wm.nii.gz'
        im_new_template_wm.setFileName(fname_new_template_wm)
        im_new_template_wm.save()

        fname_old_template_wm = 'old_template_wm.nii.gz'
        self.im_template_wm.setFileName(fname_old_template_wm)
        self.im_template_wm.save()

        fname_old_template_gm = 'old_template_gm.nii.gz'
        self.im_template_gm.setFileName(fname_old_template_gm)
        self.im_template_gm.save()

        fname_manual_wmseg = 'target_manual_wmseg.nii.gz'
        sct.run('sct_maths -i '+file_sc_seg+ext_sc_seg+' -sub '+file_manual_gmseg+ext_manual_gmseg+' -o '+fname_manual_wmseg)

        # Compute Hausdorff distance
        status, output_old_hd = sct.run('sct_compute_hausdorff_distance -i '+fname_old_template_gm+' -r '+file_manual_gmseg+ext_manual_gmseg+' -t 1  -v 1')
        status, output_new_hd = sct.run('sct_compute_hausdorff_distance -i '+fname_new_template_gm+' -r '+file_manual_gmseg+ext_manual_gmseg+' -t 1  -v 1')
<commit_msg>OPT: adapt use of MNI-Poly-AMU or PAM50 template according to input<commit_after>#!/usr/bin/env python
#
# multi-label registration of spinal cord internal structure
#
# ---------------------------------------------------------------------------------------
# Copyright (c) 2013 Polytechnique Montreal <www.neuro.polymtl.ca>
# Authors: <NAME>
# Modified: 2015-05-20
#
# About the license: see the file LICENSE.TXT
#########################################################################################
import sys, os, time
from msct_parser import Parser
from msct_image import Image
import sct_utils as sct

class Param:
    def __init__(self):
        self.thr = 0.5
        self.gap = (100, 200)
        self.smooth = 0.8

        self.param_reg = 'step=1,algo=slicereg,metric=MeanSquares:step=2,algo=syn,metric=MeanSquares,iter=10,smooth=0,shrink=2:step=3,algo=bsplinesyn,metric=MeanSquares,iter=5,smooth=0'
        # Previous default param (less efficient): 'step=1,algo=slicereg,metric=MeanSquares:step=2,algo=bsplinesyn,metric=MeanSquares,iter=5,smooth=1'

        self.output_folder = './'
        self.verbose = 1
        self.remove_tmp = 1
        self.qc = 1


class MultiLabelRegistration:
    def __init__(self, fname_gm, fname_wm, path_template, fname_warp_template2target, param=None, fname_warp_target2template=None, apply_warp_template=0):
        if param is None:
            self.param = Param()
        else:
            self.param = param
        self.im_gm = Image(fname_gm)
        self.im_wm = Image(fname_wm)
        self.path_template = sct.slash_at_the_end(path_template, 1)
        if 'MNI-Poly-AMU_GM.nii.gz' in os.listdir(self.path_template+'template/'):
            self.im_template_gm = Image(self.path_template+'template/MNI-Poly-AMU_GM.nii.gz')
            self.im_template_wm = Image(self.path_template+'template/MNI-Poly-AMU_WM.nii.gz')
            self.template = 'MNI-Poly-AMU'
        else:
            self.im_template_gm = Image(self.path_template + 'template/PAM50_gm.nii.gz')
            self.im_template_wm = Image(self.path_template + 'template/PAM50_wm.nii.gz')
            self.template = 'PAM50'

        # Previous warping fields:
        self.fname_warp_template2target = fname_warp_template2target
        self.fname_warp_target2template = fname_warp_target2template

        # new warping fields:
        self.fname_warp_template2gm = ''
        self.fname_wwarp_gm2template = ''
        
        # temporary fix - related to issue #871
        self.apply_warp_template = apply_warp_template

    def register(self):
        # accentuate separation WM/GM
        self.im_gm = thr_im(self.im_gm, 0.01, self.param.thr)
        self.im_wm = thr_im(self.im_wm, 0.01, self.param.thr)
        self.im_template_gm = thr_im(self.im_template_gm, 0.01, self.param.thr)
        self.im_template_wm = thr_im(self.im_template_wm, 0.01, self.param.thr)

        # create multilabel images
        im_automatic_ml = self.im_gm.copy()
        im_template_ml = self.im_template_gm.copy()

        im_automatic_ml.data = self.param.gap[1]*self.im_gm.data + self.param.gap[0]*self.im_wm.data
        im_template_ml.data = self.param.gap[1]*self.im_template_gm.data + self.param.gap[0]*self.im_template_wm.data

        fname_automatic_ml = 'multilabel_automatic_seg.nii.gz'
        fname_template_ml = 'multilabel_template_seg.nii.gz'

        path_automatic_ml, file_automatic_ml, ext_automatic_ml = sct.extract_fname(fname_automatic_ml)
        path_template_ml, file_template_ml, ext_template_ml = sct.extract_fname(fname_template_ml)
        path_gm, file_gm, ext_gm = sct.extract_fname(fname_gm)
        path_warp_template2target, file_warp_template2target, ext_warp_template2target = sct.extract_fname(self.fname_warp_template2target)

        im_automatic_ml.setFileName(fname_automatic_ml)
        im_template_ml.setFileName(fname_template_ml)

        # Create temporary folder and put files in it
        tmp_dir = sct.tmp_create()

        from sct_convert import convert
        convert(fname_gm, tmp_dir+file_gm+ext_gm)
        convert(fname_warp_template, tmp_dir+file_warp_template2target+ext_warp_template2target, squeeze_data=0)
        if self.fname_warp_target2template is not None:
            path_warp_target2template, file_warp_target2template, ext_warp_target2template = sct.extract_fname(self.fname_warp_target2template)
            convert(self.fname_warp_target2template, tmp_dir+file_warp_target2template+ext_warp_target2template)

        os.chdir(tmp_dir)
        # TODO assert RPI, if not, change orientation
        im_automatic_ml.save()
        im_template_ml.save()
        
        # apply template2image warping field
        if self.apply_warp_template == 1:
            fname_template_ml_new = sct.add_suffix(fname_template_ml, '_r')
            sct.run('sct_apply_transfo -i '+fname_template_ml+' -d '+fname_automatic_ml+' -w '+file_warp_template2target+ext_warp_template2target + ' -o ' + fname_template_ml_new)
            fname_template_ml = fname_template_ml_new

        nx, ny, nz, nt, px, py, pz, pt = im_automatic_ml.dim
        size_mask = int(22.5/px)
        fname_mask = 'square_mask.nii.gz'
        sct.run('sct_create_mask -i '+fname_automatic_ml+' -p centerline,'+fname_automatic_ml+' -f box -size '+str(size_mask)+' -o '+fname_mask)

        fname_automatic_ml, xi, xf, yi, yf, zi, zf = crop_im(fname_automatic_ml, fname_mask)
        fname_template_ml, xi, xf, yi, yf, zi, zf = crop_im(fname_template_ml, fname_mask)

#        fname_automatic_ml_smooth = sct.add_suffix(fname_automatic_ml, '_smooth')
#        sct.run('sct_maths -i '+fname_automatic_ml+' -smooth '+str(self.param.smooth)+','+str(self.param.smooth)+',0 -o '+fname_automatic_ml_smooth)
#        fname_automatic_ml = fname_automatic_ml_smooth

        path_automatic_ml, file_automatic_ml, ext_automatic_ml = sct.extract_fname(fname_automatic_ml)
        path_template_ml, file_template_ml, ext_template_ml = sct.extract_fname(fname_template_ml)

        # Register multilabel images together
        cmd_reg = 'sct_register_multimodal -i '+fname_template_ml+' -d '+fname_automatic_ml+' -iseg '+fname_template_ml+' -dseg '+fname_automatic_ml+' -param '+self.param.param_reg
        if 'centermass' in self.param.param_reg:
            fname_template_ml_seg = sct.add_suffix(fname_template_ml, '_bin')
            sct.run('sct_maths -i '+fname_template_ml+' -bin -o '+fname_template_ml_seg)

            fname_automatic_ml_seg = sct.add_suffix(fname_automatic_ml, '_bin')
            sct.run('sct_maths -i '+fname_automatic_ml+' -thr 50 -o '+fname_automatic_ml_seg)
            sct.run('sct_maths -i '+fname_automatic_ml_seg+' -bin -o '+fname_automatic_ml_seg)

            cmd_reg += ' -iseg '+fname_template_ml_seg+' -dseg '+fname_automatic_ml_seg

        sct.run(cmd_reg)
        fname_warp_multilabel_template2auto = 'warp_'+file_template_ml+'2'+file_automatic_ml+'.nii.gz'
        fname_warp_multilabel_auto2template = 'warp_'+file_automatic_ml+'2'+file_template_ml+'.nii.gz'

        self.fname_warp_template2gm = 'warp_template2'+file_gm+'.nii.gz'
        # fname_warp_multilabel_template2auto = pad_im(fname_warp_multilabel_template2auto, nx, ny, nz, xi, xf, yi, yf, zi, zf)
        # fname_warp_multilabel_auto2template = pad_im(fname_warp_multilabel_auto2template, nx, ny, nz, xi, xf, yi, yf, zi, zf)

        sct.run('sct_concat_transfo -w '+file_warp_template2target+ext_warp_template2target+','+fname_warp_multilabel_template2auto+' -d '+file_gm+ext_gm+' -o '+self.fname_warp_template2gm)

        if self.fname_warp_target2template is not None:
            path_script = os.path.dirname(__file__)
            path_sct = os.path.dirname(path_script)
            if self.template == 'MNI-Poly-AMU':
                fname_dest = path_sct+'/data/MNI-Poly-AMU/template/MNI-Poly-AMU_T2.nii.gz'
            elif self.template == 'PAM50':
                fname_dest = path_sct+'/data/PAM50/template/PAM50_t2.nii.gz'

            self.fname_warp_gm2template = 'warp_'+file_gm+'_gm2template.nii.gz'
            sct.run('sct_concat_transfo -w '+fname_warp_multilabel_auto2template+','+file_warp_target2template+ext_warp_target2template+' -d '+fname_dest+' -o '+self.fname_warp_gm2template)

        os.chdir('..')

        # sct.generate_output_file(tmp_dir+fname_warp_multilabel_template2auto, self.param.output_folder+'warp_template_multilabel2automatic_seg_multilabel.nii.gz')
        # sct.generate_output_file(tmp_dir+fname_warp_multilabel_auto2template, self.param.output_folder+'warp_automatic_seg_multilabel2template_multilabel.nii.gz')

        sct.generate_output_file(tmp_dir+self.fname_warp_template2gm, self.param.output_folder+self.fname_warp_template2gm)
        if self.fname_warp_target2template is not None:
            sct.generate_output_file(tmp_dir+self.fname_warp_gm2template, self.param.output_folder+self.fname_warp_gm2template)

        if self.param.qc:
            fname_grid_warped = visualize_warp(tmp_dir+fname_warp_multilabel_template2auto, rm_tmp=self.param.remove_tmp)
            path_grid_warped, file_grid_warped, ext_grid_warped = sct.extract_fname(fname_grid_warped)
            sct.generate_output_file(fname_grid_warped, self.param.output_folder+file_grid_warped+ext_grid_warped)

        if self.param.remove_tmp:
            sct.run('rm -rf '+tmp_dir, error_exit='warning')

    def validation(self, fname_manual_gmseg, fname_sc_seg):
        path_manual_gmseg, file_manual_gmseg, ext_manual_gmseg = sct.extract_fname(fname_manual_gmseg)
        path_sc_seg, file_sc_seg, ext_sc_seg = sct.extract_fname(fname_sc_seg)

        # Create tmp folder and copy files in it
        tmp_dir = sct.tmp_create()
        sct.run('cp '+fname_manual_gmseg+' '+tmp_dir+file_manual_gmseg+ext_manual_gmseg)
        sct.run('cp '+fname_sc_seg+' '+tmp_dir+file_sc_seg+ext_sc_seg)
        sct.run('cp '+self.param.output_folder+self.fname_warp_template2gm+' '+tmp_dir+self.fname_warp_template2gm)
        os.chdir(tmp_dir)

        sct.run('sct_warp_template -d '+fname_manual_gmseg+' -w '+self.fname_warp_template2gm+' -qc 0 -a 0')
        if 'MNI-Poly-AMU_GM.nii.gz' in os.listdir('label/template/'):
            im_new_template_gm = Image('label/template/MNI-Poly-AMU_GM.nii.gz')
            im_new_template_wm = Image('label/template/MNI-Poly-AMU_WM.nii.gz')
        else:
            im_new_template_gm = Image('label/template/PAM50_gm.nii.gz')
            im_new_template_wm = Image('label/template/PAM50_wm.nii.gz')

        im_new_template_gm = thr_im(im_new_template_gm, self.param.thr, self.param.thr)
        im_new_template_wm = thr_im(im_new_template_wm, self.param.thr, self.param.thr)

        self.im_template_gm = thr_im(self.im_template_gm, self.param.thr, self.param.thr)
        self.im_template_wm = thr_im(self.im_template_wm, self.param.thr, self.param.thr)

        fname_new_template_gm = 'new_template_gm.nii.gz'
        im_new_template_gm.setFileName(fname_new_template_gm)
        im_new_template_gm.save()

        fname_new_template_wm = 'new_template_wm.nii.gz'
        im_new_template_wm.setFileName(fname_new_template_wm)
        im_new_template_wm.save()

        fname_old_template_wm = 'old_template_wm.nii.gz'
        self.im_template_wm.setFileName(fname_old_template_wm)
        self.im_template_wm.save()

        fname_old_template_gm = 'old_template_gm.nii.gz'
        self.im_template_gm.setFileName(fname_old_template_gm)
        self.im_template_gm.save()

        fname_manual_wmseg = 'target_manual_wmseg.nii.gz'
        sct.run('sct_maths -i '+file_sc_seg+ext_sc_seg+' -sub '+file_manual_gmseg+ext_manual_gmseg+' -o '+fname_manual_wmseg)

        # Compute Hausdorff distance
        status, output_old_hd = sct.run('sct_compute_hausdorff_distance -i '+fname_old_template_gm+' -r '+file_manual_gmseg+ext_manual_gmseg+' -t 1  -v 1')
        status, output_new_hd = sct.run('sct_compute_hausdorff_distance -i '+fname_new_template_gm+' -r '+file_manual_gmseg+ext_manual_gmseg+' -t 1  -v 1')

{'fraction_non_alphanumeric': 0.11676220852549458, 'fraction_numerical': 0.012283953277875953, 'mean_word_length': 3.6806536211418197, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '954216', 'n_tokens_mistral': 9088, 'n_tokens_neox': 8541, 'n_words': 1134}