def goShifts2(): f, g = getSinoImages() f = copy(ni, nx, f) g = copy(ni + nl, nx, g) h = copy(f) sf = Sampling(ni) sg = Sampling(ni + nl) dw = DynamicWarpingR(sl.first, sl.last, si, sx) dw.setStrainLimits(0.0, 5.0, -0.2, 0.2) dw.setSmoothness(50, 50) u = dw.findShifts(sf, f, sg, g) v = vpvs(u) h = dw.applyShifts(sg, g, u) d = sub(h, f) print "nrms(h,f) =", nrms2(h, f) zoom = True plotImage(f, fmax=5, pp=True, zoom=zoom) plotImage(h, fmax=5, pp=True, zoom=zoom, png="pw2z") plotImage(d, fmax=5, pp=True, zoom=zoom, png="pd2z") if zoom: plotImage(v, fmin=1.9, fmax=2.3, pp=True, zoom=zoom) plotImage(u, fmin=150, fmax=250, pp=True, zoom=zoom, cv=True) else: plotImage(v, fmin=1.5, fmax=2.5, pp=True, zoom=zoom) plotImage(u, fmin=50, fmax=350, pp=True, zoom=zoom, cv=True)
def goTeaser(): f, g = getSinoImages() f = copy(ni, nx, f) g = copy(ni + nl, nx, g) h = copy(f) sf = Sampling(ni) sg = Sampling(ni + nl) dw = DynamicWarpingR(sl.first, sl.last, si, sx) dw.setStrainLimits(0.0, 5.0, -0.2, 0.2) dw.setSmoothness(50, 50) u = dw.findShifts(sf, f, sg, g) h = dw.applyShifts(sg, g, u) plotTeaser(f, fmax=5, png="ppt") plotTeaser(h, fmax=5, png="pst") plotTeaser(u, fmin=150, fmax=250, cv=True, png="ut")
def goWrite(): f, g = getSinoImages() f = copy(ni, nx, f) g = copy(ni + nl, nx, g) h = copy(f) sf = Sampling(ni) sg = Sampling(ni + nl) dw = DynamicWarpingR(sl.first, sl.last, si, sx) dw.setStrainLimits(0.0, 2.0, -0.1, 0.1) dw.setSmoothness(50, 20) u = dw.findShifts(sf, f, sg, g) h = dw.applyShifts(sg, g, u) print "max Tps =", max(add(rampfloat(0.0, 1.0, 0.0, ni, nx), u)) writeImage("pp.dat", f) writeImage("ps.dat", g) writeImage("pswarped.dat", h) writeImage("shifts.dat", u)
def goShifts2(): f, g = getSinoImages() f = copy(ni, nx, f) g = copy(ni + nl, nx, g) h = copy(f) sf = Sampling(ni) sg = Sampling(ni + nl) dw = DynamicWarpingR(sl.first, sl.last, si, sx) dw.setStrainLimits(0.0, 2.0, -0.1, 0.1) dw.setSmoothness(50, 20) u = dw.findShifts(sf, f, sg, g) v = vpvs(u) h = dw.applyShifts(sg, g, u) d = sub(h, f) print "nrms(h,f) =", nrms2(h, f) zoom = True #plotImage(f,fmax=5,pp=True,zoom=zoom) plotImage(h, fmax=5, pp=True, zoom=zoom, png="pw2z") plotImage(d, fmax=5, pp=True, zoom=zoom, png="pd2z") """
def goShifts1(): f, g = getSinoImages() f = copy(ni, nx, f) g = copy(ni + nl, nx, g) h = copy(f) e = computeErrors(nx, f, g) sf = Sampling(ni) sg = Sampling(ni + nl) ix = nx / 2 dw = DynamicWarpingR(sl.first, sl.last, si) dw.setStrainLimits(0.0, 2.0) plotImage(f, fmax=5, pp=True, zoom=True) for hs in [50]: dw.setSmoothness(hs) u = dw.findShifts(e) for ix in range(nx): h[ix] = dw.applyShifts(sg, g[ix], u) d = sub(h, f) print "nrms(h,f) =", nrms2(h, f) plotImage(h, fmax=5, pp=True, zoom=True, png="pw1z") plotImage(d, fmax=5, pp=True, zoom=True, png="pd1z")
def warp1(f, g): smin, smax = 0.0, 3.0 dw = DynamicWarpingR(smin, smax, s1, s2) ss = dw.getSamplingS() ns, n1, n2 = ss.count, s1.count, s2.count e = zerofloat(ns, n1) for i2 in range(n2 / 2 - 11, n2 / 2 + 12): ei = dw.computeErrors(sf, f[i2], sg, g[i2]) add(ei, e, e) dw.normalizeErrors(e) def plotShifts(): sp = SimplePlot() sp.setSize(1400, 500) pv = sp.addPixels(s1, ss, pow(transpose(e), 1.0)) pv.setInterpolation(PixelsView.Interpolation.NEAREST) pv.setColorModel(ColorMap.GRAY) pv.setPercentiles(2, 98) #pv = sp.addPoints(sf,mul(sf.delta,u1)) plotShifts()