本文整理汇总了Python中menpo.transform.Translation.apply_inplace方法的典型用法代码示例。如果您正苦于以下问题:Python Translation.apply_inplace方法的具体用法?Python Translation.apply_inplace怎么用?Python Translation.apply_inplace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menpo.transform.Translation
的用法示例。
在下文中一共展示了Translation.apply_inplace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crop
# 需要导入模块: from menpo.transform import Translation [as 别名]
# 或者: from menpo.transform.Translation import apply_inplace [as 别名]
def crop(self, min_indices, max_indices, constrain_to_boundary=True):
r"""
Crops this image using the given minimum and maximum indices.
Landmarks are correctly adjusted so they maintain their position
relative to the newly cropped image.
Parameters
-----------
min_indices: (n_dims, ) ndarray
The minimum index over each dimension
max_indices: (n_dims, ) ndarray
The maximum index over each dimension
constrain_to_boundary: boolean, optional
If True the crop will be snapped to not go beyond this images
boundary. If False, an ImageBoundaryError will be raised if an
attempt is made to go beyond the edge of the image.
Default: True
Returns
-------
cropped_image : :class:`type(self)`
This image, but cropped.
Raises
------
ValueError
min_indices and max_indices both have to be of length n_dims.
All max_indices must be greater than min_indices.
ImageBoundaryError
Raised if constrain_to_boundary is False, and an attempt is made
to crop the image in a way that violates the image bounds.
"""
min_indices = np.floor(min_indices)
max_indices = np.ceil(max_indices)
if not (min_indices.size == max_indices.size == self.n_dims):
raise ValueError(
"Both min and max indices should be 1D numpy arrays of" " length n_dims ({})".format(self.n_dims)
)
elif not np.all(max_indices > min_indices):
raise ValueError("All max indices must be greater that the min " "indices")
min_bounded = self.constrain_points_to_bounds(min_indices)
max_bounded = self.constrain_points_to_bounds(max_indices)
if not constrain_to_boundary and not (np.all(min_bounded == min_indices) or np.all(max_bounded == max_indices)):
# points have been constrained and the user didn't want this -
raise ImageBoundaryError(min_indices, max_indices, min_bounded, max_bounded)
slices = [slice(int(min_i), int(max_i)) for min_i, max_i in zip(list(min_bounded), list(max_bounded))]
self.pixels = self.pixels[slices].copy()
# update all our landmarks
lm_translation = Translation(-min_bounded)
lm_translation.apply_inplace(self.landmarks)
return self