rotated_rect_mask

laserbeamsize.background.rotated_rect_mask(image: ndarray, xc: float, yc: float, d_major: float, d_minor: float, phi: float) ndarray[tuple[Any, ...], dtype[bool]][source]

Create a boolean mask of a rotated rectangle within an image using NumPy.

Create ISO 11146 rectangular mask for specified beam.

ISO 11146-2 §7.2 states that integration should be carried out over “a rectangular integration area which is centred to the beam centroid, defined by the spatial first order moments, orientated parallel to the principal axes of the power density distribution, and sized three times the beam widths”.

This routine creates a mask with true values for each pixel in the image that should be part of the integration.

The rectangular mask is rotated about (xc, yc) using NumPy.

If the image is already masked, only unmasked pixels within the rectangle will be marked as True.

Parameters:
  • image – the image to work with (may be a masked array)

  • xc – horizontal center of beam (in full image coordinates)

  • yc – vertical center of beam (in full image coordinates)

  • d_major – semi-major ellipse diameter

  • d_minor – semi-minor ellipse diameter

  • phi – angle between horizontal and major axes [radians]

Returns:

masked_image – 2D array with True values inside rectangle