示例#1
0
def test_warp_to_mask_boolean():
    b = BooleanImage.blank((10, 10))
    b.pixels[:, :5] = False
    template_mask = BooleanImage.blank((10, 10))
    template_mask.pixels[:5, :] = False
    t = Affine.identity(2)
    warped_mask = b.warp_to_mask(template_mask, t)
    assert(type(warped_mask) == BooleanImage)
    result = template_mask.pixels.copy()
    result[:, :5] = False
    assert(np.all(result == warped_mask.pixels))
示例#2
0
def test_mask_false_indices():
    mask = BooleanImage.blank((64, 14, 51), fill=True)
    mask.mask[0, 2, 5] = False
    mask.mask[5, 13, 4] = False
    false_indices = mask.false_indices
    false_indices_test = np.array([[0, 2, 5], [5, 13, 4]])
    assert_equal(false_indices, false_indices_test)
示例#3
0
def test_mask_false_indices():
    mask = BooleanImage.blank((64, 14, 51), fill=True)
    mask.mask[0, 2, 5] = False
    mask.mask[5, 13, 4] = False
    false_indices = mask.false_indices
    false_indices_test = np.array([[0, 2, 5], [5, 13, 4]])
    assert_equal(false_indices, false_indices_test)
示例#4
0
def test_boolean_image_from_vector_no_copy_raises():
    vector = np.zeros(16, dtype=np.bool)
    image = BooleanImage.blank((4, 4))
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        image.from_vector(vector[::-1], copy=False)
        assert len(w) == 1
示例#5
0
def test_mask_true_indices():
    mask = BooleanImage.blank((64, 14, 51), fill=False)
    mask.mask[0, 2, 5] = True
    mask.mask[5, 13, 4] = True
    true_indices = mask.true_indices
    true_indices_test = np.array([[0, 2, 5], [5, 13, 4]])
    assert_equal(true_indices, true_indices_test)
示例#6
0
def test_mask_true_indices():
    mask = BooleanImage.blank((64, 14, 51), fill=False)
    mask.mask[0, 2, 5] = True
    mask.mask[5, 13, 4] = True
    true_indices = mask.true_indices
    true_indices_test = np.array([[0, 2, 5], [5, 13, 4]])
    assert_equal(true_indices, true_indices_test)
示例#7
0
def test_boolean_bounds_false():
    mask = BooleanImage.blank((8, 8), fill=True)
    mask.pixels[1, 2] = False
    mask.pixels[5, 4] = False
    mask.pixels[3:2, 3] = False
    min_b, max_b = mask.bounds_false()
    assert (np.all(min_b == np.array([1, 2])))
    assert (np.all(max_b == np.array([5, 4])))
示例#8
0
def test_mask_n_true_n_false():
    mask = BooleanImage.blank((64, 14), fill=False)
    assert_equal(mask.n_true(), 0)
    assert_equal(mask.n_false(), 64 * 14)
    mask.mask[0, 0] = True
    mask.mask[9, 13] = True
    assert_equal(mask.n_true(), 2)
    assert_equal(mask.n_false(), 64 * 14 - 2)
示例#9
0
def test_boolean_bounds_false():
    mask = BooleanImage.blank((8, 8), fill=True)
    mask.pixels[1, 2] = False
    mask.pixels[5, 4] = False
    mask.pixels[3:2, 3] = False
    min_b, max_b = mask.bounds_false()
    assert(np.all(min_b == np.array([1, 2])))
    assert(np.all(max_b == np.array([5, 4])))
示例#10
0
def test_mask_n_true_n_false():
    mask = BooleanImage.blank((64, 14), fill=False)
    assert_equal(mask.n_true, 0)
    assert_equal(mask.n_false, 64 * 14)
    mask.mask[0, 0] = True
    mask.mask[9, 13] = True
    assert_equal(mask.n_true, 2)
    assert_equal(mask.n_false, 64 * 14 - 2)
