Skip to main content

Crate demosaic

Crate demosaic 

Source
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 averaging
  • Mhc — Malvar-He-Cutler gradient-corrected interpolation
  • Ppg — Patterned Pixel Grouping
  • Ahd — Adaptive Homogeneity-Directed
  • Vng — Variable Number of Gradients

Quad Bayer:

  • Bilinear — 5x5 neighbor averaging
  • QuadPpg — gradient-based direct demosaicing
  • demosaic_quad_binned — 2x2 binning + any Bayer algorithm (half resolution)
  • remosaic — convert to standard Bayer, then use any Bayer algorithm

X-Trans:

§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.
BayerAlgorithm
Bayer-only demosaicing algorithm, used as inner algorithm for Quad Bayer binning.
Channel
Color channel in a CFA pattern.
DemosaicError
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.