Ejemplo n.º 1
0
def compute():
    outputDir='/Users/younes/Development/Results/atlasSections'
    if __name__ == "__main__":
        loggingUtils.setup_default_logging(outputDir, fileName='info')
    else:
        loggingUtils.setup_default_logging()
    ## Build Two colliding ellipses
    fv01 = Curve(filename='/cis/home/younes/MorphingData/MostofskyCurves/atlas02_curve01.txt')
    fv02 = Curve(filename='/cis/home/younes/MorphingData/MostofskyCurves/atlas02_curve02.txt')
    fv03 = Curve(filename='/cis/home/younes/MorphingData/MostofskyCurves/atlas02_curve03.txt')
    fv11 = Curve(filename='/cis/home/younes/MorphingData/MostofskyCurves/atlas08_curve01.txt')
    fv12 = Curve(filename='/cis/home/younes/MorphingData/MostofskyCurves/atlas08_curve02.txt')
    fv13 = Curve(filename='/cis/home/younes/MorphingData/MostofskyCurves/atlas08_curve03.txt')

    ## Object kernel
    K1 = Kernel(name='laplacian', sigma = 10.0)
    ## Background kernel
    K2 = Kernel(name='laplacian', sigma = 1.0)

    sm = CurveMatchingParam(timeStep=0.1, KparDiff=K1, KparDiffOut=K2, sigmaDist=2., sigmaError=.1, errorType='measure')
    f = (CurveMatching(Template=(fv01,fv02,fv03), Target=(fv11,fv12,fv13), outputDir=outputDir,
                       param=sm, mu=1.,regWeightOut=1., testGradient=False,
                       typeConstraint='stitched', maxIter_cg=10000, maxIter_al=100, affine='none', rotWeight=10))
    f.optimizeMatching()


    return f
Ejemplo n.º 2
0
def compute():

    outputDir = '/Users/younes/Development/Results/threeBallsSplineAndMomentum'
    #outputDir = '/cis/home/younes/MorphingData/twoBallsStitched'
    #outputDir = '/Users/younes/Development/Results/tight_stitched_rigid2_10'
    if __name__ == "__main__":
        loggingUtils.setup_default_logging(outputDir, fileName='info')
    else:
        loggingUtils.setup_default_logging()

    Tg = 2000
    npt = 100.0
    ## Build Two colliding ellipses
    [x,y,z] = np.mgrid[0:2*npt, 0:2*npt, 0:2*npt]/npt
    y = y-1
    z = z-1
    x = x-1
    s2 = np.sqrt(2)
    
    I1 = .06 - ((x)**2 + 0.5*((y)**2) + (z)**2)  
    fv1 = Surface() ;
    fv1.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])

    I1 = .08 - ((x+.05)**2 + 0.3*(y-0.05)**2 + (z)**2)  
    fv2 = Surface() ;
    fv2.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])

    I1 = .06 - (1.25*(x)**2 + 0.5*(y-0.25)**2 + 0.75*(z)**2)  
    fv3 = Surface() ;
    fv3.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])


    ## Object kernel
    K1 = Kernel(name='laplacian', sigma = 50.0, order=4)


    sm = surfaceMatching.SurfaceMatchingParam(timeStep=0.1, KparDiff=K1, sigmaDist=50., sigmaError=10., errorType='measure')
    f = (match.SurfaceMatching(Template=fv1, Targets=(fv2,fv3), outputDir=outputDir, param=sm, typeRegression='both',
                          testGradient=False, maxIter=1000))
    #, affine='none', rotWeight=0.1))
    f.optimizeMatching()


    return f