示例#11
0
def test_warp_to_mask_masked_image():
    mask = BooleanImage.blank((10, 10))
    # make a funny mask on the original image
    mask.pixels[2:, :] = False
    img = MaskedImage.blank((10, 10), n_channels=2, mask=mask)
    img.pixels[...] = 2.5
    template_mask = BooleanImage.blank((10, 10), fill=False)
    template_mask.pixels[:5, :5] = True
    t = Affine.identity(2)
    warped_img = img.warp_to_mask(template_mask, t)
    assert(type(warped_img) == MaskedImage)
    result = Image.blank((10, 10), n_channels=2).pixels
    result[:5, :5, :] = 2.5
    result_mask = BooleanImage.blank((10, 10), fill=False).pixels
    result_mask[:2, :5] = True
    assert(warped_img.n_true_pixels() == 10)
    assert(np.all(result == warped_img.pixels))
    assert(np.all(result_mask == warped_img.mask.pixels))
示例#12
0
def test_mask_true_bounding_extent():
    mask = BooleanImage.blank((64, 14, 51), fill=False)
    mask.mask[0, 13, 5] = True
    mask.mask[5, 2, 4] = True
    tbe = mask.bounds_true()
    true_extends_mins = np.array([0, 2, 4])
    true_extends_maxs = np.array([5, 13, 5])
    assert_equal(tbe[0], true_extends_mins)
    assert_equal(tbe[1], true_extends_maxs)
示例#13
0
def test_mask_true_bounding_extent():
    mask = BooleanImage.blank((64, 14, 51), fill=False)
    mask.mask[0, 13, 5] = True
    mask.mask[5, 2, 4] = True
    tbe = mask.bounds_true()
    true_extends_mins = np.array([0, 2, 4])
    true_extends_maxs = np.array([5, 13, 5])
    assert_equal(tbe[0], true_extends_mins)
    assert_equal(tbe[1], true_extends_maxs)
示例#14
0
def test_warp_to_mask_image():
    img = Image.blank((10, 10), n_channels=2)
    img.pixels[:, :5, :] = 0.5
    template_mask = BooleanImage.blank((10, 10))
    template_mask.pixels[5:, :] = False
    t = Affine.identity(2)
    warped_img = img.warp_to_mask(template_mask, t)
    assert(type(warped_img) == MaskedImage)
    result = Image.blank((10, 10), n_channels=2).pixels
    result[:5, :5, :] = 0.5
    assert(np.all(result == warped_img.pixels))
示例#15
0
def test_mask_blank_rounding_floor():
    mask = BooleanImage.blank((56.1, 12.1), round='floor')
    assert_allclose(mask.shape, (56, 12))
示例#16
0
def test_boolean_image_invert_inplace():
    image = BooleanImage.blank((4, 4))
    image.invert_inplace()
    assert (np.all(image.pixels == False))
示例#17
0
def test_boolean_prevent_order_kwarg():
    mask = BooleanImage.blank((8, 8), fill=True)
    mask.warp_to_mask(mask, None, order=4)
示例#18
0
def test_boolean_image_false_indices():
    image = BooleanImage.blank((2, 3))
    assert(image.__str__() == '3W x 2H 2D mask, 100.0% of which is True')
示例#19
0
def test_boolean_image_from_vector_no_copy():
    vector = np.zeros(16, dtype=np.bool)
    image = BooleanImage.blank((4, 4))
    image2 = image.from_vector(vector, copy=False)
    assert(is_same_array(image2.pixels.ravel(), vector))
示例#20
0
def test_boolean_image_from_vector_no_copy_raises():
    vector = np.zeros(16, dtype=np.bool)
    image = BooleanImage.blank((4, 4))
    image.from_vector(vector[::-1], copy=False)
示例#21
0
def test_boolean_image_proportion_sums():
    image = BooleanImage.blank((10, 10))
    image.pixels[:7] = False
    assert(image.proportion_true() + image.proportion_false() == 1)
示例#22
0
def test_boolean_image_from_vector_no_copy():
    vector = np.zeros(16, dtype=np.bool)
    image = BooleanImage.blank((4, 4))
    image2 = image.from_vector(vector, copy=False)
    assert (is_same_array(image2.pixels.ravel(), vector))
示例#23
0
def test_boolean_image_invert_inplace_double_noop():
    image = BooleanImage.blank((4, 4))
    image.invert_inplace()
    image.invert_inplace()
    assert (np.all(image.pixels))
示例#24
0
def test_boolean_image_str():
    image = BooleanImage.blank((2, 3))
    assert (image.__str__() == '3W x 2H 2D mask, 100.0% of which is True')
