Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
0
def test_image_blank_n_channels():
    image = Image(np.zeros((6, 4, 7)))
    image_blank = Image.blank((6, 4), n_channels=7)
    assert(np.all(image_blank.pixels == image.pixels))
Exemplo n.º 4
0
def test_image_blank_fill():
    image = Image(np.ones((6, 4, 1)) * 7)
    image_blank = Image.blank((6, 4), fill=7)
    assert(np.all(image_blank.pixels == image.pixels))
Exemplo n.º 5
0
def test_image_blank():
    image = Image(np.zeros((6, 4, 1)))
    image_blank = Image.blank((6, 4))
    assert(np.all(image_blank.pixels == image.pixels))
Exemplo n.º 6
0
def test_rescale_to_diagonal():
    image = Image.blank((8, 6), n_channels=2)
    assert image.diagonal == 10
    rescaled = image.rescale_to_diagonal(5)
    assert rescaled.shape == (4, 3)
    assert rescaled.n_channels == 2
Exemplo n.º 7
0
def test_diagonal_kchannel_ndim():
    image = Image.blank((100, 250, 50), n_channels=5)
    assert image.diagonal == (100**2 + 250**2 + 50**2)**0.5
Exemplo n.º 8
0
 def _set_up(self):
     # work out feature length per patch
     patch_img = Image.blank(self.patch_shape, fill=0)
     self._feature_patch_length = compute_features(
         patch_img, self.regression_features).n_parameters
Exemplo n.º 9
0
def test_diagonal_kchannel_ndim():
    image = Image.blank((100, 250, 50), n_channels=5)
    assert image.diagonal == (100 ** 2 + 250 ** 2 + 50 ** 2) ** 0.5
Exemplo n.º 10
0
def test_image_blank_n_channels():
    image = Image(np.zeros((6, 4, 7)))
    image_blank = Image.blank((6, 4), n_channels=7)
    assert (np.all(image_blank.pixels == image.pixels))
Exemplo n.º 11
0
def test_image_blank_fill():
    image = Image(np.ones((6, 4, 1)) * 7)
    image_blank = Image.blank((6, 4), fill=7)
    assert (np.all(image_blank.pixels == image.pixels))
Exemplo n.º 12
0
def test_image_blank():
    image = Image(np.zeros((6, 4, 1)))
    image_blank = Image.blank((6, 4))
    assert (np.all(image_blank.pixels == image.pixels))
Exemplo n.º 13
0
 def _set_up(self):
     # work out feature length per patch
     patch_img = Image.blank(self.patch_shape, fill=0)
     self._feature_patch_length = self.regression_features(
         patch_img).n_parameters
Exemplo n.º 14
0
from collections import OrderedDict
import numpy as np
from nose.tools import raises
from nose.plugins.attrib import attr
from menpo.image import Image
from menpo.landmark import LandmarkGroup
from menpo.shape import TriMesh, TexturedTriMesh, ColouredTriMesh, PointCloud


fake_triangle = np.array([[0.0, 0.0, 0.0],
                          [1.0, 0.0, 0.0],
                          [0.0, 1.0, 0.0]])
fake_trilist = np.array([[0, 1, 2]], dtype=np.uint32)
fake_texture = Image.blank([10, 10])
fake_tcoords = np.array([[0, 0], [0.5, 0.5], [1.0, 1.0]])


@raises(ImportError)
@attr('viewing')
def trimesh_viewer_test():
    TriMesh(fake_triangle, trilist=fake_trilist, copy=False).view()


@raises(ImportError)
@attr('viewing')
def textured_trimesh_viewer_test():
    TexturedTriMesh(fake_triangle, fake_tcoords, fake_texture,
                    trilist=fake_trilist, copy=False).view()


@raises(ImportError)
Exemplo n.º 15
0
def test_diagonal_greyscale():
    image = Image.blank((100, 250), n_channels=1)
    assert image.diagonal == (100 ** 2 + 250 ** 2) ** 0.5
Exemplo n.º 16
0
def test_diagonal_greyscale():
    image = Image.blank((100, 250), n_channels=1)
    assert image.diagonal == (100**2 + 250**2)**0.5
Exemplo n.º 17
0
def test_diagonal_color():
    image = Image.blank((100, 250), n_channels=3)
    assert image.diagonal == (100 ** 2 + 250 ** 2) ** 0.5
Exemplo n.º 18
0
def test_diagonal_color():
    image = Image.blank((100, 250), n_channels=3)
    assert image.diagonal == (100**2 + 250**2)**0.5
Exemplo n.º 19
0
def test_rescale_to_diagonal():
    image = Image.blank((8, 6), n_channels=2)
    assert image.diagonal == 10
    rescaled = image.rescale_to_diagonal(5)
    assert rescaled.shape == (4, 3)
    assert rescaled.n_channels == 2
Exemplo n.º 20
0
from collections import OrderedDict
import numpy as np
from nose.tools import raises
from menpo.image import Image
from menpo.landmark import LandmarkGroup
from menpo.shape import TriMesh, TexturedTriMesh, ColouredTriMesh, PointCloud

fake_triangle = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
fake_trilist = np.array([[0, 1, 2]], dtype=np.uint32)
fake_texture = Image.blank([10, 10])
fake_tcoords = np.array([[0, 0], [0.5, 0.5], [1.0, 1.0]])


@raises(ImportError)
def trimesh_viewer_test():
    TriMesh(fake_triangle, trilist=fake_trilist, copy=False).view()


@raises(ImportError)
def textured_trimesh_viewer_test():
    TexturedTriMesh(fake_triangle,
                    fake_tcoords,
                    fake_texture,
                    trilist=fake_trilist,
                    copy=False).view()


@raises(ImportError)
def coloured_trimesh_viewer_test():
    ColouredTriMesh(fake_triangle,
                    colours=fake_tcoords,