本文整理汇总了Python中menpo.image.Image.init_from_rolled_channels方法的典型用法代码示例。如果您正苦于以下问题:Python Image.init_from_rolled_channels方法的具体用法?Python Image.init_from_rolled_channels怎么用?Python Image.init_from_rolled_channels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menpo.image.Image
的用法示例。
在下文中一共展示了Image.init_from_rolled_channels方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _rasterize_matplotlib
# 需要导入模块: from menpo.image import Image [as 别名]
# 或者: from menpo.image.Image import init_from_rolled_channels [as 别名]
def _rasterize_matplotlib(image, pclouds, render_lines=True, line_style='-',
line_colour='b', line_width=1, render_markers=True,
marker_style='o', marker_size=1,
marker_face_colour='b', marker_edge_colour='b',
marker_edge_width=1):
import matplotlib.pyplot as plt
# Convert image shape into 100 DPI inches
# This makes sure we maintain the original image size
image_shape = np.array(image.shape)[::-1] / 100.0
f = plt.figure(figsize=image_shape, frameon=False, dpi=100)
image.view(figure_id=f.number, figure_size=image_shape)
for k, p in enumerate(pclouds):
p.view(figure_id=f.number, render_axes=False, figure_size=image_shape,
render_lines=render_lines[k], line_style=line_style[k],
line_colour=line_colour[k], line_width=line_width[k],
render_markers=render_markers[k], marker_style=marker_style[k],
marker_size=marker_size[k],
marker_face_colour=marker_face_colour[k],
marker_edge_colour=marker_edge_colour[k],
marker_edge_width=marker_edge_width[k])
# Make sure the layout is tight so that the image is of the original size
f.tight_layout(pad=0)
# Get the pixels directly from the canvas buffer which is fast
c_buffer, shape = f.canvas.print_to_buffer()
# Turn buffer into numpy array and reshape to image
pixels_buffer = np.array(c_buffer).reshape(shape[::-1] + (-1,))
# Prevent matplotlib from rendering
plt.close(f)
# Ignore the Alpha channel
return Image.init_from_rolled_channels(pixels_buffer[..., :3])
示例2: _rasterize_pillow
# 需要导入模块: from menpo.image import Image [as 别名]
# 或者: from menpo.image.Image import init_from_rolled_channels [as 别名]
def _rasterize_pillow(image, pclouds, render_lines=True, line_style='-',
line_colour='b', line_width=1, render_markers=True,
marker_style='o', marker_size=1, marker_face_colour='b',
marker_edge_colour='b', marker_edge_width=1):
from PIL import ImageDraw
if any(x != '-'for x in line_style):
raise ValueError("The Pillow rasterizer only supports the '-' "
"line style.")
if any(x not in {'o', 's'} for x in marker_style):
raise ValueError("The Pillow rasterizer only supports the 'o' and 's' "
"marker styles.")
if any(x > 1 for x in marker_edge_width):
raise ValueError('The Pillow rasterizer only supports '
'marker_edge_width of 1 or 0.')
pil_im = image.as_PILImage()
draw = ImageDraw.Draw(pil_im)
line_colour = [_parse_colour(x) for x in line_colour]
marker_edge_colour = [_parse_colour(x) for x in marker_edge_colour]
marker_face_colour = [_parse_colour(x) for x in marker_face_colour]
for k in range(len(pclouds)):
p = pclouds[k]
if isinstance(p, TriMesh):
pclouds[k] = p.as_pointgraph()
points = p.points
if (render_lines[k] and line_width[k] > 0 and
hasattr(p, 'edges') and p.edges.size > 0):
edges = p.edges
lines = zip(points[edges[:, 0], :],
points[edges[:, 1], :])
for l1, l2 in lines:
draw.line([tuple(l1[::-1]), tuple(l2[::-1])],
fill=line_colour[k], width=line_width[k])
if render_markers[k] and marker_size[k] > 0:
draw_func = (draw.ellipse if marker_style[k] == 'o'
else draw.rectangle)
outline = (marker_edge_colour[k] if marker_edge_width[k] == 1
else None)
for p in points:
y, x = p
draw_func((x - marker_size[k], y - marker_size[k],
x + marker_size[k], y + marker_size[k]),
fill=marker_face_colour[k], outline=outline)
del draw
pixels = np.asarray(pil_im)
if image.n_channels == 3:
return Image.init_from_rolled_channels(pixels)
else:
return Image(pixels)
示例3: test_init_from_rolled_channels
# 需要导入模块: from menpo.image import Image [as 别名]
# 或者: from menpo.image.Image import init_from_rolled_channels [as 别名]
def test_init_from_rolled_channels():
p = np.empty([50, 60, 3])
im = Image.init_from_rolled_channels(p)
assert im.n_channels == 3
assert im.height == 50
assert im.width == 60