示例#25
0
def test_boolean_image_from_vector():
    vector = np.zeros(16, dtype=np.bool)
    image = BooleanImage.blank((4, 4))
    image2 = image.from_vector(vector)
    assert (np.all(image2.as_vector() == vector))
示例#26
0
def test_boolean_image_false_indices():
    image = BooleanImage.blank((2, 3))
    image.pixels[0, 1] = False
    image.pixels[1, 2] = False
    assert (np.all(image.false_indices() == np.array([[0, 1], [1, 2]])))
示例#27
0
def test_boolean_image_proportion_sums():
    image = BooleanImage.blank((10, 10))
    image.pixels[:7] = False
    assert (image.proportion_true() + image.proportion_false() == 1)
示例#28
0
def test_boolean_image_wrong_round():
    BooleanImage.blank((12, 12), round='ads')
示例#29
0
def test_mask_blank_rounding_round():
    mask = BooleanImage.blank((56.1, 12.6), round='round')
    assert_allclose(mask.shape, (56, 13))
示例#30
0
def test_boolean_image_invert():
    image = BooleanImage.blank((4, 4))
    image2 = image.invert()
    assert (np.all(image.pixels))
    assert (np.all(~image2.pixels))
示例#31
0
def test_warp_to_shape_boolean_preserves_path():
    i1 = BooleanImage.blank((10, 10))
    i1.path = Path('.')
    i2 = i1.rescale(0.8)
    assert hasattr(i2, 'path')
    assert i2.path == i1.path
示例#32
0
def test_boolean_image_proportion_false():
    image = BooleanImage.blank((10, 10))
    image.pixels[:7] = False
    assert(image.proportion_false == 0.7)
示例#33
0
def test_boolean_image_wrong_round():
    BooleanImage.blank((12, 12), round='ads')
示例#34
0
def test_boolean_prevent_order_kwarg():
    mask = BooleanImage.blank((8, 8), fill=True)
    mask.warp_to_mask(mask, None, order=4)
示例#35
0
def test_boolean_image_false_indices():
    image = BooleanImage.blank((2, 3))
    image.pixels[0, 1] = False
    image.pixels[1, 2] = False
    assert(np.all(image.false_indices() == np.array([[0, 1],
                                                     [1, 2]])))
示例#36
0
def test_boolean_image_invert_inplace():
    image = BooleanImage.blank((4, 4))
    image.invert_inplace()
    assert(np.all(image.pixels == False))
示例#37
0
def test_boolean_image_from_vector():
    vector = np.zeros(16, dtype=np.bool)
    image = BooleanImage.blank((4, 4))
    image2 = image.from_vector(vector)
    assert(np.all(image2.as_vector() == vector))
示例#38
0
def test_boolean_image_invert():
    image = BooleanImage.blank((4, 4))
    image2 = image.invert()
    assert(np.all(image.pixels == True))
    assert(np.all(image2.pixels == False))
示例#39
0
from menpo.image import BooleanImage
import menpo.io as pio
from menpo.transform import Affine

from menpo.fit.lucaskanade.image import (ImageInverseCompositional,
                                         ImageForwardAdditive)
from menpo.fit.lucaskanade.residual import *


target_shape = (90, 90)

# Setup the static assets (the takeo image)
takeo = pio.import_builtin_asset('takeo.ppm')
image = takeo.as_greyscale()
template_mask = BooleanImage.blank(target_shape)

# Setup global conditions
initial_params = np.array([0, 0, 0, 0, 70.5, 30.5])
target_params = np.array([0, 0.2, 0.1, 0, 70, 30])


def compute_rms_point_error(test_pts, template_affine, M):
    iteration_pts = M.apply(template_affine.T)
    diff_pts = test_pts - iteration_pts
    return np.sqrt(np.mean(diff_pts ** 2))


