Example #1
0
def test_create_MaskedImage_copy_true_mask_BooleanImage():
    pixels = np.ones((100, 100, 1))
    mask = np.ones((100, 100), dtype=np.bool)
    mask_image = BooleanImage(mask, copy=False)
    image = MaskedImage(pixels, mask=mask_image, copy=True)
    assert (not is_same_array(image.pixels, pixels))
    assert (not is_same_array(image.mask.pixels, mask))
Example #2
0
def test_colouredtrimesh_creation_copy_false():
    points = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
    trilist = np.array([[0, 1, 3], [1, 2, 3]])
    colours = np.ones([4, 13])
    ttm = ColouredTriMesh(points, trilist, colours=colours, copy=False)
    assert (is_same_array(ttm.points, points))
    assert (is_same_array(ttm.trilist, trilist))
    assert (is_same_array(ttm.colours, colours))
Example #3
0
def test_booleanimage_copy():
    pixels = np.ones([10, 10], dtype=np.bool)
    landmarks = PointCloud(np.ones([3, 2]), copy=False)
    im = BooleanImage(pixels, copy=False)
    im.landmarks['test'] = landmarks
    im_copy = im.copy()

    assert (not is_same_array(im.pixels, im_copy.pixels))
    assert (not is_same_array(im_copy.landmarks['test'].lms.points,
                              im.landmarks['test'].lms.points))
Example #4
0
def test_pointcloud_copy_method():
    points = np.array([[1, 2, 3], [1, 1, 1]])
    landmarks = PointCloud(np.ones([3, 3]), copy=False)

    p = PointCloud(points, copy=False)
    p.landmarks["test"] = landmarks
    p_copy = p.copy()

    assert not is_same_array(p_copy.points, p.points)
    assert not is_same_array(p_copy.landmarks["test"].lms.points, p.landmarks["test"].lms.points)
Example #5
0
def test_booleanimage_copy():
    pixels = np.ones([10, 10], dtype=np.bool)
    landmarks = PointCloud(np.ones([3, 2]), copy=False)
    im = BooleanImage(pixels, copy=False)
    im.landmarks["test"] = landmarks
    im_copy = im.copy()

    assert not is_same_array(im.pixels, im_copy.pixels)
    assert not is_same_array(im_copy.landmarks["test"].points,
                             im.landmarks["test"].points)
Example #6
0
def test_trimesh_creation_copy_false():
    points = np.array([[0, 0, 0],
                       [1, 0, 0],
                       [1, 1, 0],
                       [0, 1, 0]])
    trilist = np.array([[0, 1, 3],
                        [1, 2, 3]])
    tm = TriMesh(points, trilist, copy=False)
    assert (is_same_array(tm.points, points))
    assert (is_same_array(tm.trilist, trilist))
Example #7
0
def test_maskedimage_copy():
    pixels = np.ones([1, 10, 10])
    landmarks = PointCloud(np.ones([3, 2]), copy=False)
    im = MaskedImage(pixels, copy=False)
    im.landmarks["test"] = landmarks
    im_copy = im.copy()

    assert not is_same_array(im.pixels, im_copy.pixels)
    assert not is_same_array(im_copy.landmarks["test"].points,
                             im.landmarks["test"].points)
Example #8
0
def test_image_copy():
    pixels = np.ones([1, 10, 10])
    landmarks = PointCloud(np.ones([3, 2]), copy=False)
    im = Image(pixels, copy=False)
    im.landmarks['test'] = landmarks
    im_copy = im.copy()

    assert (not is_same_array(im.pixels, im_copy.pixels))
    assert (not is_same_array(im_copy.landmarks['test'].points,
                              im.landmarks['test'].points))
Example #9
0
def test_maskedimage_copy():
    pixels = np.ones([10, 10, 1])
    landmarks = PointCloud(np.ones([3, 2]), copy=False)
    im = MaskedImage(pixels, copy=False)
    im.landmarks['test'] = landmarks
    im_copy = im.copy()

    assert (not is_same_array(im.pixels, im_copy.pixels))
    assert (im_copy.landmarks['test']._target is im_copy)
    assert (not is_same_array(im_copy.landmarks['test'].lms.points,
                              im.landmarks['test'].lms.points))
