Ejemplo n.º 1
0
import numpy as np

from demo_data import chelsea
from supreme.register.parzen import joint_hist, mutual_info
from supreme.transform import homography
import supreme.register as register

import sys
if len(sys.argv) == 3:
    from supreme.io import imread
    A = imread(sys.argv[1], flatten=True).astype(np.uint8)
    Ac = imread(sys.argv[1], flatten=False).astype(np.uint8)
    B = imread(sys.argv[2], flatten=True).astype(np.uint8)
    Bc = imread(sys.argv[2], flatten=False).astype(np.uint8)
else:
    A = chelsea(grey=True).astype(np.uint8)
    Ac = A
    t = 20/180. * np.pi
    x = 3
    y = 6
    B = homography(A, [[np.cos(t), -np.sin(t), x],
                       [np.sin(t),  np.cos(t), y],
                       [0,            0,       1]])
    Bc = B

M, S = register.dense_MI(A, B, levels=3, std=5, win_size=9)
print "Mutual information: ", S
if S < 1.5:
    print "Warning: registration probably failed."

print "Transformation matrix:"
Ejemplo n.º 2
0
import numpy as np
from numpy.testing import *

import scipy.ndimage as ndi
import scipy.linalg
import scipy.sparse as sparse

from supreme.geometry.window import gauss
from supreme.resolve.operators import bilinear, convolve, block_diag
from supreme.io import imread

import os

HR = imread(os.path.join(os.path.dirname(__file__), 'peppers_40.png'),
            flatten=True)


def test_bilinear():
    H = np.array([[1 / 2., 0, 0], [0, 1 / 2., 0], [0, 0, 1]])
    A = bilinear(HR.shape[0], HR.shape[1], [H, H], HR.shape[0] / 2,
                 HR.shape[1] / 2)

    p = np.prod(HR.shape)
    assert_equal(A.shape, (2 * p / 4, np.prod(HR.shape)))

    HR_small = (A[p / 4:, :] * HR.flat).reshape(np.array(HR.shape) / 2)
    err_norm = np.linalg.norm(ndi.zoom(HR, 0.5) - HR_small)
    err_norm /= np.prod(HR_small.shape)

    assert err_norm < 2
Ejemplo n.º 3
0
 def setup(self):
     self.X = imread(os.path.join(os.path.dirname(__file__),
                                  '../../lib/pywt/demo/data/aero.png'))
Ejemplo n.º 4
0
from supreme.config import data_path
from supreme import transform
from supreme.io import imread, ImageCollection
from supreme.transform import matrix as homography
from supreme.feature import dpt

import supreme.register

# This used to do log polar transforms, but now
# we just match the distributions of the coefficients
from supreme.register.correspond import correspond

# ----------------------------------------------------------------------

if len(sys.argv) == 3:
    icc = [imread(sys.argv[i]) for i in (1, 2)]
    ic = [imread(sys.argv[i], flatten=True) for i in (1, 2)]
    imgc0 = icc[0]
    img0 = ic[0]
    imgc1 = icc[1]
    img1 = ic[1]
else:
    icc = ImageCollection(os.path.join(data_path, 'pathfinder/i44*.png'))
    ic = ImageCollection(os.path.join(data_path, 'pathfinder/i44*.png'),
                         grey=True)

    imgc0 = icc[0]
    imgc1 = icc[7]
    img0 = ic[0]
    img1 = ic[7]
Ejemplo n.º 5
0
print "Images adjusted by: %s" % str(['%.2f, %.2f' % (a,b)
                                      for (a,b) in scale_offset])

images = [img for i,img in enumerate(images) if not i in options.ignore]

HH = [i.info['H'] for i in images]
oshape = np.floor(np.array(images[0].shape) * options.scale)
avg = initial_guess_avg(images, HH, options.scale, oshape)

