MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / composite_images

Function composite_images

lib/matplotlib/image.py:59–112  ·  view source on GitHub ↗

Composite a number of RGBA images into one. The images are composited in the order in which they appear in the *images* list. Parameters ---------- images : list of Images Each must have a `!make_image` method. For each image, `!can_composite` should return `T

(images, renderer, magnification=1.0)

Source from the content-addressed store, hash-verified

57
58
59def composite_images(images, renderer, magnification=1.0):
60 """
61 Composite a number of RGBA images into one. The images are
62 composited in the order in which they appear in the *images* list.
63
64 Parameters
65 ----------
66 images : list of Images
67 Each must have a `!make_image` method. For each image,
68 `!can_composite` should return `True`, though this is not
69 enforced by this function. Each image must have a purely
70 affine transformation with no shear.
71
72 renderer : `.RendererBase`
73
74 magnification : float, default: 1
75 The additional magnification to apply for the renderer in use.
76
77 Returns
78 -------
79 image : (M, N, 4) `numpy.uint8` array
80 The composited RGBA image.
81 offset_x, offset_y : float
82 The (left, bottom) offset where the composited image should be placed
83 in the output figure.
84 """
85 if len(images) == 0:
86 return np.empty((0, 0, 4), dtype=np.uint8), 0, 0
87
88 parts = []
89 bboxes = []
90 for image in images:
91 data, x, y, trans = image.make_image(renderer, magnification)
92 if data is not None:
93 x *= magnification
94 y *= magnification
95 parts.append((data, x, y, image._get_scalar_alpha()))
96 bboxes.append(
97 Bbox([[x, y], [x + data.shape[1], y + data.shape[0]]]))
98
99 if len(parts) == 0:
100 return np.empty((0, 0, 4), dtype=np.uint8), 0, 0
101
102 bbox = Bbox.union(bboxes)
103
104 output = np.zeros(
105 (int(bbox.height), int(bbox.width), 4), dtype=np.uint8)
106
107 for data, x, y, alpha in parts:
108 trans = Affine2D().translate(x - bbox.x0, y - bbox.y0)
109 _image.resample(data, output, trans, _image.NEAREST,
110 resample=False, alpha=alpha)
111
112 return output, bbox.x0 / magnification, bbox.y0 / magnification
113
114
115def _draw_list_compositing_images(

Callers 1

flush_imagesFunction · 0.85

Calls 6

BboxClass · 0.90
Affine2DClass · 0.90
_get_scalar_alphaMethod · 0.80
unionMethod · 0.80
translateMethod · 0.80
make_imageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…