Example #10
0
def test_pointcloud_copy_method():
    points = np.array([[1, 2, 3], [1, 1, 1]])
    landmarks = PointCloud(np.ones([3, 3]), copy=False)

    p = PointCloud(points, copy=False)
    p.landmarks["test"] = landmarks
    p_copy = p.copy()

    assert not is_same_array(p_copy.points, p.points)
    assert not is_same_array(p_copy.landmarks["test"].points,
                             p.landmarks["test"].points)
Example #11
0
def test_texturedtrimesh_creation_copy_true():
    points = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
    trilist = np.array([[0, 1, 3], [1, 2, 3]])
    pixels = np.ones([10, 10, 1])
    tcoords = np.ones([4, 2])
    texture = Image(pixels, copy=False)
    ttm = TexturedTriMesh(points, tcoords, texture, trilist=trilist, copy=True)
    assert (not is_same_array(ttm.points, points))
    assert (not is_same_array(ttm.trilist, trilist))
    assert (not is_same_array(ttm.tcoords.points, tcoords))
    assert (not is_same_array(ttm.texture.pixels, pixels))
Example #12
0
def test_colouredtrimesh_creation_copy_true():
    points = np.array([[0, 0, 0],
                       [1, 0, 0],
                       [1, 1, 0],
                       [0, 1, 0]])
    trilist = np.array([[0, 1, 3],
                        [1, 2, 3]])
    colours = np.ones([4, 13])
    ttm = ColouredTriMesh(points, trilist, colours=colours, copy=True)
    assert (not is_same_array(ttm.points, points))
    assert (not is_same_array(ttm.trilist, trilist))
    assert (not is_same_array(ttm.colours, colours))
def test_trimesh_copy():
    points = np.ones([10, 3])
    trilist = np.ones([10, 3])
    landmarks = PointCloud(np.ones([3, 3]), copy=False)

    tmesh = TriMesh(points, trilist=trilist, copy=False)
    tmesh.landmarks['test'] = landmarks
    tmesh_copy = tmesh.copy()

    assert (not is_same_array(tmesh_copy.points, tmesh.points))
    assert (not is_same_array(tmesh_copy.trilist, tmesh.trilist))
    assert (not is_same_array(tmesh_copy.landmarks['test'].lms.points,
                              tmesh.landmarks['test'].lms.points))
Example #14
0
def test_LandmarkManager_set_LabelledPointUndirectedGraph():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)

    man = LandmarkManager()
    man['test_set'] = lgroup
    assert not is_same_array(man['test_set'].points, lgroup.points)
    assert man['test_set']._labels_to_masks is not lgroup._labels_to_masks
Example #15
0
def test_LandmarkManager_set_PointCloud_not_copy_target():
    pcloud = PointCloud(points)

    man = LandmarkManager()
    man['test_set'] = pcloud
    assert not is_same_array(man['test_set'].points, pcloud.points)
    assert_allclose(man['test_set'].points, np.ones([10, 3]))
Example #16
0
def test_texturedtrimesh_creation_copy_true():
    points = np.array([[0, 0, 0],
                       [1, 0, 0],
                       [1, 1, 0],
                       [0, 1, 0]])
    trilist = np.array([[0, 1, 3],
                        [1, 2, 3]])
    pixels = np.ones([10, 10, 1])
    tcoords = np.ones([4, 2])
    texture = Image(pixels, copy=False)
    ttm = TexturedTriMesh(points, tcoords, texture, trilist=trilist,
                          copy=True)
    assert (not is_same_array(ttm.points, points))
    assert (not is_same_array(ttm.trilist, trilist))
    assert (not is_same_array(ttm.tcoords.points, tcoords))
    assert (not is_same_array(ttm.texture.pixels, pixels))
