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


Python transform.NonUniformScale类代码示例

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


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

示例1: test_nonuniformscale2d_update_from_vector

def test_nonuniformscale2d_update_from_vector():
    scale = np.array([3, 4])
    homo = np.array([[scale[0], 0, 0],
                     [0, scale[1], 0],
                     [0, 0, 1]])
    tr = NonUniformScale(np.array([1, 2]))
    tr._from_vector_inplace(scale)
    assert_equal(tr.h_matrix, homo)
开发者ID:AshwinRajendraprasad,项目名称:menpo,代码行数:8,代码来源:test_homogeneous.py

示例2: test_scale_2d_pseudoinverse

def test_scale_2d_pseudoinverse():
    scale1 = 0.5
    scale2 = 4.0
    homo = np.array([[scale1,      0, 0],
                     [     0, scale2, 0],
                     [     0,      0, 1]])

    tr = NonUniformScale([1/scale1, 1/scale2])
    assert_almost_equal(tr.pseudoinverse().h_matrix, homo)
开发者ID:HaoyangWang,项目名称:menpo,代码行数:9,代码来源:h_scale_test.py

示例3: test_nonuniformscale2d_from_vector

def test_nonuniformscale2d_from_vector():
    scale = np.array([1, 2])
    homo = np.array([[scale[0], 0, 0],
                     [0, scale[1], 0],
                     [0, 0, 1]])

    tr = NonUniformScale.init_identity(2).from_vector(scale)

    assert_equal(tr.h_matrix, homo)
开发者ID:AshwinRajendraprasad,项目名称:menpo,代码行数:9,代码来源:test_homogeneous.py

示例4: glyph

    def glyph(self, vectors_block_size=10, use_negative=False, channels=None):
        r"""
        Create glyph of a feature image. If feature_data has negative values,
        the use_negative flag controls whether there will be created a glyph of
        both positive and negative values concatenated the one on top of the
        other.

        Parameters
        ----------
        vectors_block_size: int
            Defines the size of each block with vectors of the glyph image.
        use_negative: bool
            Defines whether to take into account possible negative values of
            feature_data.
        """
        # first, choose the appropriate channels
        if channels is None:
            pixels = self.pixels[..., :4]
        elif channels != 'all':
            pixels = self.pixels[..., channels]
        else:
            pixels = self.pixels
        # compute the glyph
        negative_weights = -pixels
        scale = np.maximum(pixels.max(), negative_weights.max())
        pos = _create_feature_glyph(pixels, vectors_block_size)
        pos = pos * 255 / scale
        glyph_image = pos
        if use_negative and pixels.min() < 0:
            neg = _create_feature_glyph(negative_weights, vectors_block_size)
            neg = neg * 255 / scale
            glyph_image = np.concatenate((pos, neg))
        glyph = Image(glyph_image)
        # correct landmarks
        from menpo.transform import NonUniformScale

        image_shape = np.array(self.shape, dtype=np.double)
        glyph_shape = np.array(glyph.shape, dtype=np.double)
        nus = NonUniformScale(glyph_shape / image_shape)
        glyph.landmarks = self.landmarks
        nus.apply_inplace(glyph.landmarks)
        return glyph
开发者ID:yymath,项目名称:menpo,代码行数:42,代码来源:base.py

示例5: test_nonuniformscale_set_h_matrix_raises_notimplementederror

def test_nonuniformscale_set_h_matrix_raises_notimplementederror():
    s = NonUniformScale([2, 3, 4])
    s.set_h_matrix(s.h_matrix)
开发者ID:dubzzz,项目名称:menpo,代码行数:3,代码来源:homogeneous_test.py

示例6: rescale

    def rescale(self, scale, interpolator='scipy', round='ceil', **kwargs):
        r"""
        Return a copy of this image, rescaled by a given factor.
        Landmarks are rescaled appropriately.

        Parameters
        ----------
        scale : float or tuple
            The scale factor. If a tuple, the scale to apply to each dimension.
            If a single float, the scale will be applied uniformly across
            each dimension.
        interpolator : 'scipy', optional
            The interpolator that should be used to perform the warp.

            Default: 'scipy'
        round: {'ceil', 'floor', 'round'}
            Rounding function to be applied to floating point shapes.

            Default: 'ceil'
        kwargs : dict
            Passed through to the interpolator. See `menpo.interpolation`
            for details. Note that mode is set to nearest to avoid numerical
            issues, and cannot be changed here by the user.

        Returns
        -------
        rescaled_image : type(self)
            A copy of this image, rescaled.

        Raises
        ------
        ValueError:
            If less scales than dimensions are provided.
            If any scale is less than or equal to 0.
        """
        # Pythonic way of converting to list if we are passed a single float
        try:
            if len(scale) < self.n_dims:
                raise ValueError(
                    'Must provide a scale per dimension.'
                    '{} scales were provided, {} were expected.'.format(
                        len(scale), self.n_dims
                    )
                )
        except TypeError:  # Thrown when len() is called on a float
            scale = [scale] * self.n_dims

        # Make sure we have a numpy array
        scale = np.asarray(scale)
        for s in scale:
            if s <= 0:
                raise ValueError('Scales must be positive floats.')

        transform = NonUniformScale(scale)
        from menpo.image.boolean import BooleanImage
        # use the scale factor to make the template mask bigger
        template_mask = BooleanImage.blank(transform.apply(self.shape),
                                           round=round)
        # due to image indexing, we can't just apply the pseduoinverse
        # transform to achieve the scaling we want though!
        # Consider a 3x rescale on a 2x4 image. Looking at each dimension:
        #    H 2 -> 6 so [0-1] -> [0-5] = 5/1 = 5x
        #    W 4 -> 12 [0-3] -> [0-11] = 11/3 = 3.67x
        # => need to make the correct scale per dimension!
        shape = np.array(self.shape, dtype=np.float)
        # scale factors = max_index_after / current_max_index
        # (note that max_index = length - 1, as 0 based)
        scale_factors = (scale * shape - 1) / (shape - 1)
        inverse_transform = NonUniformScale(scale_factors).pseudoinverse
        # for rescaling we enforce that mode is nearest to avoid num. errors
        if 'mode' in kwargs:
            raise ValueError("Cannot set 'mode' kwarg on rescale - set to "
                             "'nearest' to avoid numerical errors")
        kwargs['mode'] = 'nearest'
        # Note here we pass warp_mask to warp_to. In the case of
        # Images that aren't MaskedImages this kwarg will
        # harmlessly fall through so we are fine.
        return self.warp_to(template_mask, inverse_transform,
                            warp_landmarks=True,
                            interpolator=interpolator, **kwargs)
开发者ID:yymath,项目名称:menpo,代码行数:80,代码来源:base.py

示例7: test_nonuniformscale_identity_3d

def test_nonuniformscale_identity_3d():
    assert_allclose(NonUniformScale.init_identity(3).h_matrix, np.eye(4))
开发者ID:HaoyangWang,项目名称:menpo,代码行数:2,代码来源:h_scale_test.py

示例8: test_nonuniformscale_identity_2d

def test_nonuniformscale_identity_2d():
    assert_allclose(NonUniformScale.identity(2).h_matrix, np.eye(3))
开发者ID:Amos-zq,项目名称:menpo,代码行数:2,代码来源:h_scale_test.py


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