def prep_source_img(src: Image, crop: bool = True, do_plot: bool = True) -> Image: src = src.as_masked() if crop: src = src.crop_to_landmarks() src = src.constrain_mask_to_landmarks() if do_plot: src.view(new_figure=True) return src
def wrapper(index, shape): index = index.decode("utf-8") prefix = index.split('_')[0] landmark_indices = list(map(int, index.split('_')[1:])) if len(landmark_indices) > 1: min_index, max_index = landmark_indices landmark_indices = range(min_index, max_index + 1) kpts = np.zeros(shape[:2], dtype=int) im = Image(kpts) mask = np.ones(list(shape[:2]) + [1]).astype(np.float32) for lms_index in landmark_indices: filename = ( prefix + '_' + str(lms_index) + '.' + self.lms_extension) path = self.lms_root / filename if not path.exists(): continue lms = mio.import_landmark_file(path.as_posix()).lms if lms.points.shape[0] != 68: min_indices, max_indices = lms.bounds() mask[min_indices[0]:max_indices[0], min_indices[1]: max_indices[1]] = 0 continue for i in range(68): lms_mask = im.as_masked().copy() patches = np.ones((1, 1, 1, 4, 4), dtype=np.bool) pc = lms.points[i][None, :] lms_mask.mask.pixels[...] = False lms_mask = lms_mask.mask.set_patches( patches, menpo.shape.PointCloud(pc)) kpts[lms_mask.mask] = i + 1 return kpts.astype(np.int32), mask.astype(np.int32)
def test_image_as_masked(): img = Image(np.random.rand(3, 3, 1), copy=False) m_img = img.as_masked() assert type(m_img) == MaskedImage assert_allclose(m_img.pixels, img.pixels)
def test_image_as_masked(): img = Image(np.random.rand(3, 3, 1), copy=False) m_img = img.as_masked() assert(type(m_img) == MaskedImage) assert_allclose(m_img.pixels, img.pixels)
def test_image_as_masked(): img = Image(np.random.rand(3, 3, 1), copy=False) m_img = img.as_masked() assert(type(m_img) == MaskedImage) assert(np.all(m_img.pixels == img.pixels))