Sensor API Reference
The deeplens.sensor module provides differentiable sensor models with noise simulation and a full image signal processing (ISP) pipeline.
Sensor Models
Base sensor class.
deeplens.sensor.Sensor
Bases: Module
Minimal image sensor with gamma-only ISP.
The simplest sensor model: records physical size and resolution, and
applies only a gamma correction in the ISP forward pass. For a sensor
with noise simulation and Bayer demosaicing use
:class:~deeplens.sensor.rgb_sensor.RGBSensor.
Attributes:
| Name | Type | Description |
|---|---|---|
size |
tuple
|
Physical sensor size (W, H) [mm]. |
res |
tuple
|
Pixel resolution (W, H). |
isp |
Sequential
|
ISP pipeline ( |
Example
sensor = Sensor(size=(8.0, 6.0), res=(4000, 3000)) sensor = Sensor.from_config("sensor.json")
Initialize a minimal sensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple
|
Physical sensor size (W, H) [mm].
Defaults to |
(8.0, 6.0)
|
res
|
tuple
|
Pixel resolution (W, H).
Defaults to |
(4000, 3000)
|
Source code in deeplens/sensor/sensor.py
from_config
classmethod
Create a Sensor from a JSON config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_file
|
Path to JSON sensor config file. |
required |
Returns:
| Type | Description |
|---|---|
|
Sensor instance. |
Source code in deeplens/sensor/sensor.py
response_curve
Apply response curve to the irradiance image to get the raw image.
Default is identity (linear response).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_irr
|
Irradiance image |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_raw |
Raw image |
unprocess
Inverse ISP: convert sRGB image back to linear RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Tensor of shape (B, C, H, W), range [0, 1] in sRGB space. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_linear |
Tensor of shape (B, C, H, W), range [0, 1] in linear space. |
Source code in deeplens/sensor/sensor.py
linrgb2raw
Convert linear RGB image to raw sensor space.
For the base Sensor, raw is the linear image itself (identity).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_linear
|
Tensor of shape (B, C, H, W), range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_raw |
Tensor of shape (B, C, H, W), range [0, 1]. |
Source code in deeplens/sensor/sensor.py
simu_noise
Simulate sensor noise.
Default is identity (no noise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Input image |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img |
Same image unchanged |
Full RGB sensor with Bayer pattern, noise model (read noise + shot noise), and ISP pipeline (black level compensation, white balance, demosaicing, color correction, gamma).
deeplens.sensor.RGBSensor
RGBSensor(size=(36.0, 24.0), res=(5472, 3648), bit=10, black_level=64, bayer_pattern='rggb', white_balance=(2.0, 1.0, 1.8), color_matrix=None, gamma_param=2.2, iso_base=100, read_noise_std=0.5, shot_noise_std_alpha=0.4, shot_noise_std_beta=0.0, wavelengths=None, red_response=None, green_response=None, blue_response=None)
Bases: Sensor
RGB Bayer-pattern sensor with physics-based noise model and invertible ISP.
Simulates the full image-capture pipeline from linear photon counts to display-ready sRGB:
- Spectral integration – optional per-channel spectral response.
- Bayer mosaic – pixel-level colour filtering to a single-channel raw image.
- Noise – shot noise (signal-dependent Gaussian) + read noise (ISO-independent Gaussian) added to the n-bit raw data.
- ISP (forward) – via an
:class:
~deeplens.sensor.isp_modules.isp.InvertibleISP: black-level correction → white balance → colour matrix → demosaicing → gamma correction.
The ISP is invertible: unprocess() converts sRGB back to linear
RGB for training data generation.
Attributes:
| Name | Type | Description |
|---|---|---|
bit |
int
|
ADC bit depth. |
nbit_max |
int
|
Maximum digital number |
black_level |
int
|
Black level pedestal [DN]. |
bayer_pattern |
str
|
Bayer pattern (e.g. |
iso_base |
int
|
Base ISO (noise-free reference). |
isp |
InvertibleISP
|
Embedded ISP pipeline. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple
|
Sensor physical size in mm (W, H). Default (36.0, 24.0). |
(36.0, 24.0)
|
res
|
tuple
|
Sensor resolution in pixels (W, H). Default (5472, 3648). |
(5472, 3648)
|
bit
|
int
|
Bit depth. Default 10. |
10
|
black_level
|
int
|
Black level. Default 64. |
64
|
bayer_pattern
|
str
|
Bayer pattern e.g. "rggb". Default "rggb". |
'rggb'
|
white_balance
|
tuple
|
White balance gains. Default (2.0, 1.0, 1.8). |
(2.0, 1.0, 1.8)
|
color_matrix
|
list or Tensor
|
Color correction matrix. |
None
|
gamma_param
|
float
|
Gamma correction parameter. Default 2.2. |
2.2
|
iso_base
|
int
|
Base ISO. Default 100. |
100
|
read_noise_std
|
float
|
Read noise std. Default 0.5. |
0.5
|
shot_noise_std_alpha
|
float
|
Shot noise alpha. Default 0.4. |
0.4
|
shot_noise_std_beta
|
float
|
Shot noise beta. Default 0.0. |
0.0
|
wavelengths
|
list
|
Wavelengths. |
None
|
red_response
|
list
|
Red channel spectral response. |
None
|
green_response
|
list
|
Green channel spectral response. |
None
|
blue_response
|
list
|
Blue channel spectral response. |
None
|
Source code in deeplens/sensor/rgb_sensor.py
from_config
classmethod
Create an RGBSensor from a JSON config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_file
|
Path to JSON sensor config file. |
required |
Returns:
| Type | Description |
|---|---|
|
RGBSensor instance. |
Source code in deeplens/sensor/rgb_sensor.py
response_curve
Apply response curve to the spectral image to get the raw image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_spectral
|
Spectral image, shape (B, C, H, W), range [0, 1] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_raw |
Raw image, shape (B, 3, H, W), range [0, 1] |
Reference
[1] Spectral Sensitivity Estimation Without a Camera. ICCP 2023. [2] https://github.com/COLOR-Lab-Eilat/Spectral-sensitivity-estimation
Source code in deeplens/sensor/rgb_sensor.py
unprocess
Unprocess an image to unbalanced RAW RGB space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor of shape (B, 3, H, W), range [0, 1] |
required | |
in_type
|
Input image type, either "rgb" or "linear_rgb" |
'rgb'
|
Returns:
| Name | Type | Description |
|---|---|---|
image |
Tensor of shape (B, 3, H, W), range [0, 1] in raw space |
Source code in deeplens/sensor/rgb_sensor.py
linrgb2raw
Convert linear RGB image to raw Bayer space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_linrgb
|
Tensor of shape (B, 3, H, W), range [0, 1] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer_nbit |
Tensor of shape (B, 1, H, W), range [~black_level, 2**bit - 1] |
Source code in deeplens/sensor/rgb_sensor.py
simu_noise
Simulate sensor noise considering sensor quantization and noise model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_raw
|
N-bit clean image, (B, C, H, W), range [0, 2**bit - 1] |
required | |
iso
|
(B,), range [0, 800] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_raw_noise |
N-bit noisy image, (B, C, H, W), range [0, 2**bit - 1] |
Reference
[1] "Unprocessing Images for Learned Raw Denoising." [2] https://www.photonstophotos.net/Charts/RN_ADU.htm [3] https://www.photonstophotos.net/Investigations/Measurement_and_Sample_Variation.htm [4] https://www.dpreview.com/forums/thread/4669806
Source code in deeplens/sensor/rgb_sensor.py
sample_augmentation
Randomly sample a set of augmentation parameters for ISP modules. Used for data augmentation during training.
Source code in deeplens/sensor/rgb_sensor.py
reset_augmentation
Reset parameters for ISP modules. Used for evaluation.
process2rgb
Process an image to a RGB image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor of shape (B, 3, H, W), range [0, 1] |
required | |
in_type
|
Input image type, either "rggb" or "bayer" |
'rggb'
|
Returns:
| Name | Type | Description |
|---|---|---|
image |
Tensor of shape (B, 3, H, W), range [0, 1] |
Source code in deeplens/sensor/rgb_sensor.py
bayer2rggb
Convert RAW bayer image to RAW RGGB image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer_nbit
|
Tensor of shape (B, 1, H, W), range [~black_level, 2**bit - 1] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rggb |
Tensor of shape (B, 3, H, W), range [0, 1] |
Source code in deeplens/sensor/rgb_sensor.py
rggb2bayer
Convert RGGB image to RAW Bayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rggb
|
Tensor of shape [4, H/2, W/2] or [B, 4, H/2, W/2], range [0, 1] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer |
Tensor of shape [1, H, W] or [B, 1, H, W], range [~black_level, 2**bit - 1] |
Source code in deeplens/sensor/rgb_sensor.py
Monochrome sensor without color filter array.
deeplens.sensor.MonoSensor
MonoSensor(bit=10, black_level=64, size=(8.0, 6.0), res=(4000, 3000), read_noise_std=0.5, shot_noise_std_alpha=0.4, shot_noise_std_beta=0.0, iso_base=100, wavelengths=None, spectral_response=None)
Bases: Sensor
Monochrome sensor with noise simulation and ISP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bit
|
int
|
Bit depth of the sensor. Default 10. |
10
|
black_level
|
float
|
Black level value. Default 64. |
64
|
size
|
tuple
|
Sensor physical size in mm (W, H). Default (8.0, 6.0). |
(8.0, 6.0)
|
res
|
tuple
|
Sensor resolution in pixels (W, H). Default (4000, 3000). |
(4000, 3000)
|
read_noise_std
|
float
|
Read noise standard deviation. Default 0.5. |
0.5
|
shot_noise_std_alpha
|
float
|
Shot noise alpha parameter. Default 0.4. |
0.4
|
shot_noise_std_beta
|
float
|
Shot noise beta parameter. Default 0.0. |
0.0
|
iso_base
|
int
|
Base ISO value. Default 100. |
100
|
wavelengths
|
list
|
Wavelengths for spectral response. |
None
|
spectral_response
|
list
|
Spectral response values. |
None
|
Source code in deeplens/sensor/mono_sensor.py
from_config
classmethod
Create a MonoSensor from a JSON config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_file
|
Path to JSON sensor config file. |
required |
Returns:
| Type | Description |
|---|---|
|
MonoSensor instance. |
Source code in deeplens/sensor/mono_sensor.py
response_curve
Apply spectral response curve to get a monochrome raw image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_spectral
|
Spectral image, (B, N_wavelengths, H, W) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_raw |
Monochrome raw image, (B, 1, H, W) |
Source code in deeplens/sensor/mono_sensor.py
unprocess
Inverse ISP: convert gamma-corrected image back to linear RGB space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Tensor of shape (B, C, H, W), range [0, 1] in display space. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_linear |
Tensor of shape (B, C, H, W), range [0, 1] in linear space. |
Source code in deeplens/sensor/mono_sensor.py
linrgb2raw
Convert linear image to n-bit raw digital number.
Applies spectral response (RGB to Mono) and quantization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_linear
|
Tensor of shape (B, C, H, W), range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_nbit |
Tensor of shape (B, 1, H, W), range [~black_level, 2**bit - 1]. |
Source code in deeplens/sensor/mono_sensor.py
simu_noise
Simulate sensor noise considering sensor quantization and noise model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_raw
|
N-bit clean image, (B, C, H, W), range [0, 2**bit - 1] |
required | |
iso
|
(B,), range [0, 800] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_raw_noise |
N-bit noisy image, (B, C, H, W), range [0, 2**bit - 1] |
Reference
[1] "Unprocessing Images for Learned Raw Denoising." [2] https://www.photonstophotos.net/Charts/RN_ADU.htm [3] https://www.photonstophotos.net/Investigations/Measurement_and_Sample_Variation.htm [4] https://www.dpreview.com/forums/thread/4669806
Source code in deeplens/sensor/mono_sensor.py
Event camera sensor that outputs asynchronous brightness-change events.
deeplens.sensor.EventSensor
EventSensor(size=(8.0, 6.0), res=(4000, 3000), threshold_pos=0.2, threshold_neg=0.2, sigma_threshold=0.03, cutoff_hz=0.0, leak_rate_hz=0.0, shot_noise_rate_hz=0.0, eps=1e-07)
Bases: Sensor
Event sensor (Dynamic Vision Sensor) simulation.
An event camera independently measures per-pixel log-intensity changes and fires an event whenever the change exceeds a contrast threshold:
e_k = (x_k, y_k, t_k, p_k)
where p_k ∈ {+1, -1} is the polarity. This class produces dense event count maps of shape (B, 2, H, W) where channel 0 counts positive events and channel 1 counts negative events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
Physical sensor size in mm, (width, height). |
(8.0, 6.0)
|
|
res
|
Sensor resolution in pixels, (width, height). |
(4000, 3000)
|
|
threshold_pos
|
Positive contrast threshold (C+). Default 0.2. |
0.2
|
|
threshold_neg
|
Negative contrast threshold (C-). Default 0.2. |
0.2
|
|
sigma_threshold
|
Std-dev of threshold noise. Set to 0 for deterministic operation. Default 0.03. |
0.03
|
|
cutoff_hz
|
High-pass temporal filter cutoff frequency in Hz. Set to 0 to disable. Default 0. |
0.0
|
|
leak_rate_hz
|
Leak event rate in Hz. Simulates spontaneous background events. Set to 0 to disable. Default 0. |
0.0
|
|
shot_noise_rate_hz
|
Shot noise event rate in Hz. Simulates noise events from dark current. Set to 0 to disable. Default 0. |
0.0
|
|
eps
|
Small constant added before log to avoid log(0). Default 1e-7. |
1e-07
|
Source code in deeplens/sensor/event_sensor.py
from_config
classmethod
Create an EventSensor from a JSON config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_file
|
Path to JSON sensor config file. |
required |
Returns:
| Type | Description |
|---|---|
|
EventSensor instance. |
Source code in deeplens/sensor/event_sensor.py
forward
Convert two consecutive frames into a dense event count map.
Each pixel independently computes the change in log intensity and fires integer-count positive or negative events when the change exceeds the contrast threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
I_t
|
Current frame, tensor (B, C, H, W), range [0, 1]. |
required | |
I_t_1
|
Previous frame, tensor (B, C, H, W), range [0, 1]. |
required | |
dt
|
Time interval between frames in seconds. Required when
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
events |
Tensor (B, 2, H, W). Channel 0 = positive event counts, channel 1 = negative event counts. |
Source code in deeplens/sensor/event_sensor.py
forward_video
Simulate event sensor output from a video sequence.
Iterates over consecutive frame pairs and generates event count maps for each transition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
Tensor (B, T, C, H, W), range [0, 1]. |
required | |
dt
|
Time interval between frames in seconds. Default None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
events |
Tensor (B, T-1, 2, H, W). Event count maps for each consecutive frame pair. |
Source code in deeplens/sensor/event_sensor.py
events_to_voxel_grid
Convert event count map to a temporal voxel grid representation.
Distributes events across num_bins temporal bins using linear
interpolation. This is a common input representation for event-
based neural networks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Tensor (B, 2, H, W) — single-pair event counts. |
required | |
num_bins
|
Number of temporal bins. Default 5. |
5
|
Returns:
| Name | Type | Description |
|---|---|---|
voxel |
Tensor (B, num_bins, H, W). |
Source code in deeplens/sensor/event_sensor.py
events_to_timestamp_image
Convert event count map to a 2-channel timestamp-like image.
Creates a representation where non-zero pixels indicate event activity. Channel 0 stores positive event magnitude, channel 1 stores negative event magnitude, both normalised to [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Tensor (B, 2, H, W). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ts_img |
Tensor (B, 2, H, W), range [0, 1]. |
Source code in deeplens/sensor/event_sensor.py
ISP Modules
Individual image signal processing stages used inside RGBSensor. Each module is a torch.nn.Module.
deeplens.sensor.isp_modules.BlackLevelCompensation
Bases: Module
Black level compensation (BLC).
Black level compensation is a technique to subtract the black level from the image.
Initialize black level compensation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bit
|
Bit depth of the input image. |
10
|
|
black_level
|
Black level value. |
64
|
Source code in deeplens/sensor/isp_modules/black_level.py
forward
Black Level Compensation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Tensor
|
Input n-bit bayer image [B, 1, H, W], data range [~black_level, 2**bit - 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer_float |
Tensor
|
Output float bayer image [B, 1, H, W], data range [0, 1]. |
Source code in deeplens/sensor/isp_modules/black_level.py
reverse
Inverse black level compensation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Input tensor of shape [B, 1, H, W], data range [0, 1]. |
required | |
quantize
|
If True, round to integer values (non-differentiable). |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
bayer_nbit |
Output tensor of shape [B, 1, H, W], data range [0, 2^bit-1]. |
Source code in deeplens/sensor/isp_modules/black_level.py
deeplens.sensor.isp_modules.AutoWhiteBalance
Bases: Module
Auto white balance (AWB).
Initialize auto white balance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
awb_method
|
AWB method, "gray_world" or "manual". |
'gray_world'
|
|
white_balance
|
RGB white balance for manual AWB, shape [3]. |
(2.0, 1.0, 1.8)
|
Source code in deeplens/sensor/isp_modules/white_balance.py
apply_awb_bayer
Apply white balance to Bayer pattern image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Input tensor of shape [B, 1, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer_wb |
Output tensor with same shape as input. |
Source code in deeplens/sensor/isp_modules/white_balance.py
apply_awb_rgb
Apply white balance to RGB image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb
|
Input tensor of shape [B, 3, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb_wb |
Output tensor with same shape as input. |
Source code in deeplens/sensor/isp_modules/white_balance.py
forward
Auto White Balance (AWB).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_tensor
|
Input tensor of shape [B, 1, H, W] or [B, 3, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
output_tensor |
Output tensor [B, 1, H, W] or [B, 3, H, W]. |
Source code in deeplens/sensor/isp_modules/white_balance.py
reverse
Inverse auto white balance (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Input tensor of shape [3, H, W] or [B, 3, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb_unbalanced |
Output tensor with inverse white balance applied. |
Source code in deeplens/sensor/isp_modules/white_balance.py
safe_reverse_awb
Inverse auto white balance.
Ref: https://github.com/google-research/google-research/blob/master/unprocessing/unprocess.py#L92C1-L102C28
Source code in deeplens/sensor/isp_modules/white_balance.py
deeplens.sensor.isp_modules.Demosaic
Bases: Module
Demosaic, or Color Filter Array (CFA).
Converts a Bayer pattern image to a full RGB image by interpolating missing color values at each pixel location.
Supported methods
- "bilinear": Simple bilinear interpolation (fast, lower quality)
- "malvar": Malvar-He-Cutler high-quality gradient-corrected interpolation
Reference
[1] Malvar, He, Cutler. "High-Quality Linear Interpolation for Demosaicing of Bayer-Patterned Color Images", ICASSP 2004.
Initialize demosaic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer_pattern
|
Bayer pattern, "rggb" or "bggr". |
'rggb'
|
|
method
|
Demosaic method, "bilinear" or "malvar". |
'malvar'
|
Source code in deeplens/sensor/isp_modules/demosaic.py
forward
Demosaic a Bayer pattern image to RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Input tensor of shape [B, 1, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb |
Output tensor of shape [B, 3, H, W]. |
Source code in deeplens/sensor/isp_modules/demosaic.py
reverse
Inverse demosaic from RAW RGB to RAW Bayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Tensor
|
RAW RGB image, shape [3, H, W] or [B, 3, H, W], data range [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Bayer image, shape [1, H, W] or [B, 1, H, W], data range [0, 1]. |
Source code in deeplens/sensor/isp_modules/demosaic.py
deeplens.sensor.isp_modules.ColorCorrectionMatrix
Bases: Module
Color correction matrix (CCM).
Color correction matrix is a 4x3 matrix that corrects the color of the image.
Initialize color correction matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ccm_matrix
|
Color correction matrix of shape [4, 3]. Example: [[1.8506, -0.7920, -0.0605], [-0.1562, 1.6455, -0.4912], [ 0.0176, -0.5439, 1.5254], [ 0.0, 0.0, 0.0 ]] |
None
|
Reference
[1] https://github.com/QiuJueqin/fast-openISP/blob/master/configs/nikon_d3200.yaml#L57 [2] https://github.com/timothybrooks/hdr-plus/blob/master/src/finish.cpp#L626 [3] https://www.dxomark.com/Cameras/Canon/EOS-R6---Measurements, "Color Response"
Source code in deeplens/sensor/isp_modules/color_matrix.py
sample_augmentation
Sample augmentation for synthetic data generation.
reset_augmentation
forward
Color Correction Matrix. Convert RGB image to sensor color space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb_image
|
Input tensor of shape [B, 3, H, W] in RGB format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb_corrected |
Corrected RGB image in sensor color space. |
Source code in deeplens/sensor/isp_modules/color_matrix.py
reverse
Inverse color correction matrix. Convert sensor color space to RGB image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb_image
|
Input tensor of shape [B, 3, H, W] in sensor color space. |
required |
Source code in deeplens/sensor/isp_modules/color_matrix.py
deeplens.sensor.isp_modules.GammaCorrection
Bases: Module
Gamma correction (GC).
Gamma correction is a technique to adjust the gamma of the image.
Initialize gamma correction module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma_param
|
Gamma parameter. Default is 2.2. |
2.2
|
Source code in deeplens/sensor/isp_modules/gamma_correction.py
sample_augmentation
Sample augmentation for synthetic data generation.
Source code in deeplens/sensor/isp_modules/gamma_correction.py
reset_augmentation
forward
Gamma Correction (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
tensor
|
Input image. Shape of [B, C, H, W]. |
required |
quantize
|
bool
|
Whether to quantize the image to 8-bit. WARNING: quantize=True makes this non-differentiable! |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
img_gamma |
tensor
|
Gamma corrected image. Shape of [B, C, H, W]. |
Reference
[1] "There is no restriction as to where stage gamma correction is placed," page 35, Architectural Analysis of a Baseline ISP Pipeline.
Source code in deeplens/sensor/isp_modules/gamma_correction.py
reverse
Inverse gamma correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
tensor
|
Input image. Shape of [B, C, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img |
tensor
|
Inverse gamma corrected image. Shape of [B, C, H, W]. |
Reference
[1] https://github.com/google-research/google-research/blob/master/unprocessing/unprocess.py#L78
Source code in deeplens/sensor/isp_modules/gamma_correction.py
deeplens.sensor.isp_modules.ToneMapping
Bases: Module
Global tone mapping operator.
Maps HDR linear radiance values to displayable [0, 1] range using a global (per-pixel, spatially invariant) curve.
Supported methods
- "reinhard": L / (1 + L), from [Reinhard et al. 2002].
- "aces": ACES filmic curve approximation, from [Narkowicz 2015].
- "hable": Uncharted 2 filmic curve, from [Hable 2010].
Reference
[1] Reinhard et al., "Photographic Tone Reproduction for Digital Images", SIGGRAPH 2002. [2] Narkowicz, "ACES Filmic Tone Mapping Curve", 2015. [3] Hable, "Filmic Tonemapping Operators", GDC 2010.
Initialize tone mapping module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Tone mapping method, one of "reinhard", "aces", "hable". |
'reinhard'
|
|
exposure
|
Exposure multiplier applied before tone mapping. |
1.0
|
Source code in deeplens/sensor/isp_modules/tone_mapping.py
forward
Apply global tone mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
HDR linear image, (B, C, H, W), range [0, +inf). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_tm |
Tone-mapped image, (B, C, H, W), range [0, 1]. |
Source code in deeplens/sensor/isp_modules/tone_mapping.py
reverse
Inverse tone mapping (recover linear HDR from tone-mapped image).
Only analytically invertible for "reinhard". For "aces" and "hable", uses an iterative Newton's method approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Tone-mapped image, (B, C, H, W), range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_hdr |
Recovered linear image, (B, C, H, W), range [0, +inf). |
Source code in deeplens/sensor/isp_modules/tone_mapping.py
deeplens.sensor.isp_modules.DeadPixelCorrection
Bases: Module
Dead pixel correction (DPC).
Detects and corrects dead/stuck pixels by comparing each pixel to its neighbors and replacing outliers with a local mean value.
Note: Uses differentiable operations (mean instead of median, soft mask).
Reference
[1] https://github.com/QiuJueqin/fast-openISP/blob/master/modules/dpc.py
Initialize dead pixel correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
Threshold for detecting dead pixels (as fraction of max value). |
0.1
|
|
kernel_size
|
Size of the kernel for correction (must be odd). |
3
|
|
soft_blend
|
If True, use differentiable soft blending. If False, use hard threshold. |
True
|
|
temperature
|
Temperature for soft sigmoid blending (lower = sharper transition). |
0.01
|
Source code in deeplens/sensor/isp_modules/dead_pixel.py
forward
Dead Pixel Correction (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Tensor
|
Input bayer image [B, 1, H, W], data range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer_corrected |
Tensor
|
Corrected bayer image [B, 1, H, W]. |
Source code in deeplens/sensor/isp_modules/dead_pixel.py
reverse
Reverse dead pixel correction (identity).
Note: Dead pixel correction is a lossy operation that cannot be reversed. This returns the input unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Tensor
|
Input bayer image [B, 1, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer |
Tensor
|
Input unchanged. |
Source code in deeplens/sensor/isp_modules/dead_pixel.py
deeplens.sensor.isp_modules.Denoise
Bases: Module
Noise reduction (differentiable).
Applies denoising filters to reduce sensor noise in the image. Supports Gaussian filtering (differentiable) and bilateral filtering.
Note: Median filtering is NOT differentiable, so we use Gaussian or bilateral instead.
Initialize denoise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Noise reduction method: "gaussian", "bilateral", or None. |
'gaussian'
|
|
kernel_size
|
Size of the kernel (must be odd). |
3
|
|
sigma
|
Standard deviation for spatial Gaussian kernel. |
0.5
|
|
sigma_color
|
Standard deviation for color/intensity similarity (bilateral only). |
0.1
|
Source code in deeplens/sensor/isp_modules/denoise.py
forward
Apply denoise (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Tensor
|
Input tensor of shape [B, C, H, W], data range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_filtered |
Tensor
|
Denoised image, data range [0, 1]. |
Source code in deeplens/sensor/isp_modules/denoise.py
reverse
Reverse denoising (identity).
Note: Denoising is a lossy operation that cannot be reversed. This returns the input unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Tensor
|
Input tensor of shape [B, C, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img |
Tensor
|
Input unchanged. |
Source code in deeplens/sensor/isp_modules/denoise.py
deeplens.sensor.isp_modules.LensShadingCorrection
Bases: Module
Lens shading correction (LSC).
Corrects vignetting (darkening at edges/corners) caused by lens optical properties by applying a spatially-varying gain map.
Initialize lens shading correction module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shading_map
|
Pre-computed shading gain map of shape [H, W] or [1, 1, H, W]. If None, a radial falloff model is used. Default is None. |
None
|
|
strength
|
Strength of the correction (0-1). 0 = no correction, 1 = full. Default is 1.0. |
1.0
|
|
falloff_model
|
Model for computing gain map. Options: "radial", "polynomial". Only used if shading_map is None. Default is "radial". |
'radial'
|
Source code in deeplens/sensor/isp_modules/lens_shading.py
forward
Apply lens shading correction to remove vignetting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Input tensor of shape [B, C, H, W], data range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x_corrected |
Corrected tensor of shape [B, C, H, W]. |
Source code in deeplens/sensor/isp_modules/lens_shading.py
reverse
Reverse lens shading correction (add vignetting back).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Input tensor of shape [B, C, H, W], data range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x_vignetted |
Tensor with vignetting applied, shape [B, C, H, W]. |
Source code in deeplens/sensor/isp_modules/lens_shading.py
deeplens.sensor.isp_modules.AntiAliasingFilter
Bases: Module
Anti-Aliasing Filter (AAF).
Anti-aliasing filter is applied to raw Bayer data to reduce moiré patterns and aliasing artifacts before demosaicing.
Reference
[1] https://github.com/QiuJueqin/fast-openISP/blob/master/modules/aaf.py
Initialize the Anti-Aliasing Filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Filtering method. Options: "weighted_average", "gaussian", "none", or None. |
'weighted_average'
|
kernel_size
|
int
|
Size of the filter kernel (must be odd). |
3
|
Source code in deeplens/sensor/isp_modules/anti_alising.py
forward
Apply anti-aliasing filter to remove moiré pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Input tensor of shape [B, 1, H, W], data range [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
|
Filtered bayer tensor of same shape as input. |
Source code in deeplens/sensor/isp_modules/anti_alising.py
reverse
Reverse anti-aliasing filter (approximation).
Note: Anti-aliasing is a lossy operation, so perfect reversal is not possible. This returns the input unchanged as an approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Input tensor of shape [B, 1, H, W], data range [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
|
Input tensor unchanged. |
Source code in deeplens/sensor/isp_modules/anti_alising.py
deeplens.sensor.isp_modules.ColorSpaceConversion
Bases: Module
Color space conversion (CSC).
Color space conversion is a technique to convert the color space of the image.
Initialize color space conversion module.
Source code in deeplens/sensor/isp_modules/color_space.py
rgb_to_ycrcb
Convert RGB to YCrCb (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb_image
|
Input tensor of shape [B, 3, H, W] in RGB format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ycrcb_image |
Output tensor of shape [B, 3, H, W] in YCrCb format. |
Reference
[1] https://github.com/QiuJueqin/fast-openISP/blob/master/modules/csc.py
Source code in deeplens/sensor/isp_modules/color_space.py
ycrcb_to_rgb
Convert YCrCb to RGB (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ycrcb_image
|
Input tensor of shape [B, 3, H, W] in YCrCb format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb_image |
Output tensor of shape [B, 3, H, W] in RGB format. |
Source code in deeplens/sensor/isp_modules/color_space.py
forward
Convert between color spaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Input tensor of shape [B, 3, H, W]. |
required | |
conversion
|
Conversion direction, "rgb_to_ycrcb" or "ycrcb_to_rgb". |
'rgb_to_ycrcb'
|
Returns:
| Name | Type | Description |
|---|---|---|
converted_image |
Output tensor of shape [B, 3, H, W]. |
Source code in deeplens/sensor/isp_modules/color_space.py
reverse
Reverse color space conversion (YCrCb to RGB).
This is the inverse of the forward pass (which defaults to rgb_to_ycrcb).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Input tensor of shape [B, 3, H, W] in YCrCb format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb_image |
Output tensor of shape [B, 3, H, W] in RGB format. |