slmsuite.hardware.cameras.camera.Camera
- class Camera(width, height, bitdepth=8, dx_um=None, dy_um=None, rot='0', fliplr=False, flipud=False, name='camera')[source]
Bases:
object
Abstract class for cameras. Comes with transformations and helper functions like autoexpose.
- name
Camera identifier.
- Type
str
- shape
Stores
(height, width)
of the camera in pixels, the same convention asnumpy.shape()
.- Type
(int, int)
- bitdepth
Depth of a camera pixel well in bits.
- Type
int
- bitresolution
Stores
2**bitdepth
.- Type
int
- dx_um
\(x\) pixel pitch in microns. Defaults to
None
. Potential future features will use this.- Type
float or None
- exposure_bounds_s
Shortest and longest allowable integration in seconds.
- Type
(float, float) OR None
- woi
WOI (window of interest) in
(x, width, y, height)
form.- Type
tuple
- default_shape
Default
shape
of the camera before any WOI changes are made.- Type
tuple
- transform
Flip and/or rotation operator specified by the user in
__init__()
. The user is expected to apply this transform to the matrix returned inget_image()
. Note that WOI changes are applied on the camera hardware before this transformation.- Type
lambda
Methods
Sets the exposure of the camera such that the maximum value is at
set_fraction
of the dynamic range.Uses an FFT contrast metric to find optimal focus when scanning over some variable
z
.Abstract method to close the camera and delete related objects.
Abstract method to cycle the image buffer (if any) such that all new
get_image()
calls yield fresh frames.Abstract method to get the integration time in seconds.
Abstract method to pull an image from the camera and return.
Grab
image_count
images in succession.Abstract method to load display information.
Abstract method to reset the camera to a default state.
Abstract method to set the integration time in seconds.
Abstract method to narrow the imaging region to a 'window of interest' for faster framerates.
- __init__(width, height, bitdepth=8, dx_um=None, dy_um=None, rot='0', fliplr=False, flipud=False, name='camera')[source]
Initializes a camera.
In addition to the other class attributes, accepts the following parameters to set
transform
. Seeget_orientation_transformation()
.- Parameters
width – See
shape
.height – See
shape
.bitdepth – See
bitdepth
.dx_um – See
dx_um
.dy_um – See
dy_um
.rot (str or int) – Rotates returned image by the corresponding degrees in
["90", "180", "270"]
ornumpy.rot90()
code in[1, 2, 3]
. Defaults to no rotation. Used to determineshape
andtransform
.fliplr (bool) – Flips returned image left right. Used to determine
transform
.flipud (bool) – Flips returned image up down. Used to determine
transform
.name (str) – Defaults to
"camera"
.
- static info(verbose=True)[source]
Abstract method to load display information.
- Parameters
verbose (bool) – Whether or not to print display information.
- Returns
An empty list.
- Return type
list
- get_exposure()[source]
Abstract method to get the integration time in seconds. Used in
autoexposure()
.- Returns
Integration time in seconds.
- Return type
float
- set_exposure(exposure_s)[source]
Abstract method to set the integration time in seconds. Used in
autoexposure()
.- Parameters
exposure_s (float) – The integration time in seconds.
- set_woi(woi=None)[source]
Abstract method to narrow the imaging region to a ‘window of interest’ for faster framerates.
- flush(timeout_s=1)[source]
Abstract method to cycle the image buffer (if any) such that all new
get_image()
calls yield fresh frames.- Parameters
timeout_s (float) – The time in seconds to wait for frames to catch up with triggers.
- get_image(timeout_s=1)[source]
Abstract method to pull an image from the camera and return.
- Parameters
timeout_s (float) – The time in seconds to wait for the frame to be fetched.
- Returns
Array of shape
shape
.- Return type
numpy.ndarray
- get_images(image_count, flush=False)[source]
Grab
image_count
images in succession. Overwrite this implementation if a camera supports faster batch acquisition.- Parameters
image_count (int) – Number of images to grab.
flush (bool) – Whether to flush before grabbing.
- Returns
Array of shape
(image_count, height, width)
.- Return type
numpy.ndarray
- autoexposure(set_fraction=0.5, tol=0.05, exposure_bounds_s=None, window=None, average_count=5, timeout_s=5, verbose=True)[source]
Sets the exposure of the camera such that the maximum value is at
set_fraction
of the dynamic range. Useful for mitigating deleterious over- or under- exposure.- Parameters
set_fraction (float) – Fraction of camera dynamic range to target image maximum.
tol (float) – Fractional tolerance for exposure adjustment.
exposure_bounds_s ((float, float) OR None) – Shortest and longest allowable integration in seconds. If
None
, defaults toexposure_bounds_s
. If this attribute was not set (or not availible on a particular camera), thenNone
instead defaults to unbounded.window (array_like or None) – See
window
. IfNone
, the full camera frame will be used.average_count (int) – Number of frames to average intensity over for noise reduction.
timeout_s (float) – Stop attempting to autoexpose after
timeout_s
seconds.verbose (bool) – Whether to print exposure updates.
- Returns
Resulting exposure in seconds.
- Return type
float
- autofocus(z_get, z_set, z_list=None, plot=False)[source]
Uses an FFT contrast metric to find optimal focus when scanning over some variable
z
. Thisz
often takes the form of a vertical stage to position a sample precisely at the plane of imaging of a lens or objective. The contrast metric works particularly well when combined with a projected spot array hologram.- Parameters
z_get (lambda) – Gets the current position of the focusing stage. Should return a
float
.z_set (lambda) – Sets the position of the focusing stage to a given
float
.z_list (array_like or None) –
z
values to sweep over during search. Defaults (whenNone
) tonumpy.linspace(-4,4,16)
.plot (bool) – Whether to provide illustrative plots.