Ejemplo n.º 3
0
def compute():

    #outputDir = '/Users/younes/Development/Results/biocardTS/spline'
    outputDir = '/Users/younes/Development/Results/biocardTS/geodesic'
    #outputDir = '/cis/home/younes/MorphingData/twoBallsStitched'
    #outputDir = '/Users/younes/Development/Results/tight_stitched_rigid2_10'
    if __name__ == "__main__":
        loggingUtils.setup_default_logging(outputDir, fileName='info')
    else:
        loggingUtils.setup_default_logging()

    rdir = '/cis/project/biocard/data/2mm_complete_set_surface_mapping_10212012/hippocampus/6_mappings_baseline_template_all/0_template_to_all/' ;
    sub = '2840698'
    #sub = '2729611'
    if sub == '2840698':
        fv1 = surfaces.Surface(filename=rdir+'2840698_2_4_hippo_L_reg.byu_10_6.5_2.5.byu')
        fv2 = surfaces.Surface(filename=rdir+'2840698_3_4_hippo_L_reg.byu_10_6.5_2.5.byu')
        fv3 = surfaces.Surface(filename=rdir+'2840698_4_8_hippo_L_reg.byu_10_6.5_2.5.byu')
        fv4 = surfaces.Surface(filename=rdir+'2840698_5_6_hippo_L_reg.byu_10_6.5_2.5.byu')
    if sub == '2729611':
        fv1 = surfaces.Surface(filename=rdir+sub+'_1_4_hippo_L_reg.byu_10_6.5_2.5.byu')
        fv2 = surfaces.Surface(filename=rdir+sub+'_2_4_hippo_L_reg.byu_10_6.5_2.5.byu')
        fv3 = surfaces.Surface(filename=rdir+sub+'_3_7_hippo_L_reg.byu_10_6.5_2.5.byu')
        fv4 = surfaces.Surface(filename=rdir+sub+'_4_6_hippo_L_reg.byu_10_6.5_2.5.byu')

    ## Object kernel
    K1 = Kernel(name='laplacian', sigma = 6.5, order=4)


    sm = surfaceMatching.SurfaceMatchingParam(timeStep=0.1, KparDiff=K1, sigmaDist=2.5, sigmaError=1., errorType='varifold')
    f = (match.SurfaceMatching(Template=fv1, Targets=(fv2,fv3,fv4), outputDir=outputDir, param=sm,
                               typeRegression='geodesic',
                          affine='euclidean', testGradient=False, affineWeight=.1,  maxIter=1000, controlWeight=1.))
    #, affine='none', rotWeight=0.1))
    f.optimizeMatching()


    return f