def setup_conditions(interpolator):
    target_transform = Affine.identity(2).from_vector(target_params)
    image_warped = image.warp_to(template_mask, target_transform,
示例#40
0
def test_boolean_image_proportion_false():
    image = BooleanImage.blank((10, 10))
    image.pixels[:7] = False
    assert (image.proportion_false == 0.7)
示例#41
0
def test_boolean_image_invert_inplace_double_noop():
    image = BooleanImage.blank((4, 4))
    image.invert_inplace()
    image.invert_inplace()
    assert(np.all(image.pixels == True))
示例#42
0
def test_warp_to_mask_preserves_path():
    bb = menpo.io.import_builtin_asset.breakingbad_jpg()
    no_op = UniformScale(1.0, n_dims=2)
    bb2 = bb.warp_to_mask(BooleanImage.blank((10, 10)), no_op)
    assert hasattr(bb2, 'path')
    assert bb2.path == bb.path
示例#43
0
import numpy as np
import menpo
from numpy.testing import assert_allclose
from menpo.image import BooleanImage, Image, MaskedImage
from menpo.transform import Affine
import menpo.io as mio

# do the import to generate the expected outputs
rgb_image = mio.import_builtin_asset('takeo.ppm')
gray_image = rgb_image.as_greyscale()
gray_template = gray_image.crop(np.array([70, 30]),
                                np.array([169, 129]))
rgb_template = rgb_image.crop(np.array([70, 30]),
                              np.array([169, 129]))
template_mask = BooleanImage.blank(gray_template.shape)

initial_params = np.array([0, 0, 0, 0, 70, 30])
row_indices, col_indices = np.meshgrid(np.arange(50, 100), np.arange(50, 100),
                                       indexing='ij')
row_indices, col_indices = row_indices.flatten(), col_indices.flatten()
multi_expected = rgb_image.crop([50, 50],
                                [100, 100]).pixels.flatten()


def test_warp_gray():
    rgb_image = mio.import_builtin_asset('takeo.ppm')
    gray_image = rgb_image.as_greyscale()
    target_transform = Affine.identity(2).from_vector(initial_params)
    warped_im = gray_image.warp_to_mask(template_mask, target_transform)

    assert(warped_im.shape == gray_template.shape)
示例#44
0
def test_mask_blank_rounding_ceil():
    mask = BooleanImage.blank((56.1, 12.1), round='ceil')
    assert_allclose(mask.shape, (57, 13))
示例#45
0
def test_mask_blank():
    mask = BooleanImage.blank((56, 12, 3))
    assert (np.all(mask.pixels))
示例#46
0
def test_mask_blank_rounding_round():
    mask = BooleanImage.blank((56.1, 12.6), round='round')
    assert_allclose(mask.shape, (56, 13))
示例#47
0
def test_mask_blank_rounding_ceil():
    mask = BooleanImage.blank((56.1, 12.1), round='ceil')
    assert_allclose(mask.shape, (57, 13))
示例#48
0
def test_mask_blank_false_fill():
    mask = BooleanImage.blank((56, 12, 3), fill=False)
    assert (np.all(~mask.pixels))
示例#49
0
def test_mask_blank_false_fill():
    mask = BooleanImage.blank((56, 12, 3), fill=False)
    assert (np.all(~mask.pixels))
示例#50
0
def test_rescale_boolean():
    mask = BooleanImage.blank((100, 100))
    mask.resize((10, 10))
示例#51
0
def test_mask_blank():
    mask = BooleanImage.blank((56, 12, 3))
    assert (np.all(mask.pixels))
示例#52
0
from numpy.testing import assert_approx_equal

from menpo.image import BooleanImage
import menpo.io as pio
from menpo.transform import Affine

from menpo.fit.lucaskanade.image import (ImageInverseCompositional,
                                         ImageForwardAdditive)
from menpo.fit.lucaskanade.residual import *

target_shape = (90, 90)

# Setup the static assets (the takeo image)
takeo = pio.import_builtin_asset('takeo.ppm')
image = takeo.as_greyscale()
template_mask = BooleanImage.blank(target_shape)

# Setup global conditions
initial_params = np.array([0, 0, 0, 0, 70.5, 30.5])
target_params = np.array([0, 0.2, 0.1, 0, 70, 30])


def compute_rms_point_error(test_pts, template_affine, M):
    iteration_pts = M.apply(template_affine.T)
    diff_pts = test_pts - iteration_pts
    return np.sqrt(np.mean(diff_pts**2))


def setup_conditions(interpolator):
    target_transform = Affine.identity(2).from_vector(target_params)
    image_warped = image.warp_to(template_mask,
示例#53
0
def test_mask_blank_rounding_floor():
    mask = BooleanImage.blank((56.1, 12.1), round='floor')
    assert_allclose(mask.shape, (56, 12))
示例#54
0
def test_boolean_image_as_masked_raises_not_implemented_error():
    b_img = BooleanImage.blank((4, 5))
    b_img.as_masked()