Exemple #1
1
offset = round(offset*img.shape[0])  # convert to pixels
dims = (img.shape[0]+offset, img.shape[1], img.shape[2])
g = m.makeCarrier(dims, T)

print 'computing gratings...'
L = 0.04    # learning rate
niter = 501   # of iterations

for i in range(niter):
    if i % 25 == 0:
        print "iteration [%4d/%4d]" % (i, niter)

    # update grating
    err = (1-img)/2 - (g[0:-offset,:,:] - g[offset:,:,:])
    g[0:-offset,:,:] += L*err
    g[offset:,:,:]   -= L*err
    g = m.smoothenPhase(g, 1e-4/T)

print 'saving image...'
g = m.makeGrating(g)

# visualize gratings 
m.show(g, 312, 'grating')

# visualize superpositions
e = m.ones((offset, img.shape[1], img.shape[2]))
s = m.vstack((e, g))*m.vstack((g, e)) 
m.show(s, 313, 'superposition')

fig.savefig('./results/moire3.png', dpi=300)
Exemple #2
0
Simple moire with a single color image
"""

import moirelib as m

T = 1./40        # grating period

print 'pre-processing images...'
img = m.prepImage('audrey', mag=2, sigma=(0,T/4., 0))
fig = m.figure(figsize=(8,10))
m.show(img, 311, 'original')

print 'generating gratings...'
carrier = m.makeCarrier(img.shape, T)
g1 = carrier-(1-img)/4
g2 = carrier+(1-img)/4

print 'smoothing phase...'
g1 = m.smoothenPhase(g1, 1e-3/T, 50)
g2 = m.smoothenPhase(g2, 1e-3/T, 50)

print 'saving images...'
g1 = m.makeGrating(g1)
g2 = m.makeGrating(g2)
m.show(g1,323, 'grating 1')
m.show(g2,324, 'grating 2')
m.show(g1*g2, 313, 'superposition')

fig.savefig('./results/moire1.png', dpi=300)

Exemple #3
0
"""
Simple moire with a single color image
"""

import moirelib as m

T = 1. / 40  # grating period

print 'pre-processing images...'
img = m.prepImage('audrey', mag=2, sigma=(0, T / 4., 0))
fig = m.figure(figsize=(8, 10))
m.show(img, 311, 'original')

print 'generating gratings...'
carrier = m.makeCarrier(img.shape, T)
g1 = carrier - (1 - img) / 4
g2 = carrier + (1 - img) / 4

print 'smoothing phase...'
g1 = m.smoothenPhase(g1, 1e-3 / T, 50)
g2 = m.smoothenPhase(g2, 1e-3 / T, 50)

print 'saving images...'
g1 = m.makeGrating(g1)
g2 = m.makeGrating(g2)
m.show(g1, 323, 'grating 1')
m.show(g2, 324, 'grating 2')
m.show(g1 * g2, 313, 'superposition')

fig.savefig('./results/moire1.png', dpi=300)
Exemple #4
0
offset = round(offset * img.shape[0])  # convert to pixels
dims = (img.shape[0] + offset, img.shape[1], img.shape[2])
g = m.makeCarrier(dims, T)

print 'computing gratings...'
L = 0.04  # learning rate
niter = 501  # of iterations

for i in range(niter):
    if i % 25 == 0:
        print "iteration [%4d/%4d]" % (i, niter)

    # update grating
    err = (1 - img) / 2 - (g[0:-offset, :, :] - g[offset:, :, :])
    g[0:-offset, :, :] += L * err
    g[offset:, :, :] -= L * err
    g = m.smoothenPhase(g, 1e-4 / T)

print 'saving image...'
g = m.makeGrating(g)

# visualize gratings
m.show(g, 312, 'grating')

# visualize superpositions
e = m.ones((offset, img.shape[1], img.shape[2]))
s = m.vstack((e, g)) * m.vstack((g, e))
m.show(s, 313, 'superposition')

fig.savefig('./results/moire3.png', dpi=300)