Certain color cameras output image data in raw format, which is called Bayer format. This chapter discusses what is involved to transform this raw data into a real color format that can be displayed as a color image.
IC Imaging Control provides built-in functionality to debayer raw image data. There is a class DeBayerTransform that allows the debayering process to be controlled. The prerequisite to use this buit-in functionality is that the camera provides BY8 video formats that identify raw data in Bayer format. Some cameras provide only grayscale video formats (e.g. Y800, RGB8 etc.) but output color raw data when these formats are selected. This is possible because the color raw data in Bayer format consists of only one value per pixel (for detailed information about color raw data, please refer to the glossary of our website http://www.theimagingsource.com and search for Bayer camera ). In this case the debayering has to be done explicitly by using the DeBayer frame filter that can be loaded from the StdFilters.ftf module.
If a BY8 video format is selected, IC Imaging Control applies debayering to the image data. Call Grabber::getDeBayerTransform to get the object that controls the debayering. The method DeBayerTransform::isActive can be used to determine whether automatic debayering is active. For details on the debayer object, please refer to the DeBayerTransform reference. In order to switch off automatic debayering for the sink, you have to specify a bayer format, e.g. eBY8 or MEDIASUBTYPE_BY_8 when creating the sink. The only way to switch off automatic debayering for the display is to insert a frame filter in the display path that accepts only a bayer format at the input and outputs a monochrome format. All this filter has to do is to copy the data from the input to the output without any changes. The complete implementation of the filter looks like this:
//Filter that allows unconverted, raw Bayer data to be displayed. class CBayerRaw: public DShowLib::FrameFilterImpl<CBayerRaw> { public: CBayerRaw(){}; ~CBayerRaw(){}; static DShowLib::FilterInfo getStaticFilterInfo(); protected: virtual void getSupportedInputTypes( FrameTypeInfoArray& arr ) const { // Specify Bayer raw data as the only input format that will be accepted. arr.addFrameType( MEDIASUBTYPE_BY8 ); } virtual bool getTransformOutputTypes( const FrameTypeInfo& in_type, FrameTypeInfoArray& out_types ) const { // Specify Y800 as the output format. out_types.addFrameType( eY800, in_type.dim.cx, in_type.dim.cy ); return true; } virtual bool transform( const IFrame& src, IFrame& dest ) { // Just copy the image data without any changes. memcpy(dest.getPtr(),src.getPtr(), dest.getFrameType().buffersize); return true; } }; DShowLib::FilterInfo CBayerRaw::getStaticFilterInfo() { // Specify a symbolic name for the filter. static FilterInfo f = { L"BayerRaw" }; return f; }
If you now create an instance of the frame filter and insert it in the display path, you will see the raw image data in the live display:
// Create an instance of the frame filter. CBayerRaw bayerRaw; // Select a Bayer raw format. m_Grabber.setVideoFormat("BY 8 (640x480)"); // Insert the Frame filter in the display path. m_Grabber.setDisplayFrameFilters( &bayerRaw ); // ... do something here // As soon as you are done, remove the frame filter from the display path. m_Grabber.setDisplayFrameFilters( 0 ); // Now the filter object 'bayerRaw' may be destroyed.
For details on frame filters please refer to Frame Filters or Binarization.
In oder to apply debayering explicitly to the image stream, you have to load the DeBayer frame filter from the StdFilter.ftf module, insert it in to the desired segment of the image stream and setup the filters parameters to match the Bayer pattern and the desired algorithm:
// Load the DeBayer filter from the std_filters.ftf module. #ifdef _DEBUG smart_com<IFrameFilter> pFilter = FilterLoader::createFilter( "DeBayer", // Filter name. "stdfiltersd.ftf" ); // Module file. #else smart_com<IFrameFilter> pFilter = FilterLoader::createFilter( "DeBayer", // Filter name. "stdfilters.ftf" ); // Module file. #endif pFilter->setParameter( "Start Pattern", 2 /* eGR */ ); pFilter->setParameter( "Mode", 1 /* Bilinear */ ); m_Grabber.setDeviceFrameFilters( pFilter.get() );
For details on frame filters please refer to Frame Filters.