Camera Module
This module contains a Camera
simulator
and a DatasetGenerator
. The camera
serves to simulate image grabbing. The dataset generator uses the camera
simulator to generate a set of images and a descriptor file to simulate
a complete set of images of an EMVA1288 test.
camera
- class emva1288.camera.camera.Camera(f_number=8, pixel_area=25, bit_depth=8, width=640, height=480, temperature=22, temperature_ref=30, temperature_doubling=8, qe=None, exposure=1000000, exposure_min=500000, exposure_max=500000000, K=0.1, K_min=0.1, K_max=17.0, K_steps=255, blackoffset=0, blackoffset_min=0, blackoffset_max=None, blackoffset_steps=255, dark_current_ref=30, dark_signal_0=10.0, sigma2_dark_0=10.0, u_esat=15000.0, dsnu=None, prnu=None, seed=None)[source]
Bases:
object
Camera simulator. It creates images according to the given parameters.
- property DSNU
The Dark Signal non uniformity, DSNU (in e^-).
- Setter:
The setter allow the option to set a new dsnu who have the same shape than the image. See how it’s used
bad_pixel()
.
- property K
The overall system gain (in DN/e^-).
- Setter:
The setter uses the
nearest_value()
function to set the system gain to the nearest value given to the setter. This is because not all system gains are possible but rather a linear sample between the minimal and maximal value.
- property Ks
The array of all the available system gains (in DN/e^-).
- __init__(f_number=8, pixel_area=25, bit_depth=8, width=640, height=480, temperature=22, temperature_ref=30, temperature_doubling=8, qe=None, exposure=1000000, exposure_min=500000, exposure_max=500000000, K=0.1, K_min=0.1, K_max=17.0, K_steps=255, blackoffset=0, blackoffset_min=0, blackoffset_max=None, blackoffset_steps=255, dark_current_ref=30, dark_signal_0=10.0, sigma2_dark_0=10.0, u_esat=15000.0, dsnu=None, prnu=None, seed=None)[source]
Camera simulator init method.
- Parameters:
f_number (float, optional) – The emva1288 f_number for the camera.
pixel_area (float, optional) – The area of one pixel (in um ^ 2)
bit_depth (int, optional) – The number of bits allowed for one pixel value.
width (int, optional) – The number of columns in the the image.
height (int, optional) – The number of rows in the image.
temperature (float, optional) – The camera’s sensor temperature in degrees Celsius.
temperature_ref (float, optional) – The reference temperature (at which the dark current is equal to the reference dark current).
temperature_doubling (float, optional) – The doubling temperature (at which the dark current is two times the reference dark current).
qe (float, optional) – Quantum efficiency (between 0 and 1). If None, a simulated quantum efficiency is choosen with the
qe()
function.exposure (float, optional) – The camera’s exposure time in ns.
exposure_min (float, optional) – The camera’s minimal exposure time in ns.
exposure_max (float, optional) – The camera’s maximal exposure time in ns.
K (float, optional) – The overall system gain (in DN/e^-).
K_min (float, optional) – The overall minimal system gain (in DN/e^-).
K_max (float, optional) – The overall maximal system gain (in DN/e^-).
K_steps (int, optional) – The number of available intermediate overall system gains between K_min and K_max.
blackoffset (float, optional) – The dark signal offset for each pixel (in DN).
blackoffset_min (float, optional) – The minimal dark signal offset for each pixel (in DN).
blackoffset_max (float, optional) – The maximal dark signal offset for each pixel (in DN).
blackoffset_steps (int, optional) – The number of available blackoffsets between the mimimal and maximal blackoffsets.
dark_current_ref (float, optional) – The reference dark current used for computing the total dark current.
dark_signal_0 (float, optional) – Mean number of electrons generated by the electronics (offset)
sigma2_dark_0 (float, optional) – Variance of electrons generated by the electronics
u_esat (float, optional) – Full well capacity
dsnu (np.array, optional) – DSNU image in e^-, array with the same shape of the image that is added to every image.
prnu (np.array, optional) – PRNU image in percentages (1 = 100%), array with the same shape of the image. Every image is multiplied by it.
seed (int, optional) – A seed to initialize the random number generator.
- property bit_depth
The number of bits allowed for a gray value for one pixel.
- property blackoffset
The system dark signal offset (in DN).
- Setter:
The setter uses the
nearest_value()
function to set the black signal offset to the nearest value given to the setter. This is because not all black offsets are possible but rather a linear sample between the minimal and maximal value.
- property blackoffsets
The array of all blackoffsets (in DN).
- property exposure
The camera’s exposure time (in ns).
- property exposure_max
The camera’s maximal exposure time (in ns).
- property exposure_min
The camera’s minimal exposure time (in ns).
- get_photons(radiance, exposure=None, f_number=None)[source]
Computes the number of photons received by one pixel.
Uses the
get_photons()
function to compute this number.- Parameters:
radiance (float) – The radiance exposed to the camera (in Wsr^-1cm^-2).
exposure (float, optional) – The pixel’s exposure time in ns.
- Returns:
The number of photons received by one pixel.
- Return type:
float
- get_radiance_for(mean=None, exposure=None)[source]
Radiance to achieve saturation.
Calls the
get_radiance()
function to get the radiance for saturation.- Parameters:
mean (float, optional) – The saturation value of the camera. If None, this value is set to the
img_max
attribute.exposure (float, optional) – The camera’s exposure time at which the radiance for saturation value will be computed. If None, the exposure time taken will be the camera’s actual exposure time.
- Returns:
The radiance at which, for the given saturation value and the given exposure time, the camera saturates.
- Return type:
float
- grab(radiance, temperature=None, f_number=None)[source]
Create an image based on the mean and standard deviation from the EMVA1288 parameters.
The image is generated using a normal distribution for each pixel.
- Parameters:
radiance (ndarray) – The sensor’s illumination in W/cm^2/sr. This is the only mandatory argument because it is frequently changed during an test.
temperature (float, optional) – The camera’s temperature in degrees Celsius. If None, the environment’s temperature will be taken.
f_number (float, optional) – The optical setup f_number. If None, the environment’s f_number will be taken.
- property height
The number of rows
- property img_max
The maximal value for one pixel (in DN).
- property pixel_area
The area of one pixel (in um ^ 2).
- property qe
- property width
The number of columns
routines
- class emva1288.camera.routines.Qe(qe=None, wavelength=array([400., 404.04040404, 408.08080808, 412.12121212, 416.16161616, 420.2020202, 424.24242424, 428.28282828, 432.32323232, 436.36363636, 440.4040404, 444.44444444, 448.48484848, 452.52525253, 456.56565657, 460.60606061, 464.64646465, 468.68686869, 472.72727273, 476.76767677, 480.80808081, 484.84848485, 488.88888889, 492.92929293, 496.96969697, 501.01010101, 505.05050505, 509.09090909, 513.13131313, 517.17171717, 521.21212121, 525.25252525, 529.29292929, 533.33333333, 537.37373737, 541.41414141, 545.45454545, 549.49494949, 553.53535354, 557.57575758, 561.61616162, 565.65656566, 569.6969697, 573.73737374, 577.77777778, 581.81818182, 585.85858586, 589.8989899, 593.93939394, 597.97979798, 602.02020202, 606.06060606, 610.1010101, 614.14141414, 618.18181818, 622.22222222, 626.26262626, 630.3030303, 634.34343434, 638.38383838, 642.42424242, 646.46464646, 650.50505051, 654.54545455, 658.58585859, 662.62626263, 666.66666667, 670.70707071, 674.74747475, 678.78787879, 682.82828283, 686.86868687, 690.90909091, 694.94949495, 698.98989899, 703.03030303, 707.07070707, 711.11111111, 715.15151515, 719.19191919, 723.23232323, 727.27272727, 731.31313131, 735.35353535, 739.39393939, 743.43434343, 747.47474747, 751.51515152, 755.55555556, 759.5959596, 763.63636364, 767.67676768, 771.71717172, 775.75757576, 779.7979798, 783.83838384, 787.87878788, 791.91919192, 795.95959596, 800.]), width=640, height=480, filter=None)[source]
Bases:
object
- gen_qe()[source]
Simulate quantum efficiency for a specific wavelengths.
- Returns:
The simulated quantum efficiency.
- Return type:
float
- property qe
- property w
- emva1288.camera.routines.get_bayer_filter(t00, t01, t10, t11, width, height, w)[source]
From different values of transmition and the size, get a bayer filter.
Pattern
This case
Example
Suggested values
t00
t01
G1
R
1
0.15
t10
t11
B
G2
0.02
1
Where G1 and G2 are transmition values for a green filter, R for a red filter and B for a blue filter. The suggested values are values for a standard bayer filter like the example.
- Parameters:
t00 (int) – The wavelength of the first pixel.
t01 (int) – The wavelength of the second pixel.
t10 (int) – The wavelength of the third pixel.
t11 (int) – The wavelength of the fourth pixel.
width (int) – The number of columns in the the image.
height (int) – The number of rows in the image.
w (array_like) – Array of the wavelengths to be returned
- Returns:
The array with the bayer filter of the size gived.
- Return type:
array
- emva1288.camera.routines.get_photons(exposure, radiance, pixel_area, wavelength, f_number)[source]
Get the number of photons hitting one pixel.
- Parameters:
exposure (float) – The pixel exposure time (in ns) to the light.
radiance (float or array_like) – The radiance hitting the sensor (in W/sr/cm^2).
pixel_area (float) – The pixel area in um ^ 2
f_number (float) – The f number of the setup.
- Returns:
The number of photons that hit the pixel.
- Return type:
float
- emva1288.camera.routines.get_radiance(exposure, photons, pixel_area, f_number, wavelength)[source]
From the number of photons, get the radiance hitting a pixel.
- Parameters:
exposure (float) – The pixel exposure time to the light (in ns).
wavelength (float) – The photons’ wavelength (in nm).
photons (float) – The number of photons that hit the pixel.
pixel_area (float) – The pixel area in um^2.
f_number (float) – The f number of the setup.
- Returns:
The radiance that hit the pixel and gave the number of photons.
- Return type:
float
- emva1288.camera.routines.get_tile(arr, height, width)[source]
- From an array with a pattern, repeat the array to fill an 2D array
with the given dimention.
- Parameters:
arr (array) – The pattern wanted to be replecate in a bigger shape.
height (int) – The height of the array wanted in return.
width (int) – The width of the array wanted in return.
- Returns:
The pattern given(arr) replecate in the size given.
- Return type:
array
- emva1288.camera.routines.nearest_value(value, array)[source]
Returns the nearest value in vals.
- Parameters:
value (float) – The value we want to get as near as possible.
array (array_like) – The array containing the available values to get near the value.
- Return type:
The nearest element of array to value.
dataset_generator
- class emva1288.camera.dataset_generator.DatasetGenerator(steps=100, L=50, version='4.0', image_format='png', outdir=None, radiance_min=None, radiance_max=None, exposure_fixed=None, **kwargs)[source]
Bases:
object
Dataset generator.
Creates a descriptor file and the corresponding linked images for a a exposure variant test example according to the emva1288 standart. The images are created using the implemented camera in the emva module.
- __init__(steps=100, L=50, version='4.0', image_format='png', outdir=None, radiance_min=None, radiance_max=None, exposure_fixed=None, **kwargs)[source]
Dataset generator init method.
The generator uses a
PointsGenerator
object to create the operation points. It then grabs the images for these points using aCamera
simulator object. The camera is intialized according to the given kwargs. Then, after getting the test points, itmakes
the images with it by changing its exposure time, or the radiation andsaves
the images and the descriptor file.- Parameters:
L (int, optional) – The number of image taken during a spatial test point.
version (str, optional) – Data version to add in descriptor file.
image_format (str, optional) – The image’s format when they are saved.
outdir (str, optional) – The output directory where the descriptor file and the images will be saved. If None, it will create a tempory directory that will be deleted (and its contents) when the dataset generator object is deleted.
radiance_min (float, optional) – Same as in
PointsGenerator
.radiance_max (float, optional) – Same as in
PointsGenerator
.exposure_fixed (float, optional) – Same as in
PointsGenerator
.kwargs (All other kwargs are passed to the camera.) –
- property descriptor_path
The absolute path to the descriptor file.
- property points
The test points suite.
points_generator
- class emva1288.camera.points_generator.PointsGenerator(cam, exposure_min=None, exposure_max=None, exposure_fixed=None, radiance_min=None, radiance_max=None, gain=None, blackref=None, steps=100)[source]
Bases:
object
Class that generates a dictionary of operation points for an emva test.
The points are stored in the
points
attribute as a dictionary. The points are ordered if they are a ‘spatial’ or ‘temporal’ operation point. Under each keys there is a dictionary whose keys are the different exposure times and their values are the list of radiances under which the camera is illuminated.- __init__(cam, exposure_min=None, exposure_max=None, exposure_fixed=None, radiance_min=None, radiance_max=None, gain=None, blackref=None, steps=100)[source]
Point generator init method.
- Parameters:
cam (The camera object that will be taking the images.) –
exposure_min (float, optional) – The minimal exposure time (in ns).
exposure_max (float, optional) – The maximal exposure time (in ns).
exposure_fixed (float, optional) – By default, the points given are for an exposure time variation test (if this is None). If a value is given to this kwarg, this will be the camera’s exposure time (in ns) at which the operation points will be set for an illumination variation test.
radiance_min (float, optional) – The minimal radiance (in W/cm^2/sr). If None, a value above dark illumination will be automatically chosen.
radiance_max (float, optional) – The maximal radiance (in W/cm^2/sr). If None, the maximal radiation will be taken as the saturation radiation for the exposition time given in the exposure_fixed kwarg.
gain (float, optional) – The camera’s gain at which we want the test to run.
blackref (float, optional) – The camera’s blackoffset at which we want the test to run.
steps (int, optional) – The number of points in the test.
- property points
The operation points.