Image.blend#

Image.blend(image2: Image, alpha: float, beta: float | None = None, gamma: float = 0, dtype: str | None = None) Image[source]#

Image blending

Parameters:
  • image2 (Image) – second image

  • alpha (float) – fraction of image

  • beta (float, optional) – fraction of image2, defaults to 1-alpha

  • gamma (int, optional) – image offset, defaults to 0

  • dtype (str, optional) – data type of the result, defaults to same as self

Raises:
  • ValueError – images are not same size

  • ValueError – images are of different type

Returns:

blended image

Return type:

Image

The resulting image isn a linear blend of the two input images self and image2 according to:

\[\mathbf{Y} = \alpha \mathbf{X}_1 + \beta \mathbf{X}_2 + \gamma\]

Example:

>>> from machinevisiontoolbox import Image
>>> img1 = Image.Constant(4, size=3)
>>> img2 = Image([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> img1.blend(img2, 0.5, 2).A
array([[ 4,  6,  8],
       [10, 12, 14],
       [16, 18, 20]], dtype=uint8)

Note

  • For uint8 images the result may be saturated. To avoid this specify dtype='float' and the result will be a floating point image.

  • For a multiplane image each plane is processed independently.

Important

Uses OpenCV function cv2.addWeighted which accepts multiple-channel, CV_8U, CV_16U, CV_16S, CV_32F or CV_64F images.

Seealso:

choose cv2.addWeighted