示例#1
0
def test_affine(image, template, p):
    """
    Tests image registration using a affine deformation model.
    """

    affine = register.Register(model.Affine, metric.Residual, sampler.Spline)

    # Coerce the image data into RegisterData.
    image = register.RegisterData(image)
    template = register.RegisterData(template)

    step, _search = affine.register(image, template)

    assert np.allclose(p, step.p, atol=0.5), \
        "Estimated p: {} not equal to p: {}".format(
            step.p,
            p
            )
示例#2
0
def test_shift(image, template, method, p):
    """
    Tests image registration using a shift deformation model.
    """

    shift = register.Register()

    # Coerce the image data into RegisterData.
    image = register.RegisterData(image)
    template = register.RegisterData(template)

    step, _search = shift.register(image,
                                   template,
                                   model.Shift(),
                                   method=method)

    assert np.allclose(p, step.p, atol=0.5), \
        "Estimated p: {} not equal to p: {}".format(
            step.p,
            p
            )
示例#3
0
    p = spline_model.identity
    #TODO: Understand the effect of parameter magnitude:
    p += np.random.rand(p.shape[0]) * 100 - 50

    return spline_sampler.f(image, spline_model.warp(p)).reshape(image.shape)


image = misc.lena()
template = warp(image)

# Coerce the image data into RegisterData.
image = register.RegisterData(image).downsample(5.0)
template = register.RegisterData(template).downsample(5.0)

# Form the affine registration instance.
affine = register.Register(model.Affine, metric.Residual, sampler.Spline)

# Form the spline registration instance.
spline = register.Register(model.CubicSpline, metric.Residual, sampler.Spline)

# Compute an affine registration between the template and image.
step, search = affine.register(
    image,
    template,
)

# Compute a nonlinear (spline) registration, initialized with the warp field
# found using the affine registration.
step, _search = spline.register(image,
                                template,
                                displacement=step.displacement,
示例#4
0
    http://en.wikipedia.org/wiki/Lenna
"""

import scipy.ndimage as nd
import scipy.misc as misc

from imreg import register, model, metric
from imreg.samplers import sampler

# Form some test data (lena, lena rotated 20 degrees)
image = misc.lena()
template = nd.rotate(image, 20, reshape=False)

# Form the affine registration instance.
affine = register.Register(
    model.Affine,
    metric.Residual,
    sampler.CubicConvolution
    )

# Coerce the image data into RegisterData.
image = register.RegisterData(image).downsample(2)
template = register.RegisterData(template).downsample(2)

# Register.
step, search = affine.register(
    image,
    template,
    verbose=True,
    )
示例#5
0
    p = mymodel.identity
    #TODO: Understand the effect of parameter magnitude:
    p += np.random.rand(p.shape[0]) * 0.1 - 0.05

    return mysampler.f(image, mymodel.warp(p)).reshape(image.shape)


image = misc.lena().astype(np.double)
image = nd.zoom(image, 0.30)
template = warp(image)

# Coerce the image data into RegisterData.
image = register.RegisterData(image)
template = register.RegisterData(template)

# Smooth the template and image.
image.smooth(0.5)
template.smooth(0.5)

# Form the affine registration instance.
reg = register.Register(model.Projective, metric.Residual,
                        sampler.CubicConvolution)

# Compute an affine registration between the template and image.
step, search = reg.register(
    image,
    template,
    alpha=0.00002,
    verbose=True,
)