Image.samesize#

Image.samesize(image2: Any, bias: float = 0.5) Self[source]#

Automatic image trimming

Parameters:
  • image2 (Image or array_like(2)) – image to match size with

  • bias (float, optional) – bias that controls what part of the image is cropped, defaults to 0.5

Returns:

resized image

Return type:

Image

Return a version of the image that has the same dimensions as image2. This is achieved by cropping (to match the aspect ratio) and scaling (to match the size).

bias controls which part of the image is cropped. bias = 0.5 is symmetric cropping, bias < 0.5 moves the crop window up or to the left, while bias>0.5 moves the crop window down or to the right.

Example:

>>> from machinevisiontoolbox import Image
>>> foreground = Image.Read("greenscreen.png", dtype="float")
>>> foreground
Image(size=(1024, 768), dtype=float32, nplanes=3, colororder=R:G:B, name='.../images/greenscreen.png')
>>> background = Image.Read("road.png", dtype="float")
>>> background
Image(size=(1280, 851), dtype=float32, nplanes=3, colororder=R:G:B, name='.../images/road.png')
>>> background.samesize(foreground)
Image(size=(1024, 768), dtype=float32, nplanes=3, colororder=R:G:B)

Original background image:

(Source code, png, hires.png, pdf)

../_images/machinevisiontoolbox-Image-samesize-1.png

Samesized background image:

(Source code, png, hires.png, pdf)

../_images/machinevisiontoolbox-Image-samesize-2.png
References:
Seealso:

trim scale