pysdic.ImagePlotter#

The pysdic.ImagePlotter draws images, the sensor of a camera and the geometrical objects of pysdic (pysdic.PointCloud, pysdic.Mesh, pysdic.IntegrationPoints) in the image coordinate system with matplotlib. Its API mirrors the one of pysdic.Plotter3D.

The objects are projected with the camera when their dimension is the input dimension of the camera (projected=None), or drawn directly as image points \((x, y)\) when they are 2D (see the projected argument).

ImagePlotter class#

class ImagePlotter(source, *, figsize=None, ax=None)[source]#

Bases: object

A plotter for the geometrical objects of pysdic (pysdic.PointCloud, pysdic.Mesh and pysdic.IntegrationPoints) and the images on the sensor of a camera, based on matplotlib.

The API mirrors pysdic.Plotter3D: add_image, add_sensor, add_point_cloud, add_mesh, add_integration_points, add_rectangle, set_title and show. It also draws the regions of interest of the images with add_roi.

The plot is in the image coordinate system \((x, y)\) in pixels: \(x\) is the column index and \(y\) the row index (pointing downwards). The centers of the pixels are at integer coordinates, so the sensor covers \([-0.5, W - 0.5] \times [-0.5, H - 0.5]\).

The objects are drawn as follows, according to their dimension \(E\):

  • With projected=None (default): if a camera is set and \(E\) is the input dimension of the camera, the points are projected with pysdic.Camera.project(). Otherwise \(E\) must be 2 and the points are drawn as image points \((x, y)\).

  • With projected=True: the points are always projected (a camera is required).

  • With projected=False: the points are always drawn as image points (\(E = 2\)).

The non-finite points (e.g. after a projection) are not drawn, nor the faces with a non-finite vertex.

Parameters:
  • source (Union[pysdic.Camera, pysdic.View, Tuple[Integral, Integral]]) – The camera (used to project the objects), the view (its camera and its image, the default of add_image()) or the sensor size (height, width) in pixels (only image points can then be drawn). The sensor size cannot be changed.

  • figsize (Optional[Tuple[Real, Real]], optional) – The size of the new figure in inches (width, height). Default: (8, 6). Cannot be given with ax.

  • ax (Optional[matplotlib.axes.Axes], optional) – Existing matplotlib axes to draw in (e.g. a subplot of a figure composed of several plotters). By default, a new figure is created.

Raises:
  • TypeError – If source or ax has a wrong type.

  • ValueError – If the sensor size or figsize are not strictly positive, or if both figsize and ax are given.

Instantiation#

The ImagePlotter class is instantiated with a source and optional figure settings:

  • From a camera: ImagePlotter(camera), to project the objects.

  • From a view: ImagePlotter(view), to project the objects and draw the image of the view by default.

  • From a sensor size: ImagePlotter((height, width)), to draw only image points.

The ax argument draws in existing matplotlib axes (e.g. a subplot of a larger figure).

Implemented methods and attributes#

The following sections provide an overview of the attributes and methods defined in the pysdic.ImagePlotter class.

Attributes#

ImagePlotter.ax

[Get] the internal matplotlib Axes object used for plotting.

ImagePlotter.camera

[Get] the camera used to project the objects, or None.

ImagePlotter.figure

[Get] the internal matplotlib Figure object used for plotting.

ImagePlotter.sensor_height

[Get] the height of the sensor in pixels.

ImagePlotter.sensor_width

[Get] the width of the sensor in pixels.

Sensor and image#

ImagePlotter.add_sensor(*[, color, ...])

Draw the sensor of the camera and optionally the grid of the pixels.

ImagePlotter.add_image([image, channel, ...])

Draw an image on the sensor, with its pixels centered at integer coordinates.

Geometrical objects#

ImagePlotter.add_point_cloud(point_cloud, *)

Add a point cloud to the plotter (projected or drawn as image points, see pysdic.ImagePlotter).

ImagePlotter.add_mesh(mesh, *[, projected, ...])

Add a mesh to the plotter (projected or drawn in image points, see pysdic.ImagePlotter).

ImagePlotter.add_integration_points(...[, ...])

Add integration points to the plotter, at their global coordinates in a mesh (see pysdic.Mesh.compute_property_interpolation()), projected or drawn as image points (see pysdic.ImagePlotter).

ImagePlotter.add_rectangle(center, width, ...)

Draw a rectangle in the image plane (e.g. a subset of DIC).

Figure methods#

ImagePlotter.set_title(title, *[, ...])

Add a title to the plotter.

ImagePlotter.clear()

Remove all the objects, color bars and the title from the plotter.

ImagePlotter.show()

Show the figure of the plotter (with matplotlib.pyplot.show).

ImagePlotter.close()

Close the figure of the plotter to free its memory (the whole figure, also when the plotter draws in given axes).