Ejemplo n.º 4
0
def main():

    loggingUtils.setup_default_logging()

    parser = argparse.ArgumentParser(description='runs surface matching registration over directories (relative to the template)')
    parser.add_argument('template', metavar='template', type = str, help='template')
    parser.add_argument('target', metavar='target', type = str, help='target')
    parser.add_argument('--typeKernel', metavar='typeKernel', type=str, dest='typeKernel', default = 'gauss', help='kernel type') 
    parser.add_argument('--sigmaKernel', metavar='sigmaKernel', type=float, dest='sigmaKernel', default = 6.5, help='kernel width') 
    parser.add_argument('--sigmaDist', metavar='sigmaDist', type=float, dest='sigmaDist', default = 2.5, help='kernel width (error term); (default = 2.5)') 
    parser.add_argument('--sigmaError', metavar='sigmaError', type=float, dest='sigmaError', default = 1.0, help='std error; (default = 1.0)') 
    parser.add_argument('--typeError', metavar='typeError', type=str, dest='typeError', default = 'varifold', help='type error term (default: varifold)') 
    parser.add_argument('--dirOut', metavar = 'dirOut', type = str, dest = 'dirOut', default = '', help='Output directory')
    parser.add_argument('--tmpOut', metavar = 'tmpOut', type = str, dest = 'tmpOut', default = '', help='info files directory')
    parser.add_argument('--rigid', action = 'store_true', dest = 'rigid', default = False, help='Perform Rigid Registration First')
    parser.add_argument('--logFile', metavar = 'logFile', type = str, dest = 'logFile', default = 'info.txt', help='Output log file')
    parser.add_argument('--stdout', action = 'store_true', dest = 'stdOutput', default = False, help='To also print on standard output')
    parser.add_argument('--scaleFactor', metavar='scaleFactor', type=float, dest='scaleFactor',
                        default = 1, help='scale factor for all surfaces') 
    parser.add_argument('--atrophy', action = 'store_true', dest = 'atrophy', default = False, help='force atrophy')
    parser.add_argument('--symmetric', action = 'store_true', dest = 'symmetric', default = False, help='Use error term on both template and target')
    args = parser.parse_args()

    if args.dirOut == '':
        args.dirOut = '.'

    if args.tmpOut == '':
        args.tmpOut = args.dirOut + '/tmp'
    if not os.path.exists(args.dirOut):
        os.makedirs(args.dirOut)
    if not os.path.exists(args.tmpOut):
        os.makedirs(args.tmpOut)
    loggingUtils.setup_default_logging(fileName=args.tmpOut+'/'+args.logFile, stdOutput = args.stdOutput)

    if args.atrophy:
        import surfaceMatchingAtrophy as smt
    else:
        import surfaceMatching as smt

    tmpl = surfaces.Surface(filename=args.template)
    tmpl.vertices *= args.scaleFactor
    K1 = Kernel(name=args.typeKernel, sigma = args.sigmaKernel)
    sm = smt.SurfaceMatchingParam(timeStep=0.1, KparDiff=K1, sigmaDist=args.sigmaDist, sigmaError=args.sigmaError, errorType=args.typeError)
    fv = surfaces.Surface(filename=args.target)
    fv.vertices *= args.scaleFactor
    #print fv.vertices

    if args.rigid:
        R0, T0 = rigidRegistration(surfaces = (fv.vertices, tmpl.vertices),  verb=False, temperature=10., annealing=True)
        fv.updateVertices(np.dot(fv.vertices, R0.T) + T0)

        #print fv.vertices

    if args.atrophy:
        f = smt.SurfaceMatching(Template=tmpl, Target=fv, outputDir=args.tmpOut,param=sm, testGradient=False, mu = 0.001, symmetric=args.symmetric,
                            maxIter_cg=1000, affine= 'euclidean', rotWeight=.01, transWeight = .01, scaleWeight=10., affineWeight=100.)
    else:
        f = smt.SurfaceMatching(Template=tmpl, Target=fv, outputDir=args.tmpOut,param=sm, testGradient=False, symmetric=args.symmetric,
                            maxIter=1000, affine= 'euclidean', rotWeight=.01, transWeight = .01, scaleWeight=10., affineWeight=100.)

    f.optimizeMatching()
    u = path.split(args.target)
    [nm,ext] = path.splitext(u[1])
    f.fvDef.savebyu(args.dirOut+'/'+nm+'Def.byu')
Ejemplo n.º 5
0
    def computeMatching(self):
        (rg,N,T) = self.getSimData()
        for it in range(500):
            self.optimizeN()
            conjugateGradient.cg(self, True, \
                        maxIter = self.nonlinear_cg_max_iter, \
                        TestGradient=True, epsInit=self.cg_init_eps)
            if (it % self.write_iter == 0):
                self.writeData("iter%d" % (it))
        return self

if __name__ == "__main__":
    # set permanent options
    output_directory_base = metamorphosisConfig.compute_output_dir
    #output_directory_base = "./"
    # set options from command line
    parser = optparse.OptionParser()
    parser.add_option("-o", "--output_dir", dest="output_dir")
    parser.add_option("-c", "--config_name", dest="config_name")
    (options, args) = parser.parse_args()
    output_dir = output_directory_base + options.output_dir
    # remove any old results in the output directory
    if os.access(output_dir, os.F_OK):
        shutil.rmtree(output_dir)
    os.mkdir(output_dir)
    loggingUtils.setup_default_logging(output_dir, metamorphosisConfig)
    logging.info(options)
    sim = Metamorphosis(output_dir, options.config_name)
    sim.computeMatching()
    sim.writeData("final")
Ejemplo n.º 6
0
import imageTimeSeries
import imageTimeSeriesConfig
import optparse
import os
import shutil
import logging
import loggingUtils

output_directory_base = imageTimeSeriesConfig.compute_output_dir
# set options from command line
parser = optparse.OptionParser()
parser.add_option("-o", "--output_dir", dest="output_dir")
parser.add_option("-c", "--config_name", dest="config_name")
parser.add_option("-f", "--file_base", dest="fbase")
(options, args) = parser.parse_args()
output_dir = output_directory_base + options.output_dir
# remove any old results in the output directory
if os.access(output_dir, os.F_OK):
    shutil.rmtree(output_dir)