def test_colouredtrimesh_copy():
    points = np.ones([10, 3])
    colours = np.ones([10, 3])
    trilist = np.ones([10, 3])
    landmarks = PointCloud(np.ones([3, 3]), copy=False)

    ctmesh = ColouredTriMesh(points, trilist=trilist, colours=colours,
                             copy=False)
    ctmesh.landmarks['test'] = landmarks
    ctmesh_copy = ctmesh.copy()

    assert (not is_same_array(ctmesh_copy.points, ctmesh.points))
    assert (not is_same_array(ctmesh_copy.trilist, ctmesh.trilist))
    assert (not is_same_array(ctmesh_copy.colours, ctmesh.colours))
    assert (not is_same_array(ctmesh_copy.landmarks['test'].lms.points,
                              ctmesh.landmarks['test'].lms.points))
Example #18
0
def test_LabelledPointUndirectedGraph_copy_false():
    lgroup = LabelledPointUndirectedGraph(
        points, adjacency_matrix, mask_dict, copy=False
    )
    assert is_same_array(lgroup.points, points)
    assert lgroup._labels_to_masks is mask_dict
    assert lgroup.adjacency_matrix is adjacency_matrix
Example #19
0
def test_LandmarkGroup_copy_true():
    points = np.ones((10, 3))
    mask_dict = {'all': np.ones(10, dtype=np.bool)}
    pcloud = PointCloud(points, copy=False)
    lgroup = LandmarkGroup(None, 'label', pcloud, mask_dict)
    assert (not is_same_array(lgroup.lms.points, points))
    assert (lgroup._labels_to_masks is not mask_dict)
    assert (lgroup.lms is not pcloud)
Example #20
0
def test_LandmarkManager_get():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)

    man = LandmarkManager()
    man._landmark_groups['test_set'] = lgroup

    assert (man['test_set'] is lgroup)
    assert is_same_array(man['test_set'].points, lgroup.points)
Example #21
0
def test_LandmarkManager_set_PointCloud_not_copy_target():
    points = np.ones((10, 3))
    pcloud = PointCloud(points, copy=False)

    man = LandmarkManager()
    man['test_set'] = pcloud
    assert (not is_same_array(man['test_set'].lms.points, pcloud.points))
    assert_allclose(man['test_set']['all'].points, np.ones([10, 3]))
Example #22
0
def test_LandmarkManager_set_LabelledPointUndirectedGraph():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)

    man = LandmarkManager()
    man['test_set'] = lgroup
    assert not is_same_array(man['test_set'].points,
                             lgroup.points)
    assert man['test_set']._labels_to_masks is not lgroup._labels_to_masks
Example #23
0
def test_LandmarkManager_set_PointCloud_not_copy_target():
    pcloud = PointCloud(points)

    man = LandmarkManager()
    man['test_set'] = pcloud
    assert not is_same_array(man['test_set'].points,
                             pcloud.points)
    assert_allclose(man['test_set'].points, np.ones([10, 3]))
Example #24
0
def test_LandmarkGroup_copy_false():
    points = np.ones((10, 3))
    mask_dict = OrderedDict([('all', np.ones(10, dtype=np.bool))])
    pcloud = PointCloud(points, copy=False)
    lgroup = LandmarkGroup(pcloud, mask_dict, copy=False)
    assert (is_same_array(lgroup._pointcloud.points, points))
    assert (lgroup._labels_to_masks is mask_dict)
    assert (lgroup.lms is pcloud)
Example #25
0
def test_LandmarkManager_get():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)

    man = LandmarkManager()
    man._landmark_groups['test_set'] = lgroup

    assert(man['test_set'] is lgroup)
    assert is_same_array(man['test_set'].points, lgroup.points)
def test_LandmarkGroup_copy_false():
    points = np.ones((10, 3))
    mask_dict = OrderedDict([('all', np.ones(10, dtype=np.bool))])
    pcloud = PointCloud(points, copy=False)
    lgroup = LandmarkGroup(pcloud, mask_dict, copy=False)
    assert (is_same_array(lgroup._pointcloud.points, points))
    assert (lgroup._labels_to_masks is mask_dict)
    assert (lgroup.lms is pcloud)
Example #27
0
def test_LandmarkManager_copy_method():
    pcloud = PointCloud(points)

    man = LandmarkManager()
    man["test_set"] = pcloud
    man_copy = man.copy()

    assert man_copy["test_set"] is not man["test_set"]
    assert not is_same_array(man_copy["test_set"].points, man["test_set"].points)
