Common Vision Blox 15.0
Loading...
Searching...
No Matches
Pixel Format Conversion - PFNC Formats and Bayer Conversion

PFNC Formats

The Pixel Format Naming Convention (PFNC) is a standardized scheme used in machine vision to name and describe pixel formats. It covers both 2D and 3D imaging data.

CVB follows this convention and provides convenient tools for converting between formats using the Cvb::PixelFormatConverter (C++), Stemmer.Cvb.PixelFormatConverter (.NET), and cvb.PixelFormatConverter (Python). Please note that while most formats are supported for conversion, they can only be converted to commonly used (displayable) formats.

For more general information about PFNC, refer to the official documentation.

Bayer Conversion

Bayer conversion is the process of transforming raw image data from a camera sensor that uses a Bayer filter into a full-color RGB image. Each pixel in the raw Bayer image records only one color (red, green, or blue), and the missing color values are estimated through a process called demosaicing, which reconstructs the complete color information for each pixel.

G R G R G R G R
B G B G B G B G
G R G R G R G R
B G B G B G B G
G R G R G R G R
B G B G B G B G
RGB RGB RGB RGB
RGB RGB RGB RGB
RGB RGB RGB RGB

With CVB, performing a Bayer-to-RGB conversion is straightforward using the Cvb::PixelFormatConverter (C++), Stemmer.Cvb.PixelFormatConverter (.NET), and cvb.PixelFormatConverter (Python). Example programs for Bayer conversion are provided in the section below.

#include <cvb/image.hpp>
#include <cvb/pixel_format_converter.hpp>
auto dstImage = Cvb::Image::FromPixelFormat(srcImage->Size(), Cvb::PfncFormat::RGB8);
auto converter = Cvb::PixelFormatConverter (Cvb::PfncFormat::BayerGR8, Cvb::PfncFormat::RGB8);
converter->Execute(*srcImage, *dstImage);
static std::unique_ptr< Image > FromPixelFormat(const Cvb::Size2D< int > &size, Cvb::PfncFormat format)

var dstImage = Image.FromPixelFormat(srcImage.Size, PfncFormat.RGB8);
var converter = PixelFormatConverter.Create(PfncFormat.BayerGR8, PfncFormat.RGB8);
converter.Execute(srcImage, dstImage);
static Image FromPixelFormat(Size2D size, PfncFormat pixelFormat)
void Execute(T sourceObject, Image destinationObject)
static PixelFormatConverter Create(PfncFormat sourceFormat, PfncFormat destinationFormat)

import cvb
dst_image = cvb.Image.from_pixel_format(src_image.size, cvb.PfncFormat.RGB8)
converter = cvb.PixelFormatConverter(cvb.PfncFormat.BayerGR8, cvb.PfncFormat.RGB8)
converter.execute(src_image, dst_image)
cvb.Image from_pixel_format(cvb.Size2D size, int format)

Note
A CVB color image always presents the red plane first and the blue plane last, even if the memory layout is BGR. Bayer images only have one plane and are equal to mono images in respect of memory access.

Unpacking

Unpacking packed pixel formats works the same way as bayer conversion. As packed formats cannot be represented as CVB image the converter can also handle PFNCBuffers as input. You can get PFNCBuffers from acquired Composites.

Examples

Note
To view a CVB image as a PFNC buffer see the following example: Reinterpreting Images as PFNC Buffer.

Example programs for PFNC format conversion, such as a Bayer conversion, are provided in C++, .NET and, Python. You can find them in your CVB setup under %cvb%Tutorial/Image Manager or in the online documentation, as listed in the table below:

Link to Example Location in your CVB Setup
C++ PixelFormatConversion %cvb%Tutorial/Image Manager/Cvb++/CppPixelFormatConversion
.NET PixelFormatConversion %cvb%Tutorial/Image Manager/Cvb.Net/PixelFormatConversion
Python PixelFormatConversion %cvb%Tutorial/Image Manager/CVBpy/PixelFormatConversion