优化彩色图像
介绍
本教程旨在帮助您优化Zivid相机捕获的彩色图像的质量。我们将首先介绍如何使用获得良好颜色信息的基本工具:调整采集和颜色设置。然后我们将解决最常见的挑战(HDR中的光晕/过度饱和现象和颜色不一致性),并就如何克服这些问题提供我们的建议。
小技巧
Zivid 2+ 相机比 Zivid 2 相机具有更高的分辨率并采用了更好的去马赛克算法, 因此,Zivid 2+ 可以输出更高质量的 2D 图像。
调整采集设置
您从Zivid相机获得的彩色图像的质量取决于采集设置。本教程不包含如何调整曝光设置(曝光时间、光圈、亮度和增益)的组合以获得所需的动态范围, 调整合适的曝光以获取好的点云 一文涵盖这部分的内容。本教程侧重于调整影响彩色图像质量的特定采集设置。
曝光时间和投影仪亮度不会影响彩色图像的质量。另一方面,较高的光圈值是避免彩色图像模糊的关键。见下图。一个好的经验设定值是5.66或更高的f-值(更小的光圈)。如需了解更详细的说明,请参阅 焦深 和 Depth of Focus Calculator。
Single acquisition capture with aperture 10.37 |
Single acquisition capture with aperture 3.67 |
备注
上面的图像是在最佳成像距离之外拍摄的,以强调大光圈值时的失焦效果,而在最佳范围内拍摄时,图像不会如此模糊。
我们建议使用较低的增益值,例如1-2,因为高增益值会增加图像噪声(粒度)水平,从而降低2D图像质量;见下图。
Single acquisition capture with gain 1 |
Single acquisition capture with gain 16 |
我们通常通过调整采集设置以达到所需的动态范围和捕获时间,首要关注点是点云质量。通过这种方法,彩色图像质量是我们在给定捕获时间下针对3D质量优化的设置获得的。这种方法的缺点是它并不总是能够提供良好的彩色图像质量。然而事实情况是高质量的彩色图像(低模糊、低噪声和平衡照明)会产生高质量的点云。考虑到这一点,很明显,遵循上述微调的方法来提高彩色图像质量也会相应地提高3D质量。实现这一目标的关键是通过增加曝光时间和投影仪亮度值来补偿低增益和光圈(高 f 值)。
调整颜色设置
除了光圈和增益,彩色图像质量还取决于Gamma、Color Balance(白平衡)和Color Mode(颜色模式)等设置。本节旨在深入了解如何优化这些设置以在彩色图像中获得所需的颜色质量。有关颜色设置的更多信息,请参见此处: Filters(过滤器)。
Gamma
相机对亮度的编码与人眼不同。人眼侧重于光谱的较暗端,相机则以线性比例编码亮度。为了补偿这种影响,gamma校正被应用于使图像变暗或变亮,使其更接近人类的感知。
备注
Zivid相机的Gamma校正设定值范伟介于0.25和1.5之间。
Gamma值越低,场景会显得越亮。如果增加Gamma值,则场景会显得更暗。
Image captured with Gamma set to 0.6 |
Image captured with Gamma set to 1.3 |
是否需要gamma校正来优化图像质量用于机器视觉算法是有疑问的。尽管如此,它仍然可以帮助我们评估彩色图像质量的某些方面,例如焦点和颗粒/噪声水平。
有关示例的实现,请查看 Gamma校正。该教程展示了如何使用可配置的gamma校正捕获2D图像。
Color Balance(色彩平衡)
环境光的 color temperature (色温)会影响彩色图像的显示。您可以通过红色、绿色和蓝色通道的数字增益进行调整,使彩色图像看起来更加自然。如下图所示,您可以看到平衡颜色前后的图像的对比。如果您想自动为您的设置找到合适的色彩平衡参数,请查看 色彩平衡教程 。
备注
Zivid相机的色彩平衡增益值范围在1.0到8.0之间。
在强烈和变化的环境光下使用色彩平衡将是有益的。在没有投影仪或投影仪亮度值较低的情况下捕获图像时,调节色彩平衡是必要的。换句话说,即当环境光是相机看到的光的重要组成部分时。有两种默认的色彩平衡设置,对应投影仪开启和不开启的情况。当投影仪亮度设置为0或关闭时,色彩平衡校准为4500K,这是工业环境中的典型值。对于高于0的投影仪亮度值,会针对投影仪灯光的色温校准色彩平衡。
有关示例的实现,请参见 调整色彩平衡 教程。该教程展示了如何通过循环拍摄白色表面(一张纸、墙壁或类似物体)的图像来平衡2D图像的颜色。
Zivid 2+ MR130、M60 和 LR110 相机具有内置色彩平衡功能,因此强烈或非白色的环境光对彩色图像中的 RGB 值影响很小。这样就无需在这些相机型号上运行额外的色彩平衡算法。
下图显示了在不同环境光条件下使用 Zivid 2+ MR130 拍摄的二维彩色图像的细节。
300 LUX |
1000 LUX |
2000 LUX |
|
3200K |
|||
5000K |
|||
6500K |
Color Mode(颜色模式)
颜色模式设置控制了如何计算彩色图像。颜色模式设置可设为以下模式:
ToneMapping
Automatic
ToneMapping
功能使用了所有采集项来创建一个合并和标准化的彩色图像。对于多采集 HDR 捕获,捕获图像的动态范围通常高于 8 位彩色图像范围。色调映射将通过应用缩放因子将 HDR 颜色数据映射到 8 位颜色输出范围。色调映射还可用于单采集捕获,以将捕获的彩色图像标准化为完整的 8 位输出。使用 ToneMapping
时,如果您移动、添加或移除场景中的对象,颜色值在重复捕获中可能会不一致。
Automatic
是默认设置。在进行具有不同采集设置的多次采集HDR时,
Automatic
等同于ToneMapping
。
对于单次采集捕获,色调映射可用于将较暗的图像变亮。
Single acquisition capture with Color Mode set to |
Single acquisition capture with Color Mode set to |
对于多采集HDR,色调映射可用于将高动态范围颜色映射到更有限的动态输出范围。
Single acquisition capture of the first of three HDR acquisitions with Color Mode set to |
Single acquisition capture of the second of three HDR acquisitions with Color Mode set to |
Single acquisition capture of the third of three HDR acquisitions with Color Mode set to |
HDR with three acquisitions with Color Mode set to |
查看如何使用Zivid SDK配置数据处理的设置,包括Gamma、Color Balance和Color Mode:
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)
故障排除
如果您遇到任何与彩色图像有关的问题,请查看 视觉 故障排除文章。
进一步阅读
继续阅读 如何在目标像素上获得良好的3D数据。