• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python image.MaskedImage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_normalize_norm_zero_norm_exception

def test_normalize_norm_zero_norm_exception():
    pixels = np.zeros((3, 120, 120))
    image = MaskedImage(pixels)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        with raises(ValueError):
            image.normalize_norm(mode='per_channel')
开发者ID:AshwinRajendraprasad,项目名称:menpo,代码行数:7,代码来源:test_image.py


示例2: test_masked_image_as_unmasked_fill_tuple

def test_masked_image_as_unmasked_fill_tuple():
    m_img = MaskedImage(np.random.rand(3, 3, 3), copy=False)
    m_img.mask.pixels[0, 0, 0] = False
    img = m_img.as_unmasked(fill=(1, 2, 3))
    assert(type(img) == Image)
    assert_allclose(m_img.pixels[0, 1:, 1:], img.pixels[0, 1:, 1:])
    assert_allclose(img.pixels[:, 0, 0], (1, 2, 3))
开发者ID:JeanKossaifi,项目名称:menpo,代码行数:7,代码来源:image_basics_test.py


示例3: test_masked_image_as_unmasked_fill

def test_masked_image_as_unmasked_fill():
    m_img = MaskedImage(np.random.rand(1, 3, 3), copy=False)
    m_img.mask.pixels[0, 0, 0] = False
    img = m_img.as_unmasked(fill=8)
    assert type(img) == Image
    assert_allclose(m_img.pixels[0, 1:, 1:], img.pixels[0, 1:, 1:])
    assert_allclose(img.pixels[0, 0, 0], 8.0)
开发者ID:nontas,项目名称:menpo,代码行数:7,代码来源:image_basics_test.py


示例4: test_normalize_std_no_variance_exception

def test_normalize_std_no_variance_exception():
    pixels = np.ones((3, 120, 120))
    pixels[0] = 0.5
    pixels[1] = 0.2345
    image = MaskedImage(pixels)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        image.normalize_std(mode='per_channel')
开发者ID:dvdm,项目名称:menpo,代码行数:8,代码来源:image_test.py


示例5: test_2d_crop_with_mask

def test_2d_crop_with_mask():
    pixels = np.ones((120, 120, 3))
    mask = np.zeros_like(pixels[..., 0])
    mask[10:100, 20:30] = 1
    im = MaskedImage(pixels, mask=mask)
    cropped_im = im.cropped_copy([0, 0], [20, 60])
    assert (cropped_im.shape == (20, 60))
    assert (np.alltrue(cropped_im.shape))
开发者ID:ikassi,项目名称:menpo,代码行数:8,代码来源:image_test.py


示例6: test_normalize_norm_default

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


示例7: test_as_greyscale_average

def test_as_greyscale_average():
    ones = np.ones([3, 120, 120])
    image = MaskedImage(ones)
    image.pixels[0] *= 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:OlivierML,项目名称:menpo,代码行数:8,代码来源:image_test.py


示例8: test_as_greyscale_luminosity

def test_as_greyscale_luminosity():
    ones = np.ones([3, 120, 120])
    image = MaskedImage(ones)
    image.pixels[0] *= 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:OlivierML,项目名称:menpo,代码行数:8,代码来源:image_test.py


示例9: test_normalize_norm_per_channel

