machinevisiontoolbox.Image.samesize

Image.samesize(image2, bias=0.5)

Automatic image trimming

Parameters:
  • v – 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

Rtype out:

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: 1024 x 768 (float32), R:G:B [.../images/greenscreen.png]
>>> background = Image.Read("road.png", dtype="float")
>>> background
Image: 1280 x 851 (float32), R:G:B [.../images/road.png]
>>> background.samesize(foreground)
Image: 1024 x 768 (float32), R:G:B
References:
  • Robotics, Vision & Control for Python, Section 11.4.1.1, P. Corke, Springer 2023.

Seealso:

trim scale