pysdic.compute_projected_roi#

compute_projected_roi(mesh, camera, *, warp_by=None, margin=0.0)[source]#

Compute the region of interest (ROI) of the pixels covering the projected bounding box of a mesh (see compute_projected_bounding_box()), clipped to the sensor.

The box is rounded outwards (floor of the minimum, ceil of the maximum) and clipped to the sensor:

\[x = \max(\lfloor x_{\min} \rfloor, 0), \quad x + width - 1 = \min(\lceil x_{\max} \rceil, W - 1)\]

(and the same along \(y\) with \(H\)). All the projected vertices inside the sensor are then in \([x, x + width - 1] \times [y, y + height - 1]\), the domain where an pysdic.Image with this ROI can be interpolated.

The ROI is given in the format of pysdic.Image: it can be used directly as Image(data, roi=roi) or to slice the data, data[y : y + height, x : x + width].

Note

The interpolation function of an image is built on its ROI only, so it is less accurate close to the borders of the ROI. Use margin (a few pixels) to keep the projected mesh away from these borders. The notes of compute_projected_bounding_box() also apply.

Parameters:
  • mesh (pysdic.Mesh) – The mesh, of dimension \(E\) equal to the input dimension of the camera (the element type is not used).

  • camera (Union[pysdic.Camera, pysdic.View]) – The camera (or a view, whose camera is used).

  • warp_by (Optional[Union[str, ArrayLike]], optional) – The displacement of the vertices (name of a vertex property or array of shape \((N_v, E)\)), e.g. the displacement of a frame of an analysis.

  • margin (Real, optional (default: 0.0)) – The margin in pixels added on each side of the box before rounding (\(\geq 0\)).

Returns:

The ROI (x, y, width, height) in pixels, or None if no vertex has a finite projection or if the box is out of the sensor.

Return type:

Optional[Tuple[int, int, int, int]]

Raises:
  • TypeError – If an input has a wrong type.

  • ValueError – If the dimension of the mesh is not the input dimension of the camera, or if margin is negative or not finite.

Examples

1from pysdic import Image, compute_projected_roi
2
3roi = compute_projected_roi(mesh, camera, margin=5)
4image = Image.from_array(data, roi=roi)