Example #28
0
def test_LandmarkManager_set_PointCloud_not_copy_target():
    points = np.ones((10, 3))
    pcloud = PointCloud(points, copy=False)

    man = LandmarkManager()
    man['test_set'] = pcloud
    assert (not is_same_array(man['test_set'].lms.points,
                              pcloud.points))
    assert_allclose(man['test_set']['all'].points, np.ones([10, 3]))
Example #29
0
def test_LandmarkManager_copy_method():
    pcloud = PointCloud(points)

    man = LandmarkManager()
    man['test_set'] = pcloud
    man_copy = man.copy()

    assert man_copy['test_set'] is not man['test_set']
    assert not is_same_array(man_copy['test_set'].points,
                             man['test_set'].points)
Example #30
0
def test_LabelledPointUndirectedGraph_copy_method():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)
    lgroup_copy = lgroup.copy()

    assert not is_same_array(lgroup_copy.points, lgroup.points)
    # Check the mask dictionary is deepcopied properly
    assert lgroup._labels_to_masks is not lgroup_copy._labels_to_masks
    masks = zip(lgroup_copy._labels_to_masks.values(), lgroup._labels_to_masks.values())
    for ms in masks:
        assert ms[0] is not ms[1]
Example #31
0
def test_LabelledPointUndirectedGraph_add_label():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict_2)

    new_lgroup = lgroup.add_label('lower2', [0, 1])
    assert not is_same_array(new_lgroup.points, lgroup.points)

    lower_pcloud = new_lgroup.get_label('lower2')
    assert lower_pcloud.n_points == 2
    assert_allclose(lower_pcloud.points[0, :], [1., 1., 1.])
    assert_allclose(lower_pcloud.points[1, :], [1., 1., 1.])
Example #32
0
def test_LandmarkManager_iterate():
    pcloud = PointCloud(points)

    man = LandmarkManager()
    man['test_set'] = pcloud
    man['test_set2'] = pcloud
    man['test_set3'] = pcloud

    for l in man:
        assert not is_same_array(man[l].points, pcloud.points)
    assert len(man) == 3
Example #33
0
def test_LandmarkManager_set_LandmarkGroup():
    points = np.ones((10, 3))
    mask_dict = OrderedDict([('all', np.ones(10, dtype=np.bool))])
    pcloud = PointCloud(points, copy=False)
    lgroup = LandmarkGroup(pcloud, mask_dict, copy=False)

    man = LandmarkManager()
    man['test_set'] = lgroup
    assert (not is_same_array(man['test_set'].lms.points, lgroup.lms.points))
    assert_allclose(man['test_set']['all'].points, np.ones([10, 3]))
    assert (man['test_set']._labels_to_masks is not lgroup._labels_to_masks)
Example #34
0
def test_LabelledPointUndirectedGraph_copy_method():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)
    lgroup_copy = lgroup.copy()

    assert not is_same_array(lgroup_copy.points, lgroup.points)
    # Check the mask dictionary is deepcopied properly
    assert lgroup._labels_to_masks is not lgroup_copy._labels_to_masks
    masks = zip(lgroup_copy._labels_to_masks.values(),
                lgroup._labels_to_masks.values())
    for ms in masks:
        assert ms[0] is not ms[1]
Example #35
0
def test_LandmarkManager_copy_method():
    points = np.ones((10, 3))
    pcloud = PointCloud(points, copy=False)

    man = LandmarkManager()
    man['test_set'] = pcloud
    man_copy = man.copy()

    assert (man_copy['test_set'] is not man['test_set'])
    assert (not is_same_array(man_copy['test_set'].lms.points,
                              man['test_set'].lms.points))
Example #36
0
def test_LandmarkManager_iterate():
    pcloud = PointCloud(points)

    man = LandmarkManager()
    man['test_set'] = pcloud
    man['test_set2'] = pcloud
    man['test_set3'] = pcloud

    for l in man:
        assert not is_same_array(man[l].points, pcloud.points)
    assert len(man) == 3
