Sensor
The end2end_imaging.sensor module provides differentiable sensor models with noise simulation and a full image signal processing (ISP) pipeline.
Sensor Models
Base sensor class shared by all sensor models.
end2end_imaging.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
RGBSensor.
Attributes:
| Name | Type | Description |
|---|---|---|
size |
tuple
|
Physical sensor size (W, H) [mm]. |
res |
tuple
|
Pixel resolution (W, H). |
pixel_size |
float
|
Physical pixel pitch [mm], |
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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/sensor.py
to
Move the sensor and its ISP pipeline to a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Target device (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Sensor |
This sensor instance, for call chaining. |
Source code in end2endimaging-src/end2end_imaging/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 |
Source code in end2endimaging-src/end2end_imaging/sensor/sensor.py
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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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).
end2end_imaging.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
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). |
readnoise_std |
float
|
Read-noise standard deviation [DN]. |
shotnoise_std_alpha |
float
|
Shot-noise scale coefficient. |
shotnoise_std_beta |
float
|
Shot-noise offset coefficient. |
isp |
InvertibleISP
|
Embedded invertible ISP pipeline. |
Initialize an RGB sensor with a physics-based noise model and invertible ISP.
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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/rgb_sensor.py
to
Move the sensor, ISP pipeline, and spectral-response tensors to a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Target device (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RGBSensor |
This sensor instance, for call chaining. |
Source code in end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/rgb_sensor.py
Monochrome sensor without color filter array.
end2end_imaging.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.
Initialize a monochrome sensor.
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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/mono_sensor.py
to
Move the sensor, its ISP pipeline, and spectral response to a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Target device (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MonoSensor |
This sensor instance, for call chaining. |
Source code in end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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_noisy |
N-bit noisy image, (B, C, H, W), range [0, 2**bit - 1] |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any ISO value exceeds 800, since the noise model is only calibrated for low ISO (<= 800). |
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 end2endimaging-src/end2end_imaging/sensor/mono_sensor.py
ISP Pipeline
The full, differentiable image signal processing pipeline that chains the modules below. RGBSensor uses it to turn raw sensor readings into an sRGB image, and it is invertible to reconstruct raw from sRGB.
end2end_imaging.sensor.isp_modules.isp.InvertibleISP
InvertibleISP(bit=10, black_level=64, bayer_pattern='rggb', white_balance=(2.0, 1.0, 1.8), color_matrix=None, gamma_param=2.2)
Bases: Module
Invertible and differentiable Bayer-sRGB ISP pipeline.
Reference
[1] Architectural Analysis of a Baseline ISP Pipeline. https://link.springer.com/chapter/10.1007/978-94-017-9987-4_2. (page 23, 50)
Initialize the invertible ISP pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bit
|
int
|
Bit depth of the input bayer image. Default 10. |
10
|
black_level
|
float
|
Black level value to subtract. Default 64. |
64
|
bayer_pattern
|
str
|
Bayer pattern of the input. Default "rggb". |
'rggb'
|
white_balance
|
tuple
|
Manual white balance gains (R, G, B). Default (2.0, 1.0, 1.8). |
(2.0, 1.0, 1.8)
|
color_matrix
|
optional
|
Color correction matrix. If None, the ColorCorrectionMatrix module uses its default. |
None
|
gamma_param
|
float
|
Gamma parameter. Default 2.2. |
2.2
|
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/isp.py
forward
A basic differentiable and invertible ISP pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer_nbit
|
Input tensor of shape [B, 1, H, W], data range [~black_level, 2^bit-1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb |
Output tensor of shape [B, 3, H, W], data range [0, 1]. |
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/isp.py
reverse
Inverse ISP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Input tensor of shape [B, 3, H, W], data range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bayer_Nbit |
Output tensor of shape [B, 1, H, W], data range [~black_level, 2^bit-1]. |
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/isp.py
ISP Modules
Individual image signal processing stages used inside RGBSensor. Each module is a torch.nn.Module.
end2end_imaging.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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/black_level.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/sensor/isp_modules/white_balance.py
sample_augmentation
Sample augmentation for synthetic data generation.
Perturbs the white balance gains with Gaussian noise, caching the original gains on first call so they can be restored later.
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/white_balance.py
reset_augmentation
Reset augmentation for evaluation by restoring the original gains.
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. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If awb_method is not "gray_world" or "manual". |
Source code in end2endimaging-src/end2end_imaging/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. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If awb_method is not "gray_world" or "manual". |
Source code in end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/white_balance.py
safe_reverse_awb
Inverse auto white balance with highlight-safe gains.
Applies inverse white balance gains while attenuating the correction in bright (near-saturated) regions to avoid pushing highlights out of range.
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, same shape as input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If img is not 3- or 4-dimensional. |
Reference
https://github.com/google-research/google-research/blob/master/unprocessing/unprocess.py#L92C1-L102C28
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/white_balance.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/sensor/isp_modules/demosaic.py
forward
Demosaic a Bayer pattern image to RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bayer
|
Input tensor of shape [1, H, W] or [B, 1, H, W]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
raw_rgb |
Output tensor of shape [3, H, W] or [B, 3, H, W], matching the dimensionality of the input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in end2endimaging-src/end2end_imaging/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]. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input does not have 3 or 4 dimensions, or if the channel dimension is not 3. |
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/demosaic.py
end2end_imaging.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 as a list of shape [4, 3] or [3, 3] (a [3, 3] matrix is padded with a zero bias row to [4, 3]). If None (default), an identity matrix with zero bias is used. 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
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If ccm_matrix is neither None nor a list. |
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 end2endimaging-src/end2end_imaging/sensor/isp_modules/color_matrix.py
sample_augmentation
Sample augmentation for synthetic data generation.
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/color_matrix.py
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 end2endimaging-src/end2end_imaging/sensor/isp_modules/color_matrix.py
reverse
Inverse color correction matrix. Convert sensor color space to RGB image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Input tensor of shape [B, 3, H, W] in sensor color space. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
img_original |
RGB image of shape [B, 3, H, W], clamped to [0, 1]. |
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/color_matrix.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/sensor/isp_modules/gamma_correction.py
sample_augmentation
Sample augmentation for synthetic data generation.
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/gamma_correction.py
reset_augmentation
Reset augmentation for evaluation.
No-op if no augmentation has been sampled yet, in which case
gamma_param already holds the original value.
Source code in end2endimaging-src/end2end_imaging/sensor/isp_modules/gamma_correction.py
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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/gamma_correction.py
end2end_imaging.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
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/tone_mapping.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/dead_pixel.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/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 of shape [B, C, H, W], data range [0, 1]. If the method is None or "none", the input is returned unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/denoise.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/lens_shading.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/sensor/isp_modules/anti_alising.py
end2end_imaging.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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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 end2endimaging-src/end2end_imaging/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]. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If conversion is not "rgb_to_ycrcb" or "ycrcb_to_rgb". |
Source code in end2endimaging-src/end2end_imaging/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. |