Skip to content

Commit

Permalink
[feat]IBA:demosaic add X-Trans demosaicing (#4579)
Browse files Browse the repository at this point in the history
Implements X-Trans pattern demosaicing using a simple bilinear
algorithm. Adds the Xtrans pattern layout to the ImageBuf attributes in
the raw reader plugin.

I have implemented unit tests in imagebufalgo_test.cpp which cover all
permutations of the Bayer and X-Trans layouts, as the X-Trans pattern is
a bit too complicated to generate using oiiotool.

---------

Signed-off-by: Anton Dukhovnikov <[email protected]>
  • Loading branch information
antond-weta authored Jan 14, 2025
1 parent 3baab41 commit dc409d8
Show file tree
Hide file tree
Showing 7 changed files with 1,181 additions and 226 deletions.
14 changes: 9 additions & 5 deletions src/doc/oiiotool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4212,13 +4212,17 @@ current top image.
Optional appended modifiers include:

`pattern=` *name*
sensor pattern. Currently supported patterns: "bayer"
sensor pattern. Currently supported patterns: "bayer", "xtrans".
`layout=` *name*
photosite order of the specified pattern. For layouts of the Bayer
pattern supported: "RGGB", "GRBG", "GBRG", "BGGR".
photosite order of the specified pattern. The default value is "RGGB"
for Bayer, and "GRBGBR BGGRGG RGGBGG GBRGRB RGGBGG BGGRGG" for X-Trans.
`algorithm=` *name*
the name of the algorithm to use: "linear"(simple bilinear demosaicing),
"MHC"(Malvar-He-Cutler algorithm)
the name of the algorithm to use.
The Bayer-pattern algorithms:
- "linear"(simple bilinear demosaicing),
- "MHC"(Malvar-He-Cutler algorithm).
The X-Trans-pattern algorithms:
- "linear"(simple bilinear demosaicing).
`white-balance=` *v1,v2,v3...*
optional white balance weights, can contain either three (R,G,B) or four
(R,G1,B,G2) values. The order of the white balance multipliers is as
Expand Down
5 changes: 3 additions & 2 deletions src/doc/pythonbindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3701,9 +3701,10 @@ Color manipulation
bool ImageBufAlgo.demosaic (dst, src, pattern="", algorithm="", layout="", white_balance=py::none(), roi=ROI.All, nthreads=0)
Demosaic a raw digital camera image.
`demosaic` can currently process Bayer pattern images (pattern="bayer")
`demosaic` can currently process Bayer-pattern images (pattern="bayer")
using two algorithms: "linear" (simple bilinear demosaicing), and "MHC"
(Malvar-He-Cutler algorithm). The optional white_balance parameter can take
(Malvar-He-Cutler algorithm); or X-Trans-pattern images (pattern="xtrans")
using "linear" algorithm. The optional white_balance parameter can take
a tuple of three (R,G,B), or four (R,G1,B,G2) values. The order of the
white balance multipliers is as specified, it does not depend on the matrix
layout.
Expand Down
11 changes: 8 additions & 3 deletions src/include/OpenImageIO/imagebufalgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,9 @@ bool OIIO_API repremult (ImageBuf &dst, const ImageBuf &src,
///
/// - "pattern" : string (default: "bayer")
///
/// The type of image sensor color filter array. Currently only the Bayer-pattern images are supported.
/// The type of image sensor color filter array. Currently suported patterns:
/// - `bayer` - Bayer-pattern image.
/// - `xtrans` - X-Trans-pattern image.
///
/// - "algorithm" : string (default: "linear")
///
Expand All @@ -2174,11 +2176,14 @@ bool OIIO_API repremult (ImageBuf &dst, const ImageBuf &src,
/// - `MHC` - Malvar-He-Cutler linear demosaicing algorithm. Slower than `linear`, but produces
/// significantly better results.
///
/// - "layout" : string (default: "RGGB")
/// The following algorithms are supported for X-Trans-pattern images:
/// - `linear` - simple linear demosaicing. Fast, but can produce artefacts along sharp edges.
///
/// - "layout" : string (default: "RGGB" for Bayer, "GRBGBR BGGRGG RGGBGG GBRGRB RGGBGG BGGRGG" for X-Trans)
///
/// The order the color filter array elements are arranged in, pattern-specific.
///
/// - "white-balance" : float[3] or float[4] (default: {1.0, 1.0, 1.0, 1.0})
/// - "white-balance" : float[3] or float[4], (default: {1.0, 1.0, 1.0, 1.0})
///
/// Optional white-balancing weights. Can contain either three (R,G,B), or four (R,G1,B,G2) values.
/// The order of the white balance multipliers does not depend on the matrix layout.
Expand Down
Loading

0 comments on commit dc409d8

Please sign in to comment.