def getBestAlignForImage(self, image, radonimage, reflist, radonreflist,
                             oldshift):
        aligndata = {}
        aligndata['bestcc'] = -1.0
        for j in range(len(reflist)):
            for shiftrad in range(0, self.params['shiftmax'],
                                  self.params['shiftstep']):
                radonimage
                radonref = radonreflist[j]
                radoncc = radermacher.radonshift(radonimage, radonref,
                                                 shiftrad)

                value = radoncc.argmax()
                ### FUTURE: use peakfinder to get subpixel peak
                col = value % radoncc.shape[1]  #rotation angle
                row = int(value / radoncc.shape[1])  #shift angle
                cc = radoncc[row, col]
                #print value, col, row, cc

                if cc > aligndata['bestcc']:
                    ### calculate parameters
                    ### FUTURE: get shift list rather than angle list
                    anglelist = radermacher.getAngles(shiftrad)
                    shiftangle = anglelist[col]
                    xshift = shiftrad * math.sin(shiftangle)
                    yshift = shiftrad * math.cos(shiftangle)
                    rotangle = row * self.params['stepsize']

                    ### save values
                    aligndata['bestcc'] = cc
                    aligndata['xshift'] = math.ceil(xshift)
                    aligndata['yshift'] = math.ceil(yshift)
                    aligndata['rotangle'] = rotangle
                    aligndata['refid'] = j
        #print ("ref %02d | %.8f | x %2d y %2d ang %.1f"
        #	%(aligndata['refid'],aligndata['bestcc'], aligndata['xshift'],
        #	aligndata['yshift'], aligndata['rotangle']))
        if oldshift is not None:
            aligndata['xshift'] += oldshift['xshift']
            aligndata['yshift'] += oldshift['yshift']
        return aligndata
	def getBestAlignForImage(self, image, radonimage, reflist, radonreflist, oldshift):
		aligndata = {}
		aligndata['bestcc'] = -1.0
		for j in range(len(reflist)):
			for shiftrad in range(0, self.params['shiftmax'], self.params['shiftstep']):
				radonimage
				radonref = radonreflist[j]
				radoncc = radermacher.radonshift(radonimage, radonref, shiftrad)

				value = radoncc.argmax()
				### FUTURE: use peakfinder to get subpixel peak
				col = value % radoncc.shape[1] #rotation angle
				row = int(value/radoncc.shape[1]) #shift angle
				cc = radoncc[row,col]
				#print value, col, row, cc

				if cc > aligndata['bestcc']:
					### calculate parameters
					### FUTURE: get shift list rather than angle list
					anglelist = radermacher.getAngles(shiftrad)
					shiftangle = anglelist[col]
					xshift = shiftrad*math.sin(shiftangle)
					yshift = shiftrad*math.cos(shiftangle)
					rotangle = row*self.params['stepsize']

					### save values
					aligndata['bestcc'] = cc
					aligndata['xshift'] = math.ceil(xshift)
					aligndata['yshift'] = math.ceil(yshift)
					aligndata['rotangle'] = rotangle
					aligndata['refid'] = j
		#print ("ref %02d | %.8f | x %2d y %2d ang %.1f"
		#	%(aligndata['refid'],aligndata['bestcc'], aligndata['xshift'], 
		#	aligndata['yshift'], aligndata['rotangle']))
		if oldshift is not None:
			aligndata['xshift'] += oldshift['xshift']
			aligndata['yshift'] += oldshift['yshift']
		return aligndata
        noiselevel = 2.0

        a = createDots(angle=0., noiselevel=noiselevel, shape=shape)
        b = createDots(angle=-30., noiselevel=noiselevel, shape=shape, shift=(3,4))
        imagefile.arrayToJpeg(a, "imagea.jpg")
        imagefile.arrayToJpeg(b, "imageb.jpg")

        ar = radonTransform(a, stepsize)
        br = radonTransform(b, stepsize)
        imagefile.arrayToJpeg(ar, "radona.jpg")
        imagefile.arrayToJpeg(br, "radonb.jpg")

        #print "%.3f"%(a[1,0])
        #print "%.3f"%(b[1,0])
        for radius in range(0,11,2):
                e = radermacher.radonshift(ar,br,radius)
                e = e / (ar.std()*br.std()) # result is not normalized properly
                val = e.argmax()
                y = val%e.shape[1]
                x = int(val/e.shape[1])
                anglelist = radermacher.getAngles(radius)
                shiftangle = anglelist[y]
                xshift = radius*math.sin(shiftangle)
                yshift = radius*math.cos(shiftangle)
                rotangle = stepsize*x
                print "Radius %02d, Max value %.16f at rot=%d, shift=%.1f,%.1f"%(radius, e.max(), rotangle, xshift, yshift)
                imagefile.arrayToJpeg(e, "radoncc%02d.jpg"%(radius), msg=False)
        print "mem used = %.1f MB"%((mem.used()-u)/1024.)
        print "done"
        #sys.exit(1)
	noiselevel = 2.0

	a = createDots(angle=0., noiselevel=noiselevel, shape=shape)
	b = createDots(angle=-30., noiselevel=noiselevel, shape=shape, shift=(3,4))
	imagefile.arrayToJpeg(a, "imagea.jpg")
	imagefile.arrayToJpeg(b, "imageb.jpg")

	ar = radonTransform(a, stepsize)
	br = radonTransform(b, stepsize)
	imagefile.arrayToJpeg(ar, "radona.jpg")
	imagefile.arrayToJpeg(br, "radonb.jpg")

	#print "%.3f"%(a[1,0])
	#print "%.3f"%(b[1,0])
	for radius in range(0,11,2):
		e = radermacher.radonshift(ar,br,radius)
		e = e / (ar.std()*br.std()) # result is not normalized properly
		val = e.argmax()
		y = val%e.shape[1]
		x = int(val/e.shape[1])
		anglelist = radermacher.getAngles(radius)
		shiftangle = anglelist[y]
		xshift = radius*math.sin(shiftangle)
		yshift = radius*math.cos(shiftangle)
		rotangle = stepsize*x
		print "Radius %02d, Max value %.16f at rot=%d, shift=%.1f,%.1f"%(radius, e.max(), rotangle, xshift, yshift)
		imagefile.arrayToJpeg(e, "radoncc%02d.jpg"%(radius), msg=False)
	print "mem used = %.1f MB"%((mem.used()-u)/1024.)
	print "done"
	#sys.exit(1)