def line_to_sparse(training_images, sparse_shape, rs, group='PTS', sd='draw_gaussian'): ni, icp_transforms, reference_frame, n_landmarks, _n_align_points, _removed_transform, normalized_images, _rf_align, rs, [ align_t ] = rescale_images_to_reference_shape(training_images, group, rs, sd='sample_gaussian') path_to_db = '{}'.format(training_images[0].path.parent) # Retrieve Results mat = sio.loadmat('{}/result.mat'.format(path_to_db)) _u, _v = mat['u'], mat['v'] # Build Transforms print(" - Build Transform") transforms = [] for i in range(_u.shape[-1]): transforms.append(OpticalFlowTransform(_u[:, :, i], _v[:, :, i])) for i, n, t, norm, icpt, oft in zip(training_images, ni, _removed_transform, normalized_images, icp_transforms, transforms): scale = AlignmentUniformScale(norm.landmarks[group].lms, i.landmarks[group].lms) pts = oft.apply(align_t.apply(sparse_shape)) i.landmarks['SPARSE'] = scale.apply(t.apply(_rf_align.apply(pts))) return training_images
def holistic_sampling_from_scale(aam, scale=0.35): r""" Function that generates a sampling reference mask given a scale value. Parameters ---------- aam : :map:`AAM` or subclass The trained AAM. scale : `float`, optional The scale value. Returns ------- true_positions : `ndarray` of `bool` The array that has ``True`` for the points of the reference shape that belong to the new mask. boolean_image : `menpo.image.BooleanImage` The boolean image of the mask. """ reference = aam.appearance_models[0].mean() scaled_reference = reference.rescale(scale) t = AlignmentUniformScale(scaled_reference.landmarks['source'].lms, reference.landmarks['source'].lms) new_indices = np.require(np.round(t.apply( scaled_reference.mask.true_indices())), dtype=np.int) modified_mask = deepcopy(reference.mask.pixels) modified_mask[:] = False modified_mask[:, new_indices[:, 0], new_indices[:, 1]] = True true_positions = np.nonzero( modified_mask[:, reference.mask.mask].ravel())[0] return true_positions, BooleanImage(modified_mask[0])
def holistic_sampling_from_scale(aam, scale=0.35): reference = aam.appearance_models[0].mean() scaled_reference = reference.rescale(scale) t = AlignmentUniformScale(scaled_reference.landmarks['source'].lms, reference.landmarks['source'].lms) new_indices = np.require(np.round(t.apply( scaled_reference.mask.true_indices())), dtype=np.int) modified_mask = deepcopy(reference.mask.pixels) modified_mask[:] = False modified_mask[:, new_indices[:, 0], new_indices[:, 1]] = True true_positions = np.nonzero( modified_mask[:, reference.mask.mask].ravel())[0] return true_positions, BooleanImage(modified_mask[0])
def holistic_sampling_from_scale(aam, scale=0.35): reference = aam.appearance_models[0].mean() scaled_reference = reference.rescale(scale) t = AlignmentUniformScale(scaled_reference.landmarks['source'].lms, reference.landmarks['source'].lms) new_indices = np.require(np.round( t.apply(scaled_reference.mask.true_indices())), dtype=np.int) modified_mask = deepcopy(reference.mask.pixels) modified_mask[:] = False modified_mask[:, new_indices[:, 0], new_indices[:, 1]] = True true_positions = np.nonzero(modified_mask[:, reference.mask.mask].ravel())[0] return true_positions, BooleanImage(modified_mask[0])
def holistic_sampling_from_scale(aam, scale=0.35): r""" Function that generates a sampling reference mask given a scale value. Parameters ---------- aam : :map:`AAM` or subclass The trained AAM. scale : `float`, optional The scale value. Returns ------- true_positions : `ndarray` of `bool` The array that has ``True`` for the points of the reference shape that belong to the new mask. boolean_image : `menpo.image.BooleanImage` The boolean image of the mask. """ reference = aam.appearance_models[0].mean() scaled_reference = reference.rescale(scale) t = AlignmentUniformScale(scaled_reference.landmarks['source'], reference.landmarks['source']) new_indices = np.require(np.round( t.apply(scaled_reference.mask.true_indices())), dtype=np.int) modified_mask = deepcopy(reference.mask.pixels) modified_mask[:] = False modified_mask[:, new_indices[:, 0], new_indices[:, 1]] = True true_positions = np.nonzero(modified_mask[:, reference.mask.mask].ravel())[0] return true_positions, BooleanImage(modified_mask[0])