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 amatrix
with afunction
. Thisfunction
must be in the style ofphase
phase helper functions, which expect agrid
parameter 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. 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
function
onto.window – See
window_slice()
.function (function OR float) – A function in the style of
toolbox
helper functions, which acceptgrid
as the first argument. Also accepts floating point values, in which case this value is simply added.grid ((array_like, array_like) OR
SLM
OR 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.None
can only be passed if a float is passed asfunction
.imprint_operation ({"replace" OR "add"}) –
Decides how the
function
is imparted to thematrix
.If
"replace"
, then the values ofmatrix
insidewindow
are replaced withfunction
.If
"add"
, then these are instead added together (useful, for instance, for 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
shift_grid()
, operating on the cropped imprint grid. This is left as an option such that the user does not have to transform the entiregrid
to satisfy a tiny imprinted patch. Seeshift_grid()
for more details.shift ((float, float)) – Passed to
shift_grid()
, operating on the cropped imprint grid. This is left as an option such that the user does not have to transform the entiregrid
to satisfy a tiny imprinted patch. Seeshift_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
window
orimprint_operation
are provided.