当前位置: 首页>>代码示例>>Python>>正文


Python image.Image类代码示例

本文整理汇总了Python中menpo.image.Image的典型用法代码示例。如果您正苦于以下问题:Python Image类的具体用法?Python Image怎么用?Python Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rotate_image_90_180

def test_rotate_image_90_180():
    image = Image(np.array([[1., 2., 3., 4.],
                            [5., 6., 7., 8.],
                            [9., 10., 11., 12.]]))
    image.landmarks['temp'] = PointCloud(np.array([[1., 1.], [1., 2.],
                                                   [2., 1.], [2., 2.]]))
    # rotate 90 degrees
    rotated_img = image.rotate_ccw_about_centre(theta=90, order=0)
    rotated_img.landmarks['temp'] = rotated_img.landmarks['temp'].constrain_to_bounds(
        rotated_img.bounds())
    assert_allclose(rotated_img.pixels, np.array([[[4., 8., 12.],
                                                   [3., 7., 11.],
                                                   [2., 6., 10.],
                                                   [1., 5., 9.]]]))
    assert_almost_equal(rotated_img.landmarks['temp'].points,
                        np.array([[2., 1.], [1., 1.], [2., 2.], [1., 2.]]))

    # rotate 180 degrees
    rotated_img = image.rotate_ccw_about_centre(theta=180, order=0)
    rotated_img.landmarks['temp'] = rotated_img.landmarks['temp'].constrain_to_bounds(
        rotated_img.bounds())
    assert_allclose(rotated_img.pixels, np.array([[[12., 11., 10., 9.],
                                                   [8., 7., 6., 5.],
                                                   [4., 3., 2., 1.]]]))
    assert_almost_equal(rotated_img.landmarks['temp'].points,
                        np.array([[1., 2.], [1., 1.], [0., 2.], [0., 1.]]))
开发者ID:grigorisg9gr,项目名称:menpo,代码行数:26,代码来源:image_warp_test.py

示例2: test_image_clip_pixels_cutom_max_uint

def test_image_clip_pixels_cutom_max_uint():
    pixels = (np.random.rand(3, 10, 20) * 255).astype(np.uint8)
    # add the noise of increased values
    pixels[0, 0, 0] = 255
    image = Image(pixels, copy=False)
    image2 = image.clip_pixels(maximum=200)
    assert(image2.pixels.max() <= 200)
开发者ID:AshwinRajendraprasad,项目名称:menpo,代码行数:7,代码来源:test_image.py

示例3: test_image_gradient_sanity

def test_image_gradient_sanity():
    # Only a sanity check - does it run and generate sensible output?
    image = Image(np.zeros([120, 120, 3]))
    new_image = image.gradient()
    assert(type(new_image) == Image)
    assert(new_image.shape == image.shape)
    assert(new_image.n_channels == image.n_channels * 2)
开发者ID:Amos-zq,项目名称:menpo,代码行数:7,代码来源:image_test.py

示例4: test_texturedtrimesh_copy

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))
开发者ID:Amos-zq,项目名称:menpo,代码行数:26,代码来源:trimesh_copy_test.py

示例5: test_image_from_vector_inplace_no_copy_warning

def test_image_from_vector_inplace_no_copy_warning():
        pixels = np.random.rand(10, 20, 2)
        pixels2 = np.random.rand(10, 20, 2)
        image = Image(pixels)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            image.from_vector_inplace(pixels2.ravel()[::-1], copy=False)
            assert len(w) == 1
开发者ID:Amos-zq,项目名称:menpo,代码行数:8,代码来源:image_test.py

示例6: test_as_greyscale_average

def test_as_greyscale_average():
    ones = np.ones([3, 120, 120])
    image = Image(ones, copy=True)
    image.pixels[0].fill(0.5)
    new_image = image.as_greyscale(mode='average')
    assert (new_image.shape == image.shape)
    assert (new_image.n_channels == 1)
    assert_allclose(new_image.pixels[0], ones[0] * 0.83333333)
开发者ID:HaoyangWang,项目名称:menpo,代码行数:8,代码来源:image_test.py

示例7: test_normalize_std_image

def test_normalize_std_image():
    pixels = np.ones((3, 120, 120))
    pixels[0] = 0.5
    pixels[1] = 0.2345
    image = Image(pixels)
    image.normalize_std_inplace()
    assert_allclose(np.mean(image.pixels), 0, atol=1e-10)
    assert_allclose(np.std(image.pixels), 1)
