kill sharpness softly – bayer filtering in nuke

Finally, it’s time to start posting stuff on my blog. I plan to share relevant knowledge about rendering and compositing here. I will also upload nuke gizmos and all kinds of scripts I created which have proven to be useful in production.

Being confronted with combining CG elements and digitally recorded footage I figured that it would be helpful to apply the processing of a digital cameras sensor to those elements. Many digital cameras (like the Arri Alexa) use single-bayer sensors that are composed of 2×2 arrays of photosites, each site being sensitive to either red, green and blue wavelengths. Since the human eye is mainly sensitive to the green spectrum there are twice as many photosites to record this spectrum than for red and blue wavelenghts in order to achieve a denser sampling for this important (because of its high contribution to luminance perception) channel. In order to convert the raw output from the sensor to a visually pleasing image the pattern needs to be de-bayered by filling the gaps in each color channel caused by the bayer pattern via interpolation.

So i put together a rough version of a bayer matrix filter as a nuke gizmo. In a nutshell, what it does is reformatting the CG input to a desired sensor resolution, applies a bayer pattern to it, filters it appropriately and reformats it back to the desired output resolution. Currently the filtering is performed using seperate matrix nodes on each color channel which seems to lead to pleasing results, but since there are different approaches to de-bayering I would really welcome any comments on how to improve it or implement different options. Applying this filter will result in a softer image in order to fight the uber-sharpness of CGi (I would recommend using a sampling filter like ‘box’ in your render application so the image doesn’t end up too soft) and produce nice, subtle color fringes. I also found that applying grain directly to the bayer pattern in sensor resolution produces quite nice grain-patterns that seem closer to the output of a digital sensor.


(left) the unfiltered CGi, (middle) bayer matrix applied at sensor resolution,  (right) de-bayered output

The intensity of the fringes can be controlled with the ratio between sensor and output format. In the image below you can see a 400% magnification of the filter at 1, 1.5 and 1.78 ratio (output format/sensor format).


If you have a lot of time you could even render the image directly at sensor resolution (usually about 1,5x larger than the cameras output resolution in order to compensate for the loss of detail caused by interpolation).

Edit: I forgot to mention that you’ll need another of my gizmos called n_grain to use n_bayer. It adds a few functionalities to nukes default grain, i will post a detailed description soon.

download here

download here

2 thoughts on “kill sharpness softly – bayer filtering in nuke

Leave a Reply

Your email address will not be published. Required fields are marked *