IDS Peak comfortSDK, genericSDK, IPL, and AFL developer manuals are external documents. Please contact us if you need them.
Querying the color correction matrix of the camera
The camera provides its color correction values via the XML tree. The correction can be done either by the camera itself or in IDS peak. This depends on where color calculation (debayering) is done, because color correction has to be done after color calculation.
The values (double) of the 3x3 matrix are named as follows:
gain_0_0
|
gain_0_1
|
gain_0_2
|
gain_1_0
|
gain_1_1
|
gain_1_2
|
gain_2_0
|
gain_2_1
|
gain_2_2
|
You can choose a predefined matrix or a user-defined matrix via ColorCorrectionMatrixValueSelector.
|
You must stop image acquisition if you want to change the enumeration nodes.
|
comfortC
|
peak_status status = PEAK_STATUS_SUCCESS;
status = peak_ColorCorrection_Mode_Set(hCam, PEAK_COLOR_CORRECTION_MODE_HQ);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
peak_matrix colorCorrectionMatrix;
status = peak_ColorCorrection_Matrix_Get(hCam, &colorCorrectionMatrix);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
|
genericC++
|
// Set the color correction matrix selector to the predefined HQ matrix
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrix")->SetCurrentEntry("HQ");
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain00");
auto gain_0_0 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain01");
auto gain_0_1 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain02");
auto gain_0_2 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain10");
auto gain_1_0 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain11");
auto gain_1_1 = nodemapRemoteDevice->FindNode<peak::peak::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain12");
auto gain_1_2 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain20");
auto gain_2_0 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain21");
auto gain_2_1 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain22");
auto gain_2_2 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
|
Setting any color correction matrix in the camera
comfortC
|
peak_status status = PEAK_STATUS_SUCCESS;
status = peak_ColorCorrection_Mode_Set(hCam, PEAK_COLOR_CORRECTION_MODE_USER_1);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
peak_matrix m;
m.elementArray[0][0] = 2; m.elementArray[0][1] = 1; m.elementArray[0][2] = 1;
m.elementArray[1][0] = 1; m.elementArray[1][1] = 2; m.elementArray[1][2] = 1;
m.elementArray[2][0] = 1; m.elementArray[2][1] = 1; m.elementArray[2][2] = 2;
status = peak_ColorCorrection_Matrix_Set(hCam, m);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
|
genericC++
|
// Set the color correction matrix selector to Custom0
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrix")->SetCurrentEntry("Custom0");
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain00");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(1);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain01");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(0);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain02");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(0);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain10");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(0);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain11");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(1);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain12");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(0);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain20");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(0);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain21");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(0);
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain22");
nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->SetValue(1);
|
Activating or deactivating color correction in the camera
comfortC
|
peak_status status = PEAK_STATUS_SUCCESS;
status = peak_ColorCorrection_Enable(hCam, PEAK_TRUE);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
status = peak_ColorCorrection_Enable(hCam, PEAK_FALSE);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
|
genericC++
|
// Disable color correction
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMode")->SetCurrentEntry("Off");
// Enable color correction if matching pixel format is set
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMode")->SetCurrentEntry("Auto");
|
Color correction in IDS peak IPL
When using a Bayer format with color calculation in IDS peak IPL (host software), the color correction must be performed afterwards in IDS peak IPL as well. You can read out the HQ matrix as described above and then pass it to the ColorCorrector in IDS peak IPL. For correction, pass the image to be corrected to the ColorCorrector.
comfortC
|
peak_status status = PEAK_STATUS_SUCCESS;
peak_matrix m;
status = peak_IPL_ColorCorrection_Matrix_Get(hCam, &m);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
status = peak_IPL_ColorCorrection_Matrix_Set(hCam, m);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
|
comfortC
|
peak_status status = PEAK_STATUS_SUCCESS;
status = peak_IPL_ColorCorrection_Enable(hCam, PEAK_TRUE);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
status = peak_IPL_ColorCorrection_Enable(hCam, PEAK_FALSE);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
|
genericC++
|
peak::ipl::ColorCorrector m_colorCorrectorIPL;
auto colorCorrectionFactors = peak::ipl::ColorCorrectionFactors(gain_0_0, gain_0_1, gain_0_2,
gain_1_0, gain_1_1, gain_1_2,
gain_2_0, gain_2_1, gain_2_2);
m_colorCorrectorIPL.SetColorCorrectionFactors(colorCorrectionFactors);
|
genericC++
|
// Correct original image
m_colorCorrectorIPL.ProcessInPlace(image);
// Correct and return new image
auto image2 = m_colorCorrectorIPL.Process(image);
|
Complete example
peak_status status = PEAK_STATUS_SUCCESS;
peak_matrix m;
m.elementArray[0][0] = 2; m.elementArray[0][1] = 1; m.elementArray[0][2] = 1;
m.elementArray[1][0] = 1; m.elementArray[1][1] = 2; m.elementArray[1][2] = 1;
m.elementArray[2][0] = 1; m.elementArray[2][1] = 1; m.elementArray[2][2] = 2;
status = peak_IPL_ColorCorrection_Matrix_Set(hCam, m);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
status = peak_IPL_ColorCorrection_Enable(hCam, PEAK_TRUE);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
peak_frame_handle hFrame;
peak_frame_handle hResultFrame;
while (running)
{
status = peak_Acquisition_WaitForFrame(hCam, 5000, &hFrame);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
status = peak_IPL_ProcessFrame(hCam, hFrame, &hResultFrame);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
// release original image
status = peak_Frame_Release(hCam, hFrame);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
// do something with the color corrected image
// release converted image
status = peak_Frame_Release(hCam, hResultFrame);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
}
|
peak::ipl::ColorCorrector m_colorCorrectorIPL;
try
{
// Set the color correction matrix selector to the predefined HQ matrix
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrix")->SetCurrentEntry("HQ");
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain00");
auto gain_0_0 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain01");
auto gain_0_1 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain02");
auto gain_0_2 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain10");
auto gain_1_0 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain11");
auto gain_1_1 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain12");
auto gain_1_2 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain20");
auto gain_2_0 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain21");
auto gain_2_1 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
nodemapRemoteDevice->FindNode<peak::core::nodes::EnumerationNode>("ColorCorrectionMatrixValueSelector")->SetCurrentEntry("Gain22");
auto gain_2_2 = nodemapRemoteDevice->FindNode<peak::core::nodes::FloatNode>("ColorCorrectionMatrixValue")->Value();
auto colorCorrectionFactors = peak::ipl::ColorCorrectionFactors(gain_0_0, gain_0_1, gain_0_2,
gain_1_0, gain_1_1, gain_1_2,
gain_2_0, gain_2_1, gain_2_2);
m_colorCorrectorIPL.SetColorCorrectionFactors(colorCorrectionFactors);
}
catch (const std::exception& e)
{
// ...
}
// ... Start acquisition ...
while (m_running)
{
try
{
// Get buffer from device's DataStream. Wait 5000 ms. The buffer is automatically locked until it is queued again.
const auto buffer = m_dataStream->WaitForFinishedBuffer(5000);
// Create IDS peak IPL image from buffer
const auto image = peak::BufferTo<peak::ipl::Image>(buffer);
// Create IDS peak IPL image for debayering and convert it to RGBa8 format
auto imageProcessed = image.ConvertTo(peak::ipl::PixelFormatName::BGRa8, peak::ipl::ConversionMode::Fast);
// Queue buffer again
m_dataStream->QueueBuffer(buffer);
// Apply color correction
m_colorCorrectorIPL.ProcessInPlace(imageProcessed);
}
catch (const std::exception& e)
{
// ...
}
}
|
var m_colorCorrectorIPL = new peak.ipl.ColorCorrector();
try
{
// Set the color correction matrix selector to the predefined HQ matrix
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrix").SetCurrentEntry("HQ");
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain00");
var gain_0_0 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain01");
var gain_0_1 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain02");
var gain_0_2 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain10");
var gain_1_0 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain11");
var gain_1_1 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain12");
var gain_1_2 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain20");
var gain_2_0 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain21");
var gain_2_1 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
nodeMapRemoteDevice.FindNode<peak.core.nodes.EnumerationNode>("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain22");
var gain_2_2 = nodeMapRemoteDevice.FindNode<peak.core.nodes.FloatNode>("ColorCorrectionMatrixValue").Value();
var colorCorrectionFactors = new peak.ipl.ColorCorrectionFactors((float)gain_0_0, (float)gain_0_1, (float)gain_0_2,
(float)gain_1_0, (float)gain_1_1, (float)gain_1_2,
(float)gain_2_0, (float)gain_2_1, (float)gain_2_2);
m_colorCorrectorIPL.SetColorCorrectionFactors(colorCorrectionFactors);
}
catch (Exception e)
{
// ...
}
// ... Start acquisition ...
while (m_running)
{
try
{
// Get buffer from device's DataStream. Wait 5000 ms. The buffer is automatically locked until it is queued again.
var buffer = m_dataStream.WaitForFinishedBuffer(5000);
// Create IDS peak IPL image from buffer
var image = new peak.ipl.Image((peak.ipl.PixelFormatName)buffer.PixelFormat(), buffer.BasePtr(),
buffer.Size(), buffer.Width(), buffer.Height(), buffer.Timestamp_ns());
// Create IDS peak IPL image for debayering and convert it to RGBa8 format
var imageProcessed = image.ConvertTo(peak.ipl.PixelFormatName.BGRa8, peak.ipl.ConversionMode.Fast);
// Queue buffer again
m_dataStream.QueueBuffer(buffer);
// Apply color correction
m_colorCorrectorIPL.ProcessInPlace(imageProcessed);
}
catch (Exception e)
{
// ...
}
}
|
m_color_corrector_ipl = ids_peak_ipl.ColorCorrector()
try:
# Set the color correction matrix selector to the predefined HQ matrix
node_map_remote_device.FindNode("ColorCorrectionMatrix").SetCurrentEntry("HQ")
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain00")
gain_0_0 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain01")
gain_0_1 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain02")
gain_0_2 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain10")
gain_1_0 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain11")
gain_1_1 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain12")
gain_1_2 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain20")
gain_2_0 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain21")
gain_2_1 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
node_map_remote_device.FindNode("ColorCorrectionMatrixValueSelector").SetCurrentEntry("Gain22")
gain_2_2 = node_map_remote_device.FindNode("ColorCorrectionMatrixValue").Value()
color_correction_factors = ids_peak_ipl.ColorCorrectionFactors(gain_0_0, gain_0_1, gain_0_2,
gain_1_0, gain_1_1, gain_1_2,
gain_2_0, gain_2_1, gain_2_2)
m_color_corrector_ipl.SetColorCorrectionFactors(color_correction_factors)
except Exception as e:
# ...
str_error = str(e)
# ... Start acquisition ...
while m_running:
try:
# Get buffer from device's DataStream. Wait 5000 ms. The buffer is automatically locked until it is queued again.
buffer = m_data_stream.WaitForFinishedBuffer(5000)
# Create IDS peak IPL image from buffer
image = ids_peak_ipl.Image.CreateFromSizeAndBuffer(
buffer.PixelFormat(),
buffer.BasePtr(),
buffer.Size(),
buffer.Width(),
buffer.Height()
)
# Create IDS peak IPL image for debayering and convert it to RGBa8 format
image_processed = image.ConvertTo(ids_peak_ipl.PixelFormatName_BGRa8, ids_peak_ipl.ConversionMode_Fast)
# Queue buffer again
m_data_stream.QueueBuffer(buffer)
# Apply color correction
m_color_corrector_ipl.ProcessInPlace(image_processed)
except Exception as e:
# ...
str_error = str(e)
|