def test_LandmarkManager_copy_method():
    points = np.ones((10, 3))
    pcloud = PointCloud(points, copy=False)

    man = LandmarkManager()
    man['test_set'] = pcloud
    man_copy = man.copy()

    assert (man_copy['test_set'] is not man['test_set'])
    assert (not is_same_array(man_copy['test_set'].lms.points,
                              man['test_set'].lms.points))
Example #38
0
def test_LandmarkManager_set_LandmarkGroup():
    points = np.ones((10, 3))
    mask_dict = OrderedDict([('all', np.ones(10, dtype=np.bool))])
    pcloud = PointCloud(points, copy=False)
    lgroup = LandmarkGroup(pcloud, mask_dict, copy=False)

    man = LandmarkManager()
    man['test_set'] = lgroup
    assert (not is_same_array(man['test_set'].lms.points,
                              lgroup.lms.points))
    assert_allclose(man['test_set']['all'].points, np.ones([10, 3]))
    assert (man['test_set']._labels_to_masks is not lgroup._labels_to_masks)
def test_texturedtrimesh_copy():
    points = np.ones([10, 3])
    tcoords = np.ones([10, 3])
    trilist = np.ones([10, 3])
    landmarks = PointCloud(np.ones([3, 3]), copy=False)
    landmarks_im = PointCloud(np.ones([3, 2]), copy=False)
    pixels = np.ones([10, 10, 1])
    texture = Image(pixels, copy=False)
    texture.landmarks['test_im'] = landmarks_im

    ttmesh = TexturedTriMesh(points, tcoords, texture, trilist=trilist,
                             copy=False)
    ttmesh.landmarks['test'] = landmarks
    ttmesh_copy = ttmesh.copy()

    assert (not is_same_array(ttmesh_copy.points, ttmesh.points))
    assert (not is_same_array(ttmesh_copy.trilist, ttmesh.trilist))
    assert (not is_same_array(ttmesh_copy.tcoords.points,
                              ttmesh.tcoords.points))
    assert (not is_same_array(ttmesh_copy.texture.pixels,
                              ttmesh.texture.pixels))
    assert (not is_same_array(
        ttmesh_copy.texture.landmarks['test_im'].lms.points,
        ttmesh.texture.landmarks['test_im'].lms.points))
    assert (not is_same_array(ttmesh_copy.landmarks['test'].lms.points,
                              ttmesh.landmarks['test'].lms.points))
Example #40
0
def test_LandmarkManager_set_PointCloud_not_copy_target():
    points = np.ones((10, 3))
    pcloud = PointCloud(points, copy=False)
    target = PointCloud(points)

    man = LandmarkManager(target)
    man['test_set'] = pcloud
    print(man['test_set'])
    assert (not is_same_array(man['test_set'].lms.points,
                              pcloud.points))
    assert_allclose(man['test_set']['all'].lms.points, np.ones([10, 3]))
    assert_equal(man['test_set'].group_label, 'test_set')
    assert (man['test_set']._target is target)
Example #41
0
def test_LandmarkManager_copy_method():
    points = np.ones((10, 3))
    pcloud = PointCloud(points, copy=False)
    target = PointCloud(points, copy=True)

    man = LandmarkManager(target)
    man['test_set'] = pcloud
    man_copy = man.copy()

    assert (man_copy._target is man._target)
    assert (man_copy['test_set'] is not man['test_set'])
    assert (not is_same_array(man_copy['test_set'].lms.points,
                              man['test_set'].lms.points))
    assert_equal(man['test_set'].group_label, 'test_set')
Example #42
0
def test_landmarkgroup_copy_method():
    points = np.ones((10, 3))
    mask_dict = OrderedDict([('all', np.ones(10, dtype=np.bool))])
    pcloud = PointCloud(points, copy=False)

    lgroup = LandmarkGroup(pcloud, mask_dict, copy=False)
    lgroup_copy = lgroup.copy()

    assert (not is_same_array(lgroup_copy.lms.points, lgroup.lms.points))
    # Check the mask dictionary is deepcopied properly
    assert (lgroup._labels_to_masks is not lgroup_copy._labels_to_masks)
    masks = zip(lgroup_copy._labels_to_masks.values(),
                lgroup._labels_to_masks.values())
    for ms in masks:
        assert (ms[0] is not ms[1])
