Expand description
Demosaicing algorithms for Bayer, Quad Bayer, and X-Trans CFA sensors.
Takes single-channel CFA (color filter array) sensor data and reconstructs full-color RGB images. Supports 2x2 Bayer patterns (RGGB, BGGR, GRBG, GBRG), 4x4 Quad Bayer patterns, and 6x6 Fujifilm X-Trans patterns.
§Algorithms
Bayer:
Bilinear— simple neighbor averagingMhc— Malvar-He-Cutler gradient-corrected interpolationPpg— Patterned Pixel GroupingAhd— Adaptive Homogeneity-DirectedVng— Variable Number of Gradients
Quad Bayer:
Bilinear— 5x5 neighbor averagingQuadPpg— gradient-based direct demosaicingdemosaic_quad_binned— 2x2 binning + any Bayer algorithm (half resolution)remosaic— convert to standard Bayer, then use any Bayer algorithm
X-Trans:
Bilinear— simple neighbor averagingMarkesteijn1— 1-pass, 4 directionsMarkesteijn3— 3-pass with median refinementDht— Directional Homogeneity Test
§Example
use demosaic::{demosaic, Algorithm, CfaPattern};
let width = 4;
let height = 4;
let cfa = CfaPattern::bayer_rggb();
let input = vec![0.5f32; width * height];
let mut output = vec![0.0f32; 3 * width * height];
demosaic(&input, width, height, &cfa, Algorithm::Bilinear, &mut output).unwrap();
// output is planar CHW: [R plane, G plane, B plane]
let r_plane = &output[..width * height];
let g_plane = &output[width * height..2 * width * height];
let b_plane = &output[2 * width * height..];Structs§
- CfaPattern
- CFA pattern descriptor for both 2x2 Bayer and 6x6 X-Trans sensors.
Enums§
- Algorithm
- Demosaicing algorithm selection.
- Bayer
Algorithm - Bayer-only demosaicing algorithm, used as inner algorithm for Quad Bayer binning.
- Channel
- Color channel in a CFA pattern.
- Demosaic
Error - Errors returned by demosaicing operations.
Functions§
- bin2x2
- 2x2-bin a single-channel image by averaging each 2x2 block of pixels.
- demosaic
- Demosaic a single-channel CFA image to 3-channel RGB.
- demosaic_
interleaved - Demosaic a single-channel CFA image to interleaved 3-channel RGB.
- demosaic_
quad_ binned - Demosaic a Quad Bayer CFA image via 2x2 binning + standard Bayer demosaic.
- demosaic_
quad_ binned_ interleaved - Demosaic a Quad Bayer CFA image via binning to interleaved RGB output.
- interleaved_
to_ planar - Convert interleaved HWC layout to planar CHW between two buffers.
- planar_
to_ interleaved - Convert planar CHW layout to interleaved HWC between two buffers.
- remosaic
- Convert Quad Bayer raw data to Standard Bayer raw data at the same resolution.