优化彩色图像

介绍

本教程旨在帮助您优化Zivid相机捕获的彩色图像的质量。我们将首先介绍如何使用获得良好颜色信息的基本工具:调整采集和颜色设置。然后我们将解决最常见的挑战(HDR中的光晕/过度饱和现象和颜色不一致性),并就如何克服这些问题提供我们的建议。

小技巧

Zivid 2+ 相机比 Zivid 2 相机具有更高的分辨率并采用了更好的去马赛克算法, 因此,Zivid 2+ 可以输出更高质量的 2D 图像。

调整采集设置

The quality of the color image depend on the Acquisition Settings(采集设置)- 2D. The acquisition settings should be adjusted to ensure the pixel values of interest are not close to the noise floor. It is also important to avoid pixel saturation in the image, especially in the regions of interest. A good rule of thumb is to ensure the pixel values of interest are as high as possible, while not being saturated. In other words, with RGB values close to, but not 255. This may leave some pixels saturated, but the pixels of interest will still be well exposed. In that case, make sure your image processing algorithm can handle some saturation. To learn how light intensity gets converted into pixel values, see 相机捕获中可检测到的光强度.

To optimize acquisition settings for your color image, you can use the 2D view and histogram in Zivid Studio, as seen below. Hovering the mouse cursor above the region of interest (red cross in the image) will display the pixel RGB values in the bottom left corner.

Pixel of interest

The RGB values of this particular pixel will be binned together with other pixels that have similar RGB values in the histogram view. As it can be seen in the image above, pixel (783, 526) has:

  • Red value of 224

  • Green value of 238

  • Blue value of 215

These RGB values indicate that this pixel resides within the upper right half of the histogram, and is thus considered a good pixel. However, we can also see from the histogram that there are many saturated pixels (RGB values 255) in the image, which indicates that some pixels are over-exposed.

小心

To use the histogram as a tool for adjusting acquisition settings, you must evaluate a single acquisition at a time with Color Mode set to UseFirstAcquisition or Automatic. Also, you must set Gamma and Color Balance gains to 1.0.

This is because the default Color Mode is Automatic, which is identical to ToneMapping for multi-acquisition HDR captures with differing acquisition settings. Tone mapping modifies pixel values. Gamma and Color Balance settings also modify pixel values.

While adjusting the acquisition settings to expose the image well, consider how different acquisition settings can impact the quality of the color image.

Exposure Time and Projector Brightness

Exposure time and projector brightness do not impact the color image quality. We recommend using the maximum projector brightness value, which allows for lower exposure times and thus faster 2D captures. This is assuming that your image is not saturated, as discussed above.

Aperture

Correct aperture values are key to avoiding blurry color images; see the figure below. A good rule of thumb is to use low f-number values, up to 4.0, if the working distance is within the optimal range. If the camera is outside the optimal range, try using higher f-number values, such as 5.6 or 8.0. For a more detailed explanation and guidance, see 焦深 and Depth of Focus Calculator.

Single acquisition capture with good aperture Single acquisition capture with good aperture
Single acquisition capture with bad aperture Single acquisition capture with bad aperture

备注

上面的图像是在最佳成像距离之外拍摄的,以强调大光圈值时的失焦效果,而在最佳范围内拍摄时,图像不会如此模糊。

Gain

我们建议使用较低的增益值,例如1-2,因为高增益值会增加图像噪声(粒度)水平,从而降低2D图像质量;见下图。

增益设置为1的单次采集捕获 增益设置为1的单次采集捕获
增益设置为16的单次采集捕获 增益设置为16的单次采集捕获

调整颜色设置

In addition to aperture and gain, the color image quality depends on Gamma, Color Balance, and Color Mode settings. This section aims to give insights into optimizing these settings to get desired color quality in the color image.

Gamma

相机对亮度的编码与人眼不同。人眼侧重于光谱的较暗端,相机则以线性比例编码亮度。为了补偿这种影响,gamma校正被应用于使图像变暗或变亮,使其更接近人类的感知。

Gamma值越低,场景会显得越亮。如果增加Gamma值,则场景会显得更暗。

使用 Gamma 设置为 0.6 拍摄的图像 使用 Gamma 设置为 0.6 拍摄的图像
使用 Gamma 设置为 1.3 拍摄的图像 使用 Gamma 设置为 1.3 拍摄的图像