Example #43
0
def test_LandmarkManager_set_LandmarkGroup():
    points = np.ones((10, 3))
    mask_dict = {'all': np.ones(10, dtype=np.bool)}
    pcloud = PointCloud(points, copy=False)
    target = PointCloud(points)
    lgroup = LandmarkGroup(None, 'label', pcloud, mask_dict, copy=False)

    man = LandmarkManager(target)
    man['test_set'] = lgroup
    assert (not is_same_array(man['test_set'].lms.points,
                              lgroup.lms.points))
    assert_equal(man['test_set'].group_label, 'test_set')
    assert_allclose(man['test_set']['all'].lms.points, np.ones([10, 3]))
    assert (man['test_set']._labels_to_masks is not lgroup._labels_to_masks)
    assert (man['test_set']._target is target)
Example #44
0
def test_landmarkgroup_copy_method():
    points = np.ones((10, 3))
    mask_dict = OrderedDict([('all', np.ones(10, dtype=np.bool))])
    pcloud = PointCloud(points, copy=False)

    lgroup = LandmarkGroup(pcloud, mask_dict, copy=False)
    lgroup_copy = lgroup.copy()

    assert (not is_same_array(lgroup_copy.lms.points,
                              lgroup.lms.points))
    # Check the mask dictionary is deepcopied properly
    assert (lgroup._labels_to_masks is not lgroup_copy._labels_to_masks)
    masks = zip(lgroup_copy._labels_to_masks.values(),
                lgroup._labels_to_masks.values())
    for ms in masks:
        assert (ms[0] is not ms[1])
Example #45
0
def test_fittingresult_gt_shape():
    pcloud = PointCloud(np.ones([3, 2]))
    fr = MockedFittingResult(gt_shape=pcloud)
    assert (is_same_array(fr.gt_shape.points, pcloud.points))
Example #46
0
def test_image_from_vector_no_copy():
    pixels = np.random.rand(10, 20, 2)
    pixels2 = np.random.rand(10, 20, 2)
    image = Image(pixels)
    image2 = image.from_vector(pixels2.ravel(), copy=False)
    assert (is_same_array(image2.pixels, pixels2))
Example #47
0
def test_create_MaskedImage_copy_true_mask_array():
    pixels = np.ones((100, 100))
    mask = np.ones((100, 100), dtype=np.bool)
    image = MaskedImage(pixels, mask=mask)
    assert (not is_same_array(image.pixels, pixels))
    assert (not is_same_array(image.mask.pixels, mask))
Example #48
0
def test_pointcloud_copy_false():
    points = np.array([[1, 2, 3],
                       [1, 1, 1]])
    p = PointCloud(points, copy=False)
    assert (is_same_array(p.points, points))
Example #49
0
def test_pointcloud_copy_true():
    points = np.array([[1, 2, 3],
                       [1, 1, 1]])
    p = PointCloud(points)
    assert (not is_same_array(p.points, points))
Example #50
0
def test_create_image_copy_true():
    pixels = np.ones((100, 100, 1))
    image = Image(pixels)
    assert (not is_same_array(image.pixels, pixels))
Example #51
0
def test_create_image_copy_false():
    pixels = np.ones((100, 100, 1))
    image = Image(pixels, copy=False)
    assert (is_same_array(image.pixels, pixels))
Example #52
0
def test_LabelledPointUndirectedGraph_copy_true():
    lgroup = LabelledPointUndirectedGraph(points, adjacency_matrix, mask_dict)
    assert not is_same_array(lgroup.points, points)
    assert lgroup._labels_to_masks is not mask_dict
    assert lgroup.adjacency_matrix is not adjacency_matrix
Example #53
0
def test_boolean_copy_false_boolean():
    mask = np.zeros((10, 10), dtype=np.bool)
    boolean_image = BooleanImage(mask, copy=False)
    assert (is_same_array(boolean_image.pixels, mask))
Example #54
0
def test_boolean_copy_true():
    mask = np.zeros((10, 10), dtype=np.bool)
    boolean_image = BooleanImage(mask)
    assert (not is_same_array(boolean_image.pixels, mask))