#
# Update solution one frame at a time
#
if options.update:
    if options.previous_result:
        res = imread(options.previous_result, flatten=True)
        err = []

    out = avg.copy()
    for j in range(1):
        print "SR iteration %d" % j
        for i in range(len(images)):
            print "Resolving frame %d" % i
            out = solve([images[i]], [HH[i]], scale=options.scale, tol=0,
                        x0=out, damp=options.damp, iter_lim=200,
                        method=options.method, operator=options.operator,
                        norm=options.norm)

            if options.previous_result:
                if not res.shape == out.shape:
                    raise RuntimeError('Previous result specified for '
Ejemplo n.º 6
0
import sys
if len(sys.argv) < 2:
    parser.print_help()
    sys.exit(0)

vgg = sys.argv[-1]

if not os.path.isdir(vgg):
    raise RuntimeError("Cannot open VGG directory")

img_dir = [d for d in os.listdir(vgg) if d in ['pgm', 'png', 'jpg']]
if not img_dir:
    raise RuntimeError("Cannot find images inside VGG directory")
img_dir = img_dir[0]

images = [imread(i, flatten=True).astype(np.uint8) for i in
          glob(os.path.join(os.path.join(vgg, img_dir), '*.' + img_dir))]

H_dir = os.path.join(vgg, 'H')
if not os.path.isdir(H_dir):
    os.mkdir(H_dir)

A = images[0]
M_0A = np.eye(3)
for i, img in enumerate(images[1:]):
    print "Registering %d -> %d" % (i, i + 1)
    B = images[i + 1]
    M_0B, S = register.dense_MI(B, A, levels=options.levels + 1,
                                std=3, win_size=9,
                                translation_only=options.translation,
                                fixed_scale=options.fixed_scale)
Ejemplo n.º 7
0
import numpy as np

from demo_data import chelsea
from supreme.register.parzen import joint_hist, mutual_info
from supreme.transform import homography
import supreme.register as register

import sys
if len(sys.argv) == 3:
    from supreme.io import imread
    A = imread(sys.argv[1], flatten=True).astype(np.uint8)
    Ac = imread(sys.argv[1], flatten=False).astype(np.uint8)
    B = imread(sys.argv[2], flatten=True).astype(np.uint8)
    Bc = imread(sys.argv[2], flatten=False).astype(np.uint8)
else:
    A = chelsea(grey=True).astype(np.uint8)
    Ac = A
    t = 20 / 180. * np.pi
    x = 3
    y = 6
    B = homography(
        A, [[np.cos(t), -np.sin(t), x], [np.sin(t), np.cos(t), y], [0, 0, 1]])
    Bc = B

M, S = register.dense_MI(A, B, levels=3, std=5, win_size=9)
print "Mutual information: ", S
if S < 1.5:
    print "Warning: registration probably failed."

print "Transformation matrix:"
print np.array2string(M, separator=', ')
Ejemplo n.º 8
0
from supreme.config import data_path
from supreme import transform
from supreme.io import imread, ImageCollection
from supreme.transform import matrix as homography
from supreme.feature import dpt

import supreme.register

# This used to do log polar transforms, but now
# we just match the distributions of the coefficients
from supreme.register.correspond import correspond

# ----------------------------------------------------------------------

if len(sys.argv) == 3:
    icc = [imread(sys.argv[i]) for i in (1, 2)]
    ic = [imread(sys.argv[i], flatten=True) for i in (1, 2)]
    imgc0 = icc[0]
    img0 = ic[0]
    imgc1 = icc[1]
    img1 = ic[1]
else:
    icc = ImageCollection(os.path.join(data_path, 'pathfinder/i44*.png'))
    ic = ImageCollection(os.path.join(data_path, 'pathfinder/i44*.png'),
                         grey=True)

    imgc0 = icc[0]
    imgc1 = icc[7]
    img0 = ic[0]
    img1 = ic[7]
Ejemplo n.º 9
0
if len(sys.argv) < 2:
    parser.print_help()
    sys.exit(0)

vgg = sys.argv[-1]

if not os.path.isdir(vgg):
    raise RuntimeError("Cannot open VGG directory")

img_dir = [d for d in os.listdir(vgg) if d in ['pgm', 'png', 'jpg']]
if not img_dir:
    raise RuntimeError("Cannot find images inside VGG directory")
img_dir = img_dir[0]

images = [
    imread(i, flatten=True).astype(np.uint8)
    for i in glob(os.path.join(os.path.join(vgg, img_dir), '*.' + img_dir))
]

H_dir = os.path.join(vgg, 'H')
if not os.path.isdir(H_dir):
    os.mkdir(H_dir)

A = images[0]
M_0A = np.eye(3)
for i, img in enumerate(images[1:]):
    print "Registering %d -> %d" % (i, i + 1)
    B = images[i + 1]
    M_0B, S = register.dense_MI(B,
                                A,
                                levels=options.levels + 1,
Ejemplo n.º 10
0
print "Images adjusted by: %s" % str(
    ['%.2f, %.2f' % (a, b) for (a, b) in scale_offset])

images = [img for i, img in enumerate(images) if not i in options.ignore]

HH = [i.info['H'] for i in images]
oshape = np.floor(np.array(images[0].shape) * options.scale)
avg = initial_guess_avg(images, HH, options.scale, oshape)

#
# Update solution one frame at a time
#
if options.update:
    if options.previous_result:
        res = imread(options.previous_result, flatten=True)
        err = []

    out = avg.copy()
    for j in range(1):
        print "SR iteration %d" % j
        for i in range(len(images)):
            print "Resolving frame %d" % i
            out = solve([images[i]], [HH[i]],
                        scale=options.scale,
                        tol=0,
                        x0=out,
                        damp=options.damp,
                        iter_lim=200,
                        method=options.method,
                        operator=options.operator,
Ejemplo n.º 11
0
import numpy as np
from numpy.testing import *

import scipy.ndimage as ndi
import scipy.linalg
import scipy.sparse as sparse

from supreme.geometry.window import gauss
from supreme.resolve.operators import bilinear, convolve, block_diag
from supreme.io import imread

import os

HR = imread(os.path.join(os.path.dirname(__file__), 'peppers_40.png'),
            flatten=True)

def test_bilinear():
    H = np.array([[1/2., 0,    0],
                  [0,    1/2., 0],
                  [0,    0,    1]])
    A = bilinear(HR.shape[0], HR.shape[1],
                 [H, H],
                 HR.shape[0] / 2, HR.shape[1]/2)

    p = np.prod(HR.shape)
    assert_equal(A.shape, (2 * p/4, np.prod(HR.shape)))

    HR_small = (A[p/4:, :] * HR.flat).reshape(np.array(HR.shape) / 2)
    err_norm = np.linalg.norm(ndi.zoom(HR, 0.5) - HR_small)
    err_norm /= np.prod(HR_small.shape)