slmsuite.holography.analysis.take
- take(images, vectors, size, centered=True, integrate=False, clip=False, return_mask=False, plot=False, mp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/slmsuite/envs/latest/lib/python3.9/site-packages/numpy/__init__.py'>)[source]
Crop integration regions around an array of
vectors
, yielding an array of images.Each integration region is a rectangle of the same
size
. Similar to but more general thannumpy.take()
. Useful for gathering data from spots in spot arrays. Operates with some speed due to the vectorized nature of implemented slicing.- Parameters
images (array_like) – 2D image or array of 2D images.
vectors (array_like of floats) – 2-vector (or 2-vector array). Location(s) of integration region anchor(s) in pixels, see
centered
. Seeformat_2vectors()
.size (int or (int, int)) – Size of the rectangular integration region in
(w, h)
format in pixels. If a scalar is given, assume square(w, w)
.centered (bool) – Whether to center the integration region on the
vectors
. IfFalse
,vectors
indicates the upper-left corner of the integration region. Defaults toTrue
.integrate (bool) – If
True
, the spatial dimension are integrated (summed), yielding a result of the same length as the number of vectors. Defaults toFalse
.clip (bool) – Whether to allow out-of-range integration regions.
True
allows regions outside the valid area, setting the invalid region tonp.nan
(or zero if the array datatype does not supportnp.nan
).False
throws an error upon out of range. Defaults toFalse
.return_mask (bool) – If
True
, returns a boolean mask corresponding to the regions which are taken from. Defaults toFalse
. The average user will ignore this.plot (bool) – Calls
take_plot()
to visualize the images regions.mp (module) – If
images
arecupy
objects, thencupy
must be passed asmp
. Very useful to minimize the cost of moving data between the GPU and CPU. Defaults tonumpy
. Indexing variables inside :meth:`take still usenumpy
for speed, no matter what module is used.
- Returns
If
integrate
isFalse
, returns an array containing the images cropped from the regions of size(image_count, h, w)
. Ifintegrate
isTrue
, instead returns an array of floats of size(image_count,)
where each float corresponds to thenumpy.sum()
of a cropped image. Ifmp
iscupy
, then acupy.ndarray
is returned.- Return type
numpy.ndarray OR cupy.ndarray