...
The Lenscal DLL provides functions to quickly find lens correction register settings that will best correct the image brightness and color shading distortion caused by the camera's optical system. For sensors with phase detect auto focus (PDAF), this includes the spacial calibration as well.
The library supports all Bayer sensors with built-in lens correction, including SOC sensors.
...
The input to the calibration is an image of a flat, gray field. The output is a list of the lens correction registers and their values. To get a good calibration requires careful setup of the camera system under test and correct use of the Lenscal functions and their parameters. Contact your Aptina ON Semiconductor field application engineer for assistance.
Two kinds of lens correction circuits are in use on Aptina ON Semiconductor sensors, what I'll call the orthogonal type and the polynomial type. The orthogonal type uses sets of horizontal and vertical gain curves added together to create a two-dimensional gain. The polynomial type uses a two-dimensional polynomial function. The calibration algorithms and parameters are different for each. The orthogonal type sensors are MT9D111 (SOC2010), MT9D112 (SOC2020), MT9D012 (A-2020). All others are polynomial type.
...
The functions provided by the lenscal API are described below.
All library functions use the Windows standard calling convention. A C/C++ header file is provided.
Lenscal, and other Aptina ON Semiconductor tools, internally represent sensor registers by their symbolic name and depend on the sensor data (*.sdat, *.xsdat) files in the sensor_data directory to translate between the symbolic names and numerical register addresses on the sensors. In order for functions that load and save register settings to work, the sensor data file for the selected sensor must be on the computer (or a mapped drive). The lc_Create() function will search the normal installation directory for the sensor data file. As long as you have installed the software and the sensor data files with the installation wizards provided by AptinaON Semiconductor, everything is properly set up. The lc_Create2() function lets you provide the path or filename of a sensor data file if you have a custom configuration.
...
The returned pointer is provided so you may access the pixel values. Do not free the buffer. It will be freed automatically when the lc is destroyed or when you load a new image.
The Bayer data file may be in any of a variety of formats including raw binary, ASCII text, or monochrome PNG. The filename parameter may be NULL, in which case the function will fill the buffer with gray pixels.
The Bayer pattern codes are: 0 – GR/BG; 1 – RG/GB; 2 – BG/GR; 3 – GB/RG. Unless you are using some unusual register settings, the Bayer pattern should be 0. The lenscal library requires that the image be captured without flip or mirror modes. If the image was captued with flip or mirror on then you must re-orient the image before using it with lenscal.
The raw Bayer pixel data from an Aptina ON Semiconductor sensor has an offset (black pedestal) added to all pixels so there is a small blacker-than-black margin. This value must be subtracted off correctly in order for the calibration to be accurate. The black pedestal is programmed by a register on the sensor, but there is rarely any reason to change it from its default. Assuming the sensor black pedestal register has not been changed from the default and you have not altered the data, pass -1 for nBlack. If you have already subtracted the black pedestal pass 0. If you know that the black pedestal is some specific value, pass that value.
...
size_t | size | Set to sizeof(YCbCrParams), for forward compatibility. |
int | nCoeffCtrl | Determines the coefficients in the YCbCr to RGB conversion. Set this to match the COEFF_CONTROL or SELECT_601 bitfield on the SOC. |
int | nCb_offset, | These four parameters indicate the byte order of the YCbCr data. Aptina sensors Sensors default to Cb-Y-Cr-Y byte order, in which case set these parameters to 0, 1, 2, 3 respectively. |
int | nLumaBlack | The Y component value corresponding to black. nLumaBlack, nLumaWhite and nChromaRange are normailly either 16, 235, 224 for BTU-656 compatibility, or 0, 255, 255 for JPEG compatibility. |
int | nLumaWhite | The Y component value corresponding to White. |
int | nChromaRange | The valid range for Cb and Cr values. |
int | nC_excess | Set to 128 if the Cb and Cr components are unsigned. Set to 0 if they are 2's complement signed. Other values are undefined. This is almost always 128. |
...
Do not free the returned pointer if it is different from pOriginal. It will be freed when the lenscal object is destroyed or a new image is loaded.
The Bayer data must be either 8, 10 or 12 bits per pixel. If greater than 8 bits then each pixel must occupy the low bits of a 16-bit word, with little endian byte order. The function will subtract the black pedestal and convert the data to 12 bits per pixel. If the input is 8 bpp then the function will allocate a new buffer to hold the 12 bpp data, otherwise the transform will be done in place in your buffer.
RGB data must be 32 bits per pixel, 8 bits per color channel, B-G-R-x byte order.
The Bayer pattern codes are: 0 – GR/BG; 1 – RG/GB; 2 – BG/GR; 3 – GB/RG. Unless you are using some unusual register settings, the Bayer pattern should be 0. The lenscal library requires that the image be captured without flip or mirror modes. If the image was captued with flip or mirror on then you must re-orient the image before using it with lenscal.
The raw Bayer pixel data from an Aptina a sensor almost always has an offset (black pedestal) added to all pixels so there is a small blacker-than-black margin. The black pedestal must be subtracted off correctly in order for the calibration to be accurate. The black pedestal is programmed by a register on the sensor, but there is rarely any reason to change it from its default. For non-SOC sensors, assuming the sensor black pedestal register has not been changed from the default and you have not altered the data, pass -1 for nBlack. For SOCs, passing -1 will subtract a value appropriate for the sensor core of the SOC, however many SOCs have a second bypass mode called LC Bypass or PGA Bypass that subtracts the pedestal already. If the image data was captured in that mode then you must pass 0 for nBlack. If you have already subtracted the black pedestal pass 0. If you know that the black pedestal is some specific value, pass that value.
...
Definition:
int lc_FindSolution(void *lc, CalibParams *pCalibParams);
Summary:
Run a calibration algorithm on the input image to find good lens correction and PDAF spatial calibration register settings. You must provide an input image with lc_LoadInputImageFile() or lc_SetInputImage() prior to calling this function. To get the results use lc_DumpRegList() or lc_DumpRegFile().
Parameters:
...