crop_image_to_rect

laserbeamsize.image_tools.crop_image_to_rect(image: ndarray, xc_px: float, yc_px: float, xmin: float, xmax: float, ymin: float, ymax: float) tuple[ndarray | None, float | None, float | None][source]

Return image cropped to specified rectangle.

If the crop rectangle exceeds the image bounds, the returned image is padded with zeros to match the requested size, and those padded regions are masked.

Parameters:
  • image – image of beam

  • xc_px – horizontal center of beam

  • yc_px – vertical center of beam

  • xmin – left edge (pixels)

  • xmax – right edge (pixels)

  • ymin – top edge (pixels)

  • ymax – bottom edge (pixels)

Returns:

cropped_image – cropped masked array (None if resulting crop is too small) new_xc, new_yc: new beam center (pixels, None if crop is too small)