def test_uniformscale3d_from_vector(): scale = 2 h**o = np.array([[scale, 0, 0, 0], [0, scale, 0, 0], [0, 0, scale, 0], [0, 0, 0, 1]]) uniform_scale = UniformScale(1, 3) tr = uniform_scale.from_vector(scale) assert_equal(tr.h_matrix, h**o)
def test_uniformscale2d_update_from_vector(): # make a uniform scale of 1, 2 dimensional uniform_scale = UniformScale(1, 2) new_scale = 2 h**o = np.array([[new_scale, 0, 0], [0, new_scale, 0], [0, 0, 1]]) uniform_scale.from_vector_inplace(new_scale) assert_equal(uniform_scale.h_matrix, h**o)
def rescale_to_reference_shape(self, reference_shape, group=None, label='all', interpolator='scipy', round='ceil', **kwargs): r""" Return a copy of this image, rescaled so that the scale of a particular group of landmarks matches the scale of the passed reference landmarks. Parameters ---------- reference_shape: :class:`menpo.shape.pointcloud` The reference shape to which the landmarks scale will be matched against. group : string, Optional The key of the landmark set that should be used. If None, and if there is only one set of landmarks, this set will be used. Default: None label: string, Optional The label of of the landmark manager that you wish to use. If 'all' all landmarks in the group are used. Default: 'all' interpolator : 'scipy' or 'c', optional The interpolator that should be used to perform the warp. 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. Returns ------- rescaled_image : type(self) A copy of this image, rescaled. """ pc = self.landmarks[group][label].lms scale = UniformScale.align(pc, reference_shape).as_vector() return self.rescale(scale, interpolator=interpolator, round=round, **kwargs)
def __init__(self, shape_models, appearance_models, transform_cls, feature_type, reference_shape, downscale, patch_size, interpolator): self.shape_models = shape_models self.appearance_models = appearance_models self.transform_cls = transform_cls self.feature_type = feature_type self.reference_shape = reference_shape self.downscale = downscale self.patch_size = patch_size self.interpolator = interpolator if len(appearance_models) > 1: difference = UniformScale.align( appearance_models[0].mean.landmarks['source'].lms, appearance_models[1].mean.landmarks['source'].lms).as_vector() if difference == 1: self.scaled_reference_frames = False else: self.scaled_reference_frames = True else: self.downscale = None self.scaled_reference_frames = None
def test_uniformscale_identity_3d(): assert_allclose(UniformScale.identity(3).h_matrix, np.eye(4))