os.mkdir(output_dir)
loggingUtils.setup_default_logging(output_dir, imageTimeSeriesConfig)
logging.info(options)
its = imageTimeSeries.ImageTimeSeries(output_dir, options.config_name)
its.loadData(options.fbase)
logging.info("Begin computing maps.")
its.computeMaps()
logging.info("Done.")
Ejemplo n.º 7
0
def compute():

    outputDir = '/Users/younes/Development/Results/twoBallsStitched2'
    #outputDir = '/cis/home/younes/MorphingData/twoBallsStitched'
    #outputDir = '/Users/younes/Development/Results/tight_stitched_rigid2_10'
    if __name__ == "__main__":
        loggingUtils.setup_default_logging(outputDir, fileName='info')
    else:
        loggingUtils.setup_default_logging()


    if False:
        Tg = 2000
        npt = 100.0
        ## Build Two colliding ellipses
        [x,y,z] = np.mgrid[0:2*npt, 0:2*npt, 0:2*npt]/npt
        y = y-1
        z = z-1
        x = x-1
        s2 = np.sqrt(2)

        I1 = .06 - ((x+.2)**2 + 0.5*(y-0.25)**2 + (z)**2)  
        fv1 = Surface() ;
        fv1.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])

        I1 = .06 - ((x-.2)**2 + 0.5*(y+0.25)**2 + (z)**2) 
        fv2 = Surface() ;
        fv2.Isosurface(I1, value=0, target=Tg, scales=[1, 1, 1])
    
        u = (z + y)/s2
        v = (z - y)/s2
        I1 = .095 - ((x+.25)**2 + (v)**2 + 0.5*(u+.25)**2) 
        fv3 = Surface() ;
        fv3.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])

        u = (z + y)/s2
        v = (z - y)/s2
        I1 = .095 - ((x-.25)**2 + (v)**2 + 0.5*(u-.25)**2) 
        fv4 = Surface() ;
        fv4.Isosurface(I1, value=0, target=Tg, scales=[1, 1, 1])
    else:
        fv1 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere1.obj')
        fv2 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere2.obj')
        fv3 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere1b.obj')
        fv4 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere2b.obj')
        fv1.vertices *= 100 ;
        fv2.vertices *= 100 ;
        fv3.vertices *= 100 ;
        fv4.vertices *= 100 ;

    ## Object kernel
    K1 = Kernel(name='laplacian', sigma = 50.0, order=4)
    ## Background kernel
    K2 = Kernel(name='laplacian', sigma = 10.0, order=2)


    sm = SurfaceMatchingParam(timeStep=0.1, KparDiff=K1, KparDiffOut=K2, sigmaDist=50., sigmaError=10., errorType='varifold')
    f = (SurfaceMatching(Template=(fv1,fv2), Target=(fv3,fv4), outputDir=outputDir, param=sm, mu=.1,regWeightOut=1.,
                          testGradient=False, typeConstraint='stitched', maxIter_cg=1000, maxIter_al=100, affine='none', rotWeight=0.1))
    f.optimizeMatching()


    return f
Ejemplo n.º 8
0
    letter_match = None
    if options.config_name == "letter":
        digitId = 11
        templateId = 18
        output_dir_old = output_dir
        for targetId in range(39):
            letter_match = (digitId,templateId,targetId)
            output_dir = "%s_%d_%d_%d" % (output_dir_old, letter_match[0],\
                            letter_match[1], letter_match[2])
                # remove any old results in the output directory
            if os.access(output_dir, os.F_OK):
                shutil.rmtree(output_dir)
            os.mkdir(output_dir)
            if targetId == 0:
                loggingUtils.setup_default_logging(output_dir, smoothImageConfig)
            logging.info(options)
            sim = SmoothImageMeta(output_dir, options.config_name, letter_match)
            sim.computeMatching()
            sim.writeData("final")
    else:
        # remove any old results in the output directory
        if os.access(output_dir, os.F_OK):
            shutil.rmtree(output_dir)
        os.mkdir(output_dir)
        loggingUtils.setup_default_logging(output_dir, smoothImageConfig)
        logging.info(options)
        sim = SmoothImageMeta(output_dir, options.config_name, None)
        sim.computeMatching()
        sim.writeData("final")