开发者ID:OlivierML,项目名称:menpo,代码行数:8,代码来源:image_test.py

示例8: test_normalize_norm_image

def test_normalize_norm_image():
    pixels = np.ones((3, 120, 120))
    pixels[0] = 0.5
    pixels[1] = 0.2345
    image = Image(pixels)
    new_image = image.normalize_norm()
    assert_allclose(np.mean(new_image.pixels), 0, atol=1e-10)
    assert_allclose(np.linalg.norm(new_image.pixels), 1)
开发者ID:HaoyangWang,项目名称:menpo,代码行数:8,代码来源:image_test.py

示例9: test_normalize_norm_image

def test_normalize_norm_image():
    pixels = np.ones((120, 120, 3))
    pixels[..., 0] = 0.5
    pixels[..., 1] = 0.2345
    image = Image(pixels)
    image.normalize_norm_inplace()
    assert_allclose(np.mean(image.pixels), 0, atol=1e-10)
    assert_allclose(np.linalg.norm(image.pixels), 1)
开发者ID:Amos-zq,项目名称:menpo,代码行数:8,代码来源:image_test.py

示例10: test_copy_landmarks_and_path_with_no_lms_path

def test_copy_landmarks_and_path_with_no_lms_path():
    img = Image.init_blank((5, 5))
    new_img = Image.init_blank((5, 5))
    copy_landmarks_and_path(img, new_img)
    assert not hasattr(img, "path")
    assert not hasattr(new_img, "path")
    assert not img.has_landmarks
    assert not new_img.has_landmarks
开发者ID:nontas,项目名称:menpo,代码行数:8,代码来源:copy_landmarks_and_path_test.py

示例11: test_as_greyscale_luminosity

def test_as_greyscale_luminosity():
    ones = np.ones([3, 120, 120])
    image = Image(ones, copy=True)
    image.pixels[0].fill(0.5)
    new_image = image.as_greyscale(mode="luminosity")
    assert new_image.shape == image.shape
    assert new_image.n_channels == 1
    assert_allclose(new_image.pixels[0], ones[0] * 0.850532)
开发者ID:nontas,项目名称:menpo,代码行数:8,代码来源:image_test.py

示例12: test_image_copy

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))
开发者ID:AshwinRajendraprasad,项目名称:menpo,代码行数:10,代码来源:test_image_copy.py

示例13: test_normalize_norm_image

def test_normalize_norm_image():
    pixels = np.ones((3, 120, 120))
    pixels[0] = 0.5
    pixels[1] = 0.2345
    image = Image(pixels)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        new_image = image.normalize_norm()
    assert_allclose(np.mean(new_image.pixels), 0, atol=1e-10)
    assert_allclose(np.linalg.norm(new_image.pixels), 1)
开发者ID:dvdm,项目名称:menpo,代码行数:10,代码来源:image_test.py

示例14: test_normalize_std_image_per_channel

def test_normalize_std_image_per_channel():
    pixels = np.random.randn(3, 120, 120)
    pixels[1] *= 9
    pixels[0] += -3
    pixels[2] /= 140
    image = Image(pixels)
    image.normalize_std_inplace(mode='per_channel')
    assert_allclose(
        np.mean(image.as_vector(keep_channels=True), axis=1), 0, atol=1e-10)
    assert_allclose(
        np.std(image.as_vector(keep_channels=True), axis=1), 1)
开发者ID:OlivierML,项目名称:menpo,代码行数:11,代码来源:image_test.py

示例15: test_normalize_norm_image_per_channel

def test_normalize_norm_image_per_channel():
    pixels = np.random.randn(120, 120, 3)
    pixels[..., 1] *= 17
    pixels[..., 0] += -114
    pixels[..., 2] /= 30
    image = Image(pixels)
    image.normalize_norm_inplace(mode='per_channel')
    assert_allclose(
        np.mean(image.as_vector(keep_channels=True), axis=0), 0, atol=1e-10)
    assert_allclose(
        np.linalg.norm(image.as_vector(keep_channels=True), axis=0), 1)
开发者ID:Amos-zq,项目名称:menpo,代码行数:11,代码来源:image_test.py


注:本文中的menpo.image.Image类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。