subtract_background_image

laserbeamsize.background.subtract_background_image(original, background)[source]

Subtract a background image from the image with beam.

The function operates on 2D arrays representing grayscale images. Since the subtraction can result in negative pixel values, it is important that the return array be an array of float (instead of unsigned arrays that will wrap around.

Parameters:
  • original (numpy.ndarray) – 2D array image with beam present.

  • background (numpy.ndarray) – 2D array image without beam.

Returns:

numpy.ndarray – 2D array with background subtracted

Examples

>>> import numpy as np
>>> original = np.array([[1, 2], [3, 4]])
>>> background = np.array([[2, 1], [1, 1]])
>>> subtract_background_image(original, background)
array([[-1, 1],
       [2, 3]])