slmsuite.holography.analysis.take#
- take(images, vectors, size, centered=True, integrate=False, clip=False, return_mask=False, plot=False, xp=None)[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,vectorsindicates 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. Forces floating point datatype before the summation is done, as integer data (especially for cameras near saturation) can overflow. Defaults toFalse.clip (bool) – Whether to allow out-of-range integration regions.
Trueallows regions outside the valid area, setting the invalid region tonp.nan(or zero if the array datatype does not supportnp.nan).Falsethrows 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.xp (module OR None) – If
imagesarecupyobjects, thencupymust be passed asxp. Very useful to minimize the cost of moving data between the GPU and CPU. IfNone, defaults tonumpy. Indexing variables insidetake()still usenumpyfor speed, no matter what module is used.
- Returns:
If
integrateisFalse, returns an array containing the images cropped from the regions of size(image_count, h, w). IfintegrateisTrue, instead returns an array of floats of size(image_count,)where each float corresponds to thenumpy.sum()of a cropped image. Ifxpiscupy, then acupy.ndarrayis returned.- Return type:
numpy.ndarray OR cupy.ndarray