def test_normalize_norm_per_channel():
    pixels = np.random.randn(120, 120, 3)
    pixels[..., 1] *= 7
    pixels[..., 0] += -14
    pixels[..., 2] /= 130
    image = MaskedImage(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:karla3jo,项目名称:menpo,代码行数:9,代码来源:image_test.py


示例10: test_2d_crop_without_mask

def test_2d_crop_without_mask():
    pixels = np.ones((120, 120, 3))
    im = MaskedImage(pixels)

    cropped_im = im.cropped_copy([10, 50], [20, 60])

    assert (cropped_im.shape == (10, 10))
    assert (cropped_im.n_channels == 3)
    assert (np.alltrue(cropped_im.shape))
开发者ID:ikassi,项目名称:menpo,代码行数:9,代码来源:image_test.py


示例11: test_maskedimage_copy

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


示例12: rebuild_feature_image_with_centres

def rebuild_feature_image_with_centres(image, f_pixels, centres):
    if hasattr(image, 'mask'):
        mask = sample_mask_for_centres(image.mask.mask, centres)
        new_image = MaskedImage(f_pixels, mask=mask, copy=False)
    else:
        new_image = Image(f_pixels, copy=False)
    if image.has_landmarks:
        t = lm_centres_correction(centres)
        new_image.landmarks = t.apply(image.landmarks)
    return new_image
开发者ID:csagonas,项目名称:menpo,代码行数:10,代码来源:base.py


示例13: test_normalize_norm_masked_per_channel

def test_normalize_norm_masked_per_channel():
    pixels = np.random.randn(3, 120, 120)
    pixels[1] *= 7
    pixels[0] += -14
    pixels[2] /= 130
    image = MaskedImage(pixels)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        new_image = image.normalize_norm(mode="per_channel")
    assert_allclose(np.mean(new_image.as_vector(keep_channels=True), axis=1), 0, atol=1e-10)
    assert_allclose(np.linalg.norm(new_image.as_vector(keep_channels=True), axis=1), 1)
开发者ID:nontas,项目名称:menpo,代码行数:11,代码来源:image_test.py


示例14: test_normalize_norm_masked

def test_normalize_norm_masked():
    pixels = np.random.randn(120, 120, 3)
    pixels[..., 1] *= 7
    pixels[..., 0] += -14
    pixels[..., 2] /= 130
    mask = np.zeros((120, 120))
    mask[30:50, 20:30] = 1
    image = MaskedImage(pixels, mask=mask)
    image.normalize_norm_inplace(mode="per_channel", limit_to_mask=True)
    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:karla3jo,项目名称:menpo,代码行数:11,代码来源:image_test.py


示例15: test_normalize_std_masked_per_channel

def test_normalize_std_masked_per_channel():
    pixels = np.random.randn(3, 120, 120)
    pixels[0] *= 7
    pixels[1] += -14
    pixels[2] /= 130
    image = MaskedImage(pixels)
    new_image = image.normalize_std(mode='per_channel')
    assert_allclose(
        np.mean(new_image.as_vector(keep_channels=True), axis=1), 0, atol=1e-10)
    assert_allclose(
        np.std(new_image.as_vector(keep_channels=True), axis=1), 1)
开发者ID:HaoyangWang,项目名称:menpo,代码行数:11,代码来源:image_test.py


示例16: test_normalize_norm_masked_per_channel

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


示例17: test_normalize_std_masked

def test_normalize_std_masked():
    pixels = np.random.randn(3, 120, 120)
    pixels[1] *= 7
    pixels[0] += -14
    pixels[2] /= 130
    mask = np.zeros((120, 120))
    mask[30:50, 20:30] = 1
    image = MaskedImage(pixels, mask=mask)
    image.normalize_std_inplace(mode='per_channel', limit_to_mask=True)
    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,代码行数:13,代码来源:image_test.py


示例18: test_normalize_norm_masked

def test_normalize_norm_masked():
    pixels = np.random.randn(3, 120, 120)
    pixels[1] *= 7
    pixels[0] += -14
    pixels[2] /= 130
    mask = np.zeros((120, 120))
    mask[30:50, 20:30] = 1
    image = MaskedImage(pixels, mask=mask)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        new_image = image.normalize_norm(mode="per_channel", limit_to_mask=True)
    assert_allclose(np.mean(new_image.as_vector(keep_channels=True), axis=1), 0, atol=1e-10)
    assert_allclose(np.linalg.norm(new_image.as_vector(keep_channels=True), axis=1), 1)
开发者ID:nontas,项目名称:menpo,代码行数:13,代码来源:image_test.py


示例19: test_dilate

def test_dilate():
    img = MaskedImage.init_blank((10, 10))
    img = img.erode(n_pixels=3)
    img2 = img.dilate()
    assert(img2.mask.n_true() == 32)
    img3 = img.dilate(n_pixels=3)
    assert(img3.mask.n_true() == 76)
开发者ID:mmcauliffe,项目名称:menpo,代码行数:7,代码来源:image_masked_test.py


示例20: build_patch_reference_frame

def build_patch_reference_frame(landmarks, boundary=3, group='source',
                                patch_shape=(17, 17)):
    r"""
    Builds a patch-based reference frame from a particular set of landmarks.

    Parameters
    ----------
    landmarks : `menpo.shape.PointCloud`
        The landmarks that will be used to build the reference frame.
    boundary : `int`, optional
        The number of pixels to be left as a safe margin on the boundaries
        of the reference frame (has potential effects on the gradient
        computation).
    group : `str`, optional
        Group that will be assigned to the provided set of landmarks on the
        reference frame.
    patch_shape : (`int`, `int`), optional
        The shape of the patches.

    Returns
    -------
    patch_based_reference_frame : `menpo.image.MaskedImage`
        The patch-based reference frame.
    """
    boundary = np.max(patch_shape) + boundary
    reference_frame = MaskedImage.init_from_pointcloud(
        landmarks, group=group, boundary=boundary, constrain_mask=False)

    # mask reference frame
    return reference_frame.constrain_mask_to_patches_around_landmarks(
        patch_shape, group=group)
开发者ID:jabooth,项目名称:menpofit,代码行数:31,代码来源:builder.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python io.data_dir_path函数代码示例发布时间:2022-05-27
下一篇:
Python image.Image类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap