def Run(N,dim,rodrigues,prefix,J=0.00008,PtoA=1.5,Image=False,Dump=False,dovtk=False,verbose=0):
    output = prefix+str(J)+"_"+str(PtoA)

    rod = numpy.zeros([3]+list(rodrigues['x'].numpy_array().shape), dtype='float64')
    rod[0] = rodrigues['x']
    rod[1] = rodrigues['y']
    rod[2] = rodrigues['z']
    orientationmap = OrientationField.RodriguesToUnambiguousColor(rod[0],rod[1],rod[2])
    rod = rod.transpose(range(1,len(rod.shape))+[0]).copy()
 
    omega    = rod.flatten().astype('float64')
    mis      = numpy.zeros((2*dim)*N**dim, dtype='float64')
    grain    = numpy.zeros((2*dim)*N**dim, dtype='int32')
    bdlength = numpy.zeros((2*dim)*N**dim, dtype='int32')
    indexmap = numpy.zeros(N**dim, dtype='int32')
    
    status, ngrain, nbd = bp.boundary_pruning(N, dim, omega, mis, grain, bdlength, indexmap, J, PtoA, verbose)

    if Image == True:
        if dim == 2 :
            GetReconstructionWithBoundary2D(N,orientationmap,output,indexmap=indexmap.reshape(N,N))
        if dim == 3:
            GetReconstructionWithBoundary3D(N,orientationmap,output,indexmap=indexmap.reshape(N,N,N),dovtk=dovtk)
                     
    if Dump == True:
        pickle.dump(mis[:nbd], open("%s.mis.pickle" % output, "w"), protocol=-1)
        pickle.dump(grain[:ngrain], open("%s.grain.pickle" % output, "w"), protocol=-1)
        pickle.dump(bdlength[:nbd], open("%s.bdlength.pickle" % output, "w"), protocol=-1)
        pickle.dump(indexmap, open("%s.indexmap.pickle" % output, "w"), protocol=-1)

    if dim == 3:
        return mis[:nbd], grain[:ngrain], bdlength[:nbd], indexmap.reshape(N,N,N)
    return mis[:nbd], grain[:ngrain], bdlength[:nbd], indexmap.reshape(N,N)
Example #2
0
    """
    # I don't have working PIL! skip for now
    #from PIL import Image
    import Image
    pilImage = Image.fromarray(neworientationmap.astype('uint8'), 'RGB')
    pilImage.save(filename+'.png')


output = "out"
lena = True

if lena == True:
    N = 128
    rod = misc.imread("lena.jpg")
else:
    N = 1024 
    rod = misc.imread("earth.jpg")

#rod = rod.transpose([1,0,2])
omega    = rod.flatten().astype('float64')
mis      = numpy.zeros(4*N**2, dtype='float64')
grain    = numpy.zeros(4*N**2, dtype='int32')
bdlength = numpy.zeros(4*N**2, dtype='int32')
#FIXME - need to be modified
indexmap = numpy.zeros(N**2, dtype='int32')


status, ngrain, nbd = bp.boundary_pruning(N, 2, omega, mis, grain, bdlength, indexmap, 180, 1.5)
print status, ngrain, nbd
GetReconstructionWithBoundary(N,rod,output,indexmap=indexmap.reshape(N,N))