slmsuite.holography.toolbox.voronoi_windows

voronoi_windows(grid, vectors, radius=None, plot=False)[source]

Returns boolean array windows corresponding to the Voronoi cells for a set of vectors. These boolean array windows are in the style of imprint(). The ith window corresponds to the Voronoi cell centered around the ith vector.

Note

The cv2.fillConvexPoly() function used to fill each window dilates slightly outside the window bounds. To avoid pixels belonging to multiple windows simultaneously, we crop away previously-assigned pixels from new windows while these are being iteratively generated. As a result, windows earlier in the list will be slightly larger than windows later in the list.

Parameters
  • grid ((array_like, array_like) OR SLM OR (int, int)) – Meshgrids of normalized \(\frac{x}{\lambda}\) coordinates corresponding to SLM pixels, in (x_grid, y_grid) form. These are precalculated and stored in any SLM, so such a class can be passed instead of the grids directly. If an (int, int) is passed, this is assumed to be the shape of the device, and vectors are assumed to be in pixel units instead of normalized units.

  • vectors (array_like) – Points to Voronoi-ify. Cleaned with format_2vectors().

  • radius (float) – Cells on the edge of the set of cells might be very large. This parameter bounds the cells with a boolean and to the aperture of the given radius.

  • plot (bool) – Whether to plot the resulting Voronoi diagram with scipy.spatial.voronoi_plot_2d().

Returns

The resulting windows.

Return type

list of numpy.ndarray