是否需要gamma校正来优化图像质量用于机器视觉算法是有疑问的。尽管如此,它仍然可以帮助我们评估彩色图像质量的某些方面,例如焦点和颗粒/噪声水平。

有关示例的实现,请查看 Gamma校正。该教程展示了如何使用可配置的gamma校正捕获2D图像。

Color Balance(色彩平衡)

Zivid 2+ MR130、MR60 和 LR110 相机内置色彩平衡功能,因此强烈或非白色的环境光对彩色图像的 RGB 值影响甚微。因此,无需在这些相机型号上运行额外的色彩平衡算法。

下图显示了在不同环境光条件下使用 Zivid 2+ MR130 拍摄的二维彩色图像的细节。

300 LUX

1000 LUX

2000 LUX

3200K

2d_images_mr130_lux_kelvins

5000K

6500K

If you have one of the Zivid 2+ MR130, MR60, or LR110 cameras, you can skip the rest of this section. The remainder of the section is only valid for other Zivid camera models.

The color temperature of ambient light affects the appearance of the color image. There are two default color balance settings, with and without the projector. When projector brightness is set to 0 or off, the color balance is calibrated to 4500 K, typical in industrial environments. For projector brightness values above 0, the color balance is calibrated for the color temperature of the projector light. You can adjust the digital gain to red, green, and blue color channels to make the color image look natural. Below, you can see an image before and after balancing the color.

备注

Zivid相机的色彩平衡增益值范围在1.0到8.0之间。

一盒糖果的两张图片。左侧图像中的绿色太强。

Performing color balance can be beneficial in strong and varying ambient light conditions. For an implementation example, see 调整色彩平衡 tutorial. This tutorial shows how to balance the color of a 2D image by taking images of a white surface (a piece of paper, wall, or similar) in a loop.

Color Mode(颜色模式)

颜色模式设置控制了如何计算彩色图像。颜色模式设置可设为以下模式:

  • ToneMapping

  • Automatic

ToneMapping 功能使用了所有采集项来创建一个合并和标准化的彩色图像。对于多采集 HDR 捕获,捕获图像的动态范围通常高于 8 位彩色图像范围。色调映射将通过应用缩放因子将 HDR 颜色数据映射到 8 位颜色输出范围。色调映射还可用于单采集捕获,以将捕获的彩色图像标准化为完整的 8 位输出。使用 ToneMapping 时,如果您移动、添加或移除场景中的对象,颜色值在重复捕获中可能会不一致。

  • Automatic 是默认设置。

  • 在进行具有不同采集设置的多次采集HDR时, Automatic 等同于 ToneMapping

对于单次采集捕获,色调映射可用于将较暗的图像变亮。

将色彩模式设置为自动(Automatic)(即无色调映射)的单次采集 将色彩模式设置为自动(Automatic)(即无色调映射)的单次采集
将色彩模式设置为色调映射 (ToneMapping) 的单次采集 将色彩模式设置为色调映射 (ToneMapping) 的单次采集

对于多采集HDR,色调映射可用于将高动态范围颜色映射到更有限的动态输出范围。

在色彩模式设置为自动(无色调映射)的情况下,对三次 HDR 采集中的第一次进行单次采集 在色彩模式设置为自动(无色调映射)的情况下,对三次 HDR 采集中的第一次进行单次采集
在色彩模式设置为自动(无色调映射)的情况下,对三次 HDR 采集中的第二次进行单次采集 在色彩模式设置为自动(无色调映射)的情况下,对三次 HDR 采集中的第二次进行单次采集
在色彩模式设置为自动(无色调映射)的情况下,对三次 HDR 采集中的第三次进行单次采集 在色彩模式设置为自动(无色调映射)的情况下,对三次 HDR 采集中的第三次进行单次采集
Color Mode设置为ToneMapping或Automatic的具有三个采集项的HDR Color Mode设置为ToneMapping或Automatic的具有三个采集项的HDR

查看如何使用Zivid SDK配置数据处理的设置,包括Gamma、Color Balance和Color Mode:

跳转到源码

source