Ejemplo n.º 9
0
def compute(args=None, noArgs=True):
    if noArgs:
        outputDir = '/Users/younes/Development/Results/multiShapes'
        #outputDir = '/cis/home/younes/MorphingData/twoBallsStitched'
        #outputDir = '/Users/younes/Development/Results/tight_stitched_rigid2_10'
        loggingUtils.setup_default_logging()

        if False:
            Tg = 2000
            npt = 100.0
            ## Build Two colliding ellipses
            [x,y,z] = np.mgrid[0:2*npt, 0:2*npt, 0:2*npt]/npt
            y = y-1
            z = z-1
            x = x-1
            s2 = np.sqrt(2)
    
            I1 = .06 - ((x+.2)**2 + 0.5*(y-0.25)**2 + (z)**2)  
            fv1 = Surface() ;
            fv1.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])
    
            I1 = .06 - ((x-.2)**2 + 0.5*(y+0.25)**2 + (z)**2) 
            fv2 = Surface() ;
            fv2.Isosurface(I1, value=0, target=Tg, scales=[1, 1, 1])
        
            u = (z + y)/s2
            v = (z - y)/s2
            I1 = .095 - ((x+.25)**2 + (v)**2 + 0.5*(u+.25)**2) 
            fv3 = Surface() ;
            fv3.Isosurface(I1, value = 0, target=Tg, scales=[1, 1, 1])
    
            u = (z + y)/s2
            v = (z - y)/s2
            I1 = .095 - ((x-.25)**2 + (v)**2 + 0.5*(u-.25)**2) 
            fv4 = Surface() ;
            fv4.Isosurface(I1, value=0, target=Tg, scales=[1, 1, 1])
        else:
            fv1 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere1.obj')
            fv2 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere2.obj')
            fv3 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere1b.obj')
            fv4 = Surface(filename='/Users/younes/Development/Data/Surfaces/fshpere2b.obj')
            fv1.vertices *= 100
            fv2.vertices *= 100
            fv3.vertices *= 100
            fv4.vertices *= 100
            fTmpl = (fv1, fv2)
            fTarg = (fv3, fv4)
        ## Object kernel
        K1 = Kernel(name='laplacian', sigma = 50.0, order=4)
        ## Background kernel
        K2 = Kernel(name='laplacian', sigma = 10.0, order=2)
        typeConstraint = 'stitched'
        sm = SurfaceMatchingParam(timeStep=0.1, KparDiff=K1, KparDiffOut=K2,
                                  sigmaDist=50., sigmaError=10., errorType='varifold')
        mu = 0.1 ;
    else:
        fTmpl = []
        for name in args.template:
            fTmpl.append(Surface(filename=name))
        for f in fTmpl:
            f.vertices *= args.scaleFactor
        fTarg = []
        for name in args.target:
            fTarg.append(Surface(filename=name))
        for f in fTarg:
            f.vertices *= args.scaleFactor
        ## Object kernel
        K1 = Kernel(name='laplacian', sigma = args.sigmaKernelIn, order=4)
        ## Background kernel
        K2 = Kernel(name='laplacian', sigma = args.sigmaKernelOut, order=2)
        sm = SurfaceMatchingParam(timeStep=0.1, KparDiff=K1, KparDiffOut=K2,
                                  sigmaDist=args.sigmaDist, sigmaError=args.sigmaError, errorType=args.typeError)
        outputDir = args.dirOut
        loggingUtils.setup_default_logging(fileName=outputDir+args.logFile, stdOutput = args.stdOutput)
        if args.sliding:
            typeConstraint = 'slidingV2'
        else:
            typeConstraint = 'stitched'
        mu = args.mu
        
    f = (SurfaceMatching(Template=fTmpl, Target=fTarg, outputDir=outputDir, param=sm, mu=mu,regWeightOut=1.,
                          testGradient=False, typeConstraint=typeConstraint, maxIter_cg=1000, maxIter_al=100, affine='none', rotWeight=0.1))
    f.optimizeMatching()


    return f