本文整理汇总了Python中menpo.image.MaskedImage.init_blank方法的典型用法代码示例。如果您正苦于以下问题:Python MaskedImage.init_blank方法的具体用法?Python MaskedImage.init_blank怎么用?Python MaskedImage.init_blank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menpo.image.MaskedImage
的用法示例。
在下文中一共展示了MaskedImage.init_blank方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dilate
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_dilate():
img = MaskedImage.init_blank((10, 10))
img = img.erode(n_pixels=3)
img2 = img.dilate()
assert(img2.mask.n_true() == 32)
img3 = img.dilate(n_pixels=3)
assert(img3.mask.n_true() == 76)
示例2: test_warp_to_mask_masked_image_all_true
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_warp_to_mask_masked_image_all_true():
img = MaskedImage.init_blank((10, 10), fill=2.5)
template_mask = BooleanImage.init_blank((10, 10), fill=False)
template_mask.pixels[:, :5, :5] = True
t = Affine.init_identity(2)
warped_img = img.warp_to_mask(template_mask, t)
assert(type(warped_img) == MaskedImage)
示例3: test_constrain_mask_to_patches_around_landmarks_even
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_patches_around_landmarks_even():
img = MaskedImage.init_blank((10, 10))
img.landmarks['box'] = PointCloud(np.array([[0., 0.], [5., 0.],
[5., 5.], [0., 5.]]))
new_img = img.constrain_mask_to_patches_around_landmarks((2,2), group='box')
assert(new_img.mask.n_true() == 9)
assert_allclose(new_img.mask.pixels[:, 0, 0], True)
assert_allclose(new_img.mask.pixels[:, 4:6, 0], True)
assert_allclose(new_img.mask.pixels[:, 0, 4:6], True)
assert_allclose(new_img.mask.pixels[:, 4:6, 4:6], True)
示例4: test_constrain_mask_to_patches_around_landmarks_odd
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_patches_around_landmarks_odd():
img = MaskedImage.init_blank((10, 10))
img.landmarks['box'] = PointCloud(np.array([[0., 0.], [5., 0.],
[5., 5.], [0., 5.]]))
new_img = img.constrain_mask_to_patches_around_landmarks((3,3), group='box')
assert(new_img.mask.n_true() == 25)
assert_allclose(new_img.mask.pixels[:, :2, :2], True)
assert_allclose(new_img.mask.pixels[:, 4:7, :2], True)
assert_allclose(new_img.mask.pixels[:, :2, 4:7], True)
assert_allclose(new_img.mask.pixels[:, 4:7, 4:7], True)
示例5: _build_reference_frame
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def _build_reference_frame(landmarks, boundary=3, group='source'):
# translate landmarks to the origin
minimum = landmarks.bounds(boundary=boundary)[0]
landmarks = Translation(-minimum).apply(landmarks)
resolution = landmarks.range(boundary=boundary)
reference_frame = MaskedImage.init_blank(resolution)
reference_frame.landmarks[group] = landmarks
return reference_frame
示例6: test_constrain_mask_to_landmarks_pwa
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_landmarks_pwa():
img = MaskedImage.init_blank((10, 10))
img.landmarks['box'] = PointCloud(np.array([[0.0, 0.0], [5.0, 0.0],
[5.0, 5.0], [0.0, 5.0]]))
img.constrain_mask_to_landmarks(group='box')
example_mask = BooleanImage.init_blank((10, 10), fill=False)
example_mask.pixels[0, :6, :6] = True
assert(img.mask.n_true() == 36)
assert_allclose(img.mask.pixels, example_mask.pixels)
示例7: test_constrain_mask_to_landmarks_convex_hull
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_landmarks_convex_hull():
img = MaskedImage.init_blank((10, 10))
img.landmarks['box'] = PointCloud(np.array([[0., 0.], [5., 0.],
[5., 5.], [0., 5.]]))
img.constrain_mask_to_landmarks(group='box',
point_in_pointcloud='convex_hull')
example_mask = BooleanImage.init_blank((10, 10), fill=False)
example_mask.pixels[0, :6, 1:6] = True
assert(img.mask.n_true() == 30)
assert_allclose(img.mask.pixels, example_mask.pixels)
示例8: test_set_boundary_pixels
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_set_boundary_pixels():
mask = np.ones((10, 10), dtype=np.bool)
img = MaskedImage.init_blank((10, 10), mask=mask, fill=0., n_channels=1)
new_img = img.set_boundary_pixels(value=2.)
assert(new_img.mask.n_true() == 100)
assert(~np.allclose(img.pixels, new_img.pixels))
assert_allclose(new_img.pixels[0, 1:-1, 1:-1], 0.)
assert_allclose(new_img.pixels[0, :, 0], 2.)
assert_allclose(new_img.pixels[0, 0, :], 2.)
assert_allclose(new_img.pixels[0, :, -1], 2.)
assert_allclose(new_img.pixels[0, -1, :], 2.)
示例9: test_rescale_pixels_only_masked
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_rescale_pixels_only_masked():
img = MaskedImage.init_blank((10, 10), n_channels=1, fill=1)
img.pixels[0, 0, 0] = 0
img.pixels[0, 6:, 6:] = 2
img.mask.pixels[:, 6:, 6:] = False
img_rescaled = img.rescale_pixels(0, 100)
assert np.min(img_rescaled.pixels) == 0
assert np.max(img_rescaled.pixels) == 100
assert img_rescaled.pixels[0, 0, 0] == 0
assert img_rescaled.pixels[0, 1, 1] == 100
assert np.all(img_rescaled.mask.pixels == img.mask.pixels)
示例10: test_constrain_mask_to_landmarks_callable
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_landmarks_callable():
def bounding_box(_, indices):
return np.ones(indices.shape[0], dtype=np.bool)
img = MaskedImage.init_blank((10, 10))
img.landmarks['box'] = PointCloud(np.array([[0., 0.], [5., 0.],
[5., 5.], [0., 5.]]))
img.constrain_mask_to_landmarks(group='box',
point_in_pointcloud=bounding_box)
example_mask = BooleanImage.init_blank((10, 10), fill=False)
example_mask.pixels[0, :6, :6] = True
assert(img.mask.n_true() == 36)
assert_allclose(img.mask.pixels, example_mask.pixels)
示例11: test_sample_maskedimage_error_values
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_sample_maskedimage_error_values():
m = np.zeros([100, 100], dtype=np.bool)
m[1, 0] = True
im = MaskedImage.init_blank((100, 100), mask=m, fill=2)
p = PointCloud(np.array([[0, 0], [1, 0]]))
try:
im.sample(p)
# Expect exception!
assert 0
except OutOfMaskSampleError as e:
sampled_mask = e.sampled_mask
sampled_values = e.sampled_values
assert_allclose(sampled_values, [[2., 2.]])
assert_allclose(sampled_mask, [[False, True]])
示例12: test_warp_to_mask_masked_image
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_warp_to_mask_masked_image():
mask = BooleanImage.init_blank((15, 15))
# make a truncated mask on the original image
mask.pixels[0, -1, -1] = False
img = MaskedImage.init_blank((15, 15), n_channels=2, mask=mask,
fill=2.5)
template_mask = BooleanImage.init_blank((10, 10), fill=False)
template_mask.pixels[:, :5, :5] = True
t = Affine.init_identity(2)
warped_img = img.warp_to_mask(template_mask, t)
assert(type(warped_img) == MaskedImage)
result = Image.init_blank((10, 10), n_channels=2).pixels
result[:, :5, :5] = 2.5
result_mask = BooleanImage.init_blank((10, 10), fill=False).pixels
result_mask[:, :5, :5] = True
assert(warped_img.n_true_pixels() == 25)
assert_allclose(result, warped_img.pixels)
assert_allclose(result_mask, warped_img.mask.pixels)
示例13: steepest_descent_images
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def steepest_descent_images(self, image, dW_dp, forward=None):
# compute gradient
# gradient: height x width x n_channels
gradient_img = self._calculate_gradients(image, forward=forward)
# reshape gradient
# gradient: n_pixels x (n_channels x n_dims)
gradient = gradient_img.as_vector(keep_channels=True)
# reshape gradient
# gradient: n_pixels x n_channels x n_dims
gradient = np.reshape(gradient, (-1, image.n_channels, image.n_dims))
# compute steepest descent images
# gradient: n_pixels x n_channels x x n_dims
# dW_dp: n_pixels x x n_params x n_dims
# sdi: n_pixels x n_channels x n_params
sdi = np.sum(dW_dp[:, None, :, :] * gradient[:, :, None, :], axis=3)
# make sdi images
# sdi_img: shape x n_channels x n_params
sdi_img_channels = image.n_channels * dW_dp.shape[1]
sdi_img = MaskedImage.init_blank(gradient_img.shape,
n_channels=sdi_img_channels,
mask=gradient_img.mask)
sdi_img.from_vector_inplace(sdi.flatten())
# compute FFT over each channel, parameter and dimension
# fft_sdi: height x width x n_channels x n_params
fft_axes = range(image.n_dims)
fft_sdi = fftshift(fftn(sdi_img.pixels, axes=fft_axes), axes=fft_axes)
# ToDo: Note that, fft_sdi is rectangular, i.e. is not define in
# terms of the mask pixels, but in terms of the whole image.
# Selecting mask pixels once the fft has been computed makes no
# sense because they have lost their original spatial meaning.
# reshape steepest descent images
# sdi: (height x width x n_channels) x n_params
return np.reshape(fft_sdi, (-1, dW_dp.shape[1]))
示例14: test_constrain_mask_to_landmarks_unknown_key
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_landmarks_unknown_key():
img = MaskedImage.init_blank((10, 10))
img.landmarks['box'] = PointCloud(np.array([[0., 0., 0.]]))
img.constrain_mask_to_landmarks(point_in_pointcloud='unknown')
示例15: test_constrain_mask_to_landmarks_non_2d
# 需要导入模块: from menpo.image import MaskedImage [as 别名]
# 或者: from menpo.image.MaskedImage import init_blank [as 别名]
def test_constrain_mask_to_landmarks_non_2d():
img = MaskedImage.init_blank((10, 10, 10))
img.landmarks['box'] = PointCloud(np.array([[0., 0., 0.]]))
img.constrain_mask_to_landmarks()