std::cout << "Configuring settings for capture:" << std::endl;
Zivid::Settings2D settings2D{
    Zivid::Settings2D::Sampling::Color::rgb,
    Zivid::Settings2D::Sampling::Pixel::all,

    Zivid::Settings2D::Processing::Color::Balance::Blue{ 1.0 },
    Zivid::Settings2D::Processing::Color::Balance::Green{ 1.0 },
    Zivid::Settings2D::Processing::Color::Balance::Red{ 1.0 },
    Zivid::Settings2D::Processing::Color::Gamma{ 1.0 },

    Zivid::Settings2D::Processing::Color::Experimental::Mode::automatic,
};

Zivid::Settings settings{
    Zivid::Settings::Color{ settings2D },

    Zivid::Settings::Engine::phase,

    Zivid::Settings::RegionOfInterest::Box::Enabled::yes,
    Zivid::Settings::RegionOfInterest::Box::PointO{ 1000, 1000, 1000 },
    Zivid::Settings::RegionOfInterest::Box::PointA{ 1000, -1000, 1000 },
    Zivid::Settings::RegionOfInterest::Box::PointB{ -1000, 1000, 1000 },
    Zivid::Settings::RegionOfInterest::Box::Extents{ -1000, 1000 },

    Zivid::Settings::RegionOfInterest::Depth::Enabled::yes,
    Zivid::Settings::RegionOfInterest::Depth::Range{ 200, 2000 },

    Zivid::Settings::Processing::Filters::Cluster::Removal::Enabled::yes,
    Zivid::Settings::Processing::Filters::Cluster::Removal::MaxNeighborDistance{ 10 },
    Zivid::Settings::Processing::Filters::Cluster::Removal::MinArea{ 100 },

    Zivid::Settings::Processing::Filters::Hole::Repair::Enabled::yes,
    Zivid::Settings::Processing::Filters::Hole::Repair::HoleSize{ 0.2 },
    Zivid::Settings::Processing::Filters::Hole::Repair::Strictness{ 1 },

    Zivid::Settings::Processing::Filters::Noise::Removal::Enabled::yes,
    Zivid::Settings::Processing::Filters::Noise::Removal::Threshold{ 7.0 },

    Zivid::Settings::Processing::Filters::Noise::Suppression::Enabled::yes,
    Zivid::Settings::Processing::Filters::Noise::Repair::Enabled::yes,

    Zivid::Settings::Processing::Filters::Outlier::Removal::Enabled::yes,
    Zivid::Settings::Processing::Filters::Outlier::Removal::Threshold{ 5.0 },

    Zivid::Settings::Processing::Filters::Reflection::Removal::Enabled::yes,
    Zivid::Settings::Processing::Filters::Reflection::Removal::Mode::global,

    Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Enabled::yes,
    Zivid::Settings::Processing::Filters::Smoothing::Gaussian::Sigma{ 1.5 },

    Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Enabled::yes,
    Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Correction::Strength{ 0.4 },

    Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Enabled::no,
    Zivid::Settings::Processing::Filters::Experimental::ContrastDistortion::Removal::Threshold{ 0.5 },

    Zivid::Settings::Processing::Resampling::Mode::upsample2x2,

    Zivid::Settings::Diagnostics::Enabled::no,
};

setSamplingPixel(settings, camera);
std::cout << settings << std::endl;
跳转到源码

源码

