machinevisiontoolbox.Image.paste
- Image.paste(pattern, pt, method='set', position='topleft', copy=False, zero=True)
Paste an image into an image
- Parameters:
pattern (
Image
, ndarray(H,W)) – image to be pastedpt (array_like(2)) – coordinates (u,v) where pattern is pasted
method (str) – options for image merging, one of:
'set'
[default],'mean'
,'add'
position (str, optional) –
pt
is one of:'topleft'
[default] or'centre'
copy (bool, optional) – copy image before pasting, defaults to False
zero (bool, optional) – zero-based coordinates (True, default) or 1-based coordinates (False)
- Raises:
ValueError – pattern is positioned outside the bounds of the image
- Returns:
original image with pasted pattern
- Return type:
Image
Pastes the
pattern
into the image which is modified inplace. The pattern can be incorporated into the specified image by:method
description
'set'
overwrites the pixels in image
'add'
adds to the pixels in image
'mean'
sets pixels to the mean of the pixel values in pattern and image
The
position
of the pastedpattern
in the image can be specified by its top left corner (umin, vmin) or its centre in the image.Example:
>>> from machinevisiontoolbox import Image >>> img1 = Image.Constant(5, value=10) >>> pattern = Image([[11, 12], [13, 14]]) >>> img1.copy().paste(pattern, (1,2)).image array([[10, 10, 10, 10, 10], [10, 10, 10, 10, 10], [10, 11, 12, 10, 10], [10, 13, 14, 10, 10], [10, 10, 10, 10, 10]], dtype=uint8) >>> img1.copy().paste(pattern, (1,2), method='add').image array([[10, 10, 10, 10, 10], [10, 10, 10, 10, 10], [10, 21, 22, 10, 10], [10, 23, 24, 10, 10], [10, 10, 10, 10, 10]], dtype=uint8) >>> img1.copy().paste(pattern, (1,2), method='mean').image array([[10, 10, 10, 10, 10], [10, 10, 10, 10, 10], [10, 10, 11, 10, 10], [10, 11, 12, 10, 10], [10, 10, 10, 10, 10]], dtype=uint8)
- Note:
Pixels outside the pasted region are unaffected.
If
copy
is False the image is modified in placeFor
position='centre'
an odd sized pattern is assumed. For an even dimension the centre pixel is the one at dimension / 2.Multi-plane images are supported.
If the pattern is multiplane and the image is singleplane, the image planes are replicated and colororder is taken from the pattern.
If the image is multiplane and the pattern is singleplane, the pattern planes are replicated.