slmsuite.holography.toolbox.imprint#
- imprint(matrix, window, function, grid=None, imprint_operation='replace', centered=False, circular=False, clip=True, transform=0, shift=(0, 0), **kwargs)[source]#
Imprints a region (defined by
window) of amatrixwith afunction. Thisfunctionmust be in the style ofphasephase helper functions, which expect agridparameter to define the coordinate basis (seeblaze()orlens()).For instance, we can imprint a blaze on a 200 by 200 pixel region of the SLM with:
canvas = np.zeros(shape=slm.shape) # Matrix to imprint onto. window = [200, 200, 200, 200] # Region of the matrix to imprint [x, w, y, h]. toolbox.imprint(canvas, window=window, function=toolbox.phase.blaze, grid=slm, vector=(.001, .001))
See also Examples.
- Parameters:
matrix (numpy.ndarray) – The data to imprint a
functiononto.window – Passed to
window_slice(). Seewindow_slice()for various options.function (function OR float) –
A function in the style of
toolboxhelper functions, which acceptgridas the first argument.Note
2D functions in
fitfunctionsare also of this style.Note
Also accepts floating point values, in which case the value is simply added.
grid ((array_like, array_like) OR
SLMOR None) – Meshgrids of normalized \(\frac{x}{\lambda}\) coordinates corresponding to SLM pixels, in(x_grid, y_grid)form. These are precalculated and stored in anySLM, so such a class can be passed instead of the grids directly if atoolboxfunction is used.Nonecan only be passed if a float is passed asfunction.imprint_operation ({"replace" OR "add"}) –
Decides how the
functionis imparted to thematrix.If
"replace", then the values ofmatrixinsidewindoware replaced withfunction.If
"add", then these are instead added together (useful, for instance, for adding global blazes).
centered – See
window_slice().circular – See
window_slice().clip (bool) – Whether to clip the imprint region if it exceeds the size of
matrix. IfFalse, then an error is raised when the size is exceeded. IfTrue, then the out-of-range pixels are instead filled withnumpy.nan.transform (float or ((float, float), (float, float))) – Passed to
transform_grid(), operating on the cropped imprint grid. This is left as an option such that the user does not have to transform the entiregridto satisfy a tiny imprinted patch. Seetransform_grid()for more details.shift ((float, float) OR None OR True) – Passed to
transform_grid(), operating on the cropped imprint grid. This is left as an option such that the user does not have to transform the entiregridto satisfy a tiny imprinted patch. IfTrue, the grid is centered on the region. Seetransform_grid()for more details.**kwargs – For passing additional arguments accepted by
function.
- Returns:
matrix – The modified image. Note that the matrix is modified in place, and this return is merely a copy of the user’s pointer to the data.
- Return type:
numpy.ndarray
- Raises:
ValueError – If invalid
windoworimprint_operationare provided.