Console.WriteLine("Configuring settings for capture:");
var settings2D = new Zivid.NET.Settings2D()
{
    Sampling =
    {
        Color = Zivid.NET.Settings2D.SamplingGroup.ColorOption.Rgb,
        Pixel = Zivid.NET.Settings2D.SamplingGroup.PixelOption.All,
    },
    Processing =
    {
        Color =
        {
            Balance =
            {
                Blue = 1.0,
                Green = 1.0,
                Red = 1.0,
            },
            Gamma = 1.0,
            Experimental = { Mode = Zivid.NET.Settings2D.ProcessingGroup.ColorGroup.ExperimentalGroup.ModeOption.Automatic },
        },
    },
};
var settings = new Zivid.NET.Settings()
{
    Engine = Zivid.NET.Settings.EngineOption.Phase,

    RegionOfInterest =
    {
        Box = {
            Enabled = true,
            PointO = new Zivid.NET.PointXYZ{ x = 1000, y = 1000, z = 1000 },
            PointA = new Zivid.NET.PointXYZ{ x = 1000, y = -1000, z = 1000 },
            PointB = new Zivid.NET.PointXYZ{ x = -1000, y = 1000, z = 1000 },
            Extents = new Zivid.NET.Range<double>(-1000, 1000),
        },
        Depth =
        {
            Enabled = true,
            Range = new Zivid.NET.Range<double>(200, 2000),
        },
    },
    Processing =
    {
        Filters =
        {
            Cluster =
            {
                Removal = { Enabled = true, MaxNeighborDistance = 10, MinArea = 100}
            },
            Hole =
            {
                Repair = { Enabled = true, HoleSize = 0.2, Strictness = 1 },
            },
            Noise =
            {
                Removal = { Enabled = true, Threshold = 7.0 },
                Suppression = { Enabled = true },
                Repair = { Enabled = true },
            },
            Outlier =
            {
                Removal = { Enabled = true, Threshold = 5.0 },
            },
            Reflection =
            {
                Removal = { Enabled = true, Mode = ReflectionFilterModeOption.Global },
            },
            Smoothing =
            {
                Gaussian = { Enabled = true, Sigma = 1.5 },
            },
            Experimental =
            {
                ContrastDistortion =
                {
                    Correction = { Enabled = true, Strength = 0.4 },
                    Removal = { Enabled = true, Threshold = 0.5 },
                },
            },
        },
        Resampling = { Mode = Zivid.NET.Settings.ProcessingGroup.ResamplingGroup.ModeOption.Upsample2x2 },
    },
    Diagnostics = { Enabled = false },
};

settings.Color = settings2D;

SetSamplingPixel(ref settings, camera);
Console.WriteLine(settings);
跳转到源码

源码

print("Configuring settings for capture:")
settings_2d = zivid.Settings2D()

settings_2d.sampling.color = zivid.Settings2D.Sampling.Color.rgb
settings_2d.sampling.pixel = zivid.Settings2D.Sampling.Pixel.all

settings_2d.processing.color.balance.red = 1.0
settings_2d.processing.color.balance.blue = 1.0
settings_2d.processing.color.balance.green = 1.0
settings_2d.processing.color.gamma = 1.0

settings_2d.processing.color.experimental.mode = zivid.Settings2D.Processing.Color.Experimental.Mode.automatic

settings = zivid.Settings()
settings.engine = zivid.Settings.Engine.phase

settings.region_of_interest.box.enabled = True
settings.region_of_interest.box.point_o = [1000, 1000, 1000]
settings.region_of_interest.box.point_a = [1000, -1000, 1000]
settings.region_of_interest.box.point_b = [-1000, 1000, 1000]
settings.region_of_interest.box.extents = [-1000, 1000]

settings.region_of_interest.depth.enabled = True
settings.region_of_interest.depth.range = [200, 2000]

settings.processing.filters.cluster.removal.enabled = True
settings.processing.filters.cluster.removal.max_neighbor_distance = 10
settings.processing.filters.cluster.removal.min_area = 100

settings.processing.filters.hole.repair.enabled = True
settings.processing.filters.hole.repair.hole_size = 0.2
settings.processing.filters.hole.repair.strictness = 1

settings.processing.filters.noise.removal.enabled = True
settings.processing.filters.noise.removal.threshold = 7.0

settings.processing.filters.noise.suppression.enabled = True
settings.processing.filters.noise.repair.enabled = True

settings.processing.filters.outlier.removal.enabled = True
settings.processing.filters.outlier.removal.threshold = 5.0

settings.processing.filters.reflection.removal.enabled = True
settings.processing.filters.reflection.removal.mode = (
    zivid.Settings.Processing.Filters.Reflection.Removal.Mode.global_
)

settings.processing.filters.smoothing.gaussian.enabled = True
settings.processing.filters.smoothing.gaussian.sigma = 1.5

settings.processing.filters.experimental.contrast_distortion.correction.enabled = True
settings.processing.filters.experimental.contrast_distortion.correction.strength = 0.4

settings.processing.filters.experimental.contrast_distortion.removal.enabled = False
settings.processing.filters.experimental.contrast_distortion.removal.threshold = 0.5

settings.processing.resampling.mode = zivid.Settings.Processing.Resampling.Mode.upsample2x2

settings.diagnostics.enabled = False

settings.color = settings_2d

_set_sampling_pixel(settings, camera)
print(settings)

故障排除

如果您遇到任何与彩色图像有关的问题,请查看 视觉 故障排除文章。

进一步阅读

Continue to 处理高光和闪亮的物体.