Ejemplo n.º 1
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)
Ejemplo n.º 2
0
Archivo: moire1.py Proyecto: nvh/moire
"""
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)
Ejemplo n.º 3
0
"""
Simple moire with two gratings encoding two color images
"""
import moirelib as m

T = 1.0 / 40  # grating period as fraction of image width
offset = 1.0 / 8  # offset as a fraction of the image height

print "Loading images..."
img = (m.prepImage("audrey", mag=4, sigma=(0, T / 4, 0)), m.prepImage("mona", mag=4, sigma=(0, T / 4, 0)))
fig = m.figure(figsize=(8, 10))
m.show(img[0], 321, "original")
m.show(img[1], 322, "original")

print "generating gratings..."
offset = round(offset * img[0].shape[0])  # convert to pixels
dims = img[0].shape
dims = (dims[0] + offset, dims[1], dims[2])
g1 = m.makeCarrier(dims, T)
g2 = g1.copy()

# iterative adjustment of gratings to images
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 gratings
    err1 = (1 - img[0]) / 2 - (g1[:-offset, :, :] - g2[offset:, :, :])
Ejemplo n.º 4
0
import ntpath

input1 = sys.argv[1] if len(sys.argv) > 1 else 'audrey'
input2 = sys.argv[2] if len(sys.argv) > 2 else 'mona'
dpi = int(sys.argv[3]) if len(sys.argv) > 3 else 300
grating = int(sys.argv[4]) if len(sys.argv) > 4 else 40

offset = 1. / 8  # offset as a fraction of the image height
T = 1. / grating  # grating period as fraction of image width

filename1 = ntpath.basename(input1)
filename2 = ntpath.basename(input2)
combinedFilename = filename1 + '+' + filename2 + '-(' + str(grating) + ')'

print 'Loading images...'
img = (m.prepImage(input1, mag=1, sigma=(0, T / 4, 0)),
       m.prepImage(input2, mag=1, sigma=(0, T / 4, 0)))
fig = m.figure(figsize=(8, 10))
m.show(img[0], 321, 'original')
m.show(img[1], 322, 'original')

print 'generating gratings...'
offset = round(offset * img[0].shape[0])  # convert to pixels
dims = img[0].shape
dims = (dims[0] + offset, dims[1], dims[2])
g1 = m.makeCarrier(dims, T)
g2 = g1.copy()

# iterative adjustment of gratings to images
L = 0.04  # learning rate
niter = 1000  # of iterations