How to use Image Correction Filters For Barcode Using C#

使用 C# 图像校正过滤器改进条形码解码

This article was translated from English: Does it need improvement?
Translated
View the article in English

面对现实吧。 并非每个图像都是完美的,这也是 IronBarcode 无法读取条码图像的 主要因素之一。 这并不完全是用户的错。 IronBarcode 不需要重新捕捉图像或使用其他图像增强软件,而是推出了一项功能,使用户能够以编程方式对图像应用过滤器。 这将有助于 IronBarcode 读取图像并提高准确性。

继续阅读,了解 IronBarcode 中可用的图像校正过滤器、它们对图像的影响以及如何应用它们。

快速入门:应用锐化和对比度滤镜改进条形码读取

只需一步,即可使用 BarcodeReaderOptions 中的 ImageFilterCollection 应用 IronBarcode 的 SharpenFilter 和 ContrastFilter。 这样,您只需进行最少的设置,无需外部工具,就能改进条形码扫描。

Nuget Icon立即开始使用 NuGet 创建 PDF 文件:

  1. 使用 NuGet 包管理器安装 IronBarcode

    PM > Install-Package BarCode

  2. 复制并运行这段代码。

    BarcodeResults results = IronBarCode.BarcodeReader.Read("input.png", new IronBarCode.BarcodeReaderOptions { ImageFilters = new IronBarCode.ImageFilterCollection() { new IronBarCode.SharpenFilter(3.5f), new IronBarCode.ContrastFilter(2.0f) } });
  3. 部署到您的生产环境中进行测试

    立即开始在您的项目中使用 IronBarcode,免费试用!
    arrow pointer

使用图像过滤器改进阅读示例

要应用过滤器,请实例化 ImageFilterCollection 类,并分别创建每个过滤器的实例。 然后将该对象赋值给 BarcodeReaderOptions 对象的 ImageFilters 属性。 将选项对象与示例图像一起传递到 Read 方法中。

让我们使用下面的图片作为示例图片。

图片样本

从图像的初步观察来看,它似乎相当模糊。 但是亮度尚可接受,白色和黑色也能区分。 因此,我们需要至少应用锐化滤镜对比度滤镜来提高条形码的可读性。 请参考以下代码片段,将滤镜应用于图像,读取图像,并在控制台上显示图像。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-apply-filter.cs
using IronBarCode;
using System;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection()
    {
        new SharpenFilter(3.5f),
        new ContrastFilter(2)
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Write the result value to console
foreach (BarcodeResult result in results)
{
    Console.WriteLine(result.Text);
}
Imports IronBarCode
Imports System

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection() From {
		New SharpenFilter(3.5F),
		New ContrastFilter(2)
	}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Write the result value to console
For Each result As BarcodeResult In results
	Console.WriteLine(result.Text)
Next result
$vbLabelText   $csharpLabel

从上面的代码片段来看,除了应用过滤器和读取 BarCode 之外,我们还将过滤后的图像导出到磁盘。 下面是样本与过滤后图片的对比。

图片样本
筛选样本

探索图像校正过滤器

IronBarcode 提供多种图像过滤器,专门用于图像校正。 这些过滤器可以帮助读取不完美的条形码图像,提高读取准确性。 但是,用户需要了解这些过滤器的工作原理,以便选择合适的过滤器避免因使用过多过滤器或使用错误过滤器而导致性能问题。 以下是所有可用的过滤器:

  • 自适应阈值过滤器
  • 二进制阈值过滤器
  • 亮度过滤器
  • 对比过滤器
  • 反相滤波器
  • SharpenFilter
  • ErodeFilter
  • DilateFilter
  • 直方图均衡化滤波器
  • 模糊过滤器
    • 高斯模糊滤波器
    • 双边过滤器
    • 中值模糊过滤器

这些过滤器的应用顺序基于它们在 ImageFilterCollection 中的位置。

自适应阈值过滤器

AdaptiveThresholdFilter是 IronBarcode 中可用的过滤器之一,它将Bradley Adaptive Threshold 技术应用于图像,自动确定图像二值化的阈值。 该滤镜适用于光照不均匀和背景强度水平不一的图像。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-adaptive-threshold.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new AdaptiveThresholdFilter(0.9f),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("adaptiveThreshold_0.9.png");
Imports IronBarCode

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New AdaptiveThresholdFilter(0.9F)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Export file to disk
results.ExportFilterImagesToDisk("adaptiveThreshold_0.9.png")
$vbLabelText   $csharpLabel

以下是使用不同值进行筛选后的输出结果。

Default Adaptive Threshold
0.9 Adaptive Threshold

构造函数还接受用于配置的其他参数:

  • 上色:阈值的上色(白色)。
  • 下部:阈值的下部(黑色)颜色。
  • 阈值:二值化的阈值限制(0.0-1.0)。
  • 矩形:应用处理器的矩形区域。

从上面的输出图像中可以看出,图像经过二值化处理,只有 黑色 白色 两种颜色。 虽然它似乎仍不是条形码读取的理想选择,因为过滤器需要组合使用。 用户需要尝试参数灵敏度,以达到最佳效果。

二进制阈值过滤器

BinaryThresholdFilter 通过在给定阈值处分割像素来过滤图像,它用于比较颜色分量的亮度。 与 AdaptiveThresholdFilter 相似,如果使用不当,该过滤器可能会引入新的或不需要的噪声。 不过,IronBarcode 为过滤器的属性设置了默认值。

与 AdaptiveThresholdFilter 类似,BinaryThresholdFilter 也接受相同的附加配置参数:

  • 上色:阈值的上色(白色)。
  • 下部:阈值的下部(黑色)颜色。
  • 阈值:二值化的阈值限制(0.0-1.0)。
  • 矩形:应用处理器的矩形区域。
:path=/static-assets/barcode/content-code-examples/how-to/image-correction-binary-threshold.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new BinaryThresholdFilter(0.9f)
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("binaryThreshold_0.9.png");
Imports IronBarCode

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New BinaryThresholdFilter(0.9F)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Export file to disk
results.ExportFilterImagesToDisk("binaryThreshold_0.9.png")
$vbLabelText   $csharpLabel

以下是对示例图片应用过滤器后的输出示例。

Default Binary Threshold
0.9 Binary Threshold

观察上面的输出图像,我们可以看到样本已被二值化为黑白颜色。 但是可以看出,由于条形码条纹被消除,并且引入了一些新的噪声,因此该滤镜显然不适合此图像。

亮度过滤器

BrightnessFilter 是 IronBarcode 中图像过滤器集合中另一个必不可少的过滤器。 顾名思义,该过滤器可调整 BarCode 图像的亮度。 该构造函数的输入可以改变输出图像中的亮度。 默认值为 1,图像保持不变。 数值为 0 将创建完全黑色的图像,而数值高于 1 则会使图像更亮。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-brightness.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new BrightnessFilter(1.5f),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("brightness_1.5.png");
Imports IronBarCode

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New BrightnessFilter(1.5F)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Export file to disk
results.ExportFilterImagesToDisk("brightness_1.5.png")
$vbLabelText   $csharpLabel

以下是对样本输入应用该过滤器后的输出图像。

Default Brightness
1.5 Brightness

对比度过滤器

ContrastFilter 用于调整图像的对比度。 图像对比度是指图像中不同元素之间颜色强度的差异。 提高对比度可以增强细节的可视性,使图像显得生动、醒目,而降低对比度则会使图像显得更加柔和、沉稳。

默认值为 1,图像保持不变。 数值为 0 将创建完全灰色的图像,而数值超过 1 则会增加图像对比度。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-contrast.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new ContrastFilter(1.5f),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("contrast_1.5.png");
Imports IronBarCode

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New ContrastFilter(1.5F)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Export file to disk
results.ExportFilterImagesToDisk("contrast_1.5.png")
$vbLabelText   $csharpLabel

将此过滤器应用到示例输入中将产生下图。

Default Contrast
1.5 Contrast

反相过滤器

该滤镜用于反转图像内部的颜色,使颜色相反,如白变黑、黑变白。当用户试图读取带有背景颜色的 BarCode 图像时,它尤其有用。 与 二进制阈值过滤器不同,该过滤器可直接反转颜色,而无需指定灵敏度。 此外,该过滤器可与 CropRectangle 配合使用,以指定图像中需要反转颜色的位置,而不是反转整个图像的颜色。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-invert.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new InvertFilter(),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("invert.png");
Imports IronBarCode

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New InvertFilter()}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Export file to disk
results.ExportFilterImagesToDisk("invert.png")
$vbLabelText   $csharpLabel

下面的输出图像是将该过滤器应用于样本输入图像的结果。

原始图片
反转

锐化过滤器

我们还在 IronBarcode 中提供了锐化过滤器。 该过滤器可增强图像的清晰度,在处理模糊图像时非常有用。 用户可以通过在实例化滤镜对象时调整 Sigma 值来操作该滤镜,以调整图像的清晰度。 默认值为 3,增加西格玛值可提高图像清晰度。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-sharpen.cs
using IronBarCode;
using System;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new SharpenFilter(0.5f),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("sharpen_0.5.png");
Imports IronBarCode
Imports System

Private options As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New SharpenFilter(0.5F)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.png", options)

' Export file to disk
results.ExportFilterImagesToDisk("sharpen_0.5.png")
$vbLabelText   $csharpLabel

Image below is the sharpened version of the sample input image.

Default Sharpen
0.5 Sharpen

将上图与原图进行比较,可以明显看出图像更清晰,这肯定有助于使用 IronBarcode 读取条形码。 大多数情况下, SharpenFilter总是与ImageFilterCollection类中的其他滤镜一起应用。

腐蚀过滤器

ErodeFilter可去除微小的白噪声,并通过去除形状边缘附近的像素来加粗条形码条。该过滤器最适用于条形码背景有大量白色斑点的情况,或者条形码图像本身分辨率太低或模糊,导致一些条形码合并的情况。 ErodeFilter的效果是使条形图变粗,同时去除背景中的白色斑点。

用户还可以通过为过滤器输入一个代表 kernelSize 的整数来增强侵蚀效果。 内核尺寸越大,对输入图像的影响越强。 另外请注意,kernelSize 是一个正方形,在本例中是 5x5 内核。

例如,让我们使用内核尺寸较大的 ErodeFilter 来展示该过滤器的效果。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-erode.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new ErodeFilter(5),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("erodeFilter.jpg");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
原始图片
反转

对比上面的输入和输出图像,我们可以看到,由于输入更大的内核尺寸进行滤波的激进性,一些条形明显更粗。 然而,整体画面中的白色斑点减少了。 由于腐蚀滤波器的特性,内核尺寸越大,如果应用得过于激进,可能会遇到擦除细条的问题,如上图所示。因此,开发人员会通过更改输入到ErodeFilter 的内核尺寸值来测试和改进他们想要的效果。

分散过滤器

DilateFilter的功能与ErodeFilter相反,它通过在对象边界添加像素来扩大明亮区域(通常是背景)。 虽然这种过滤器可以通过填补小缝隙或增强低对比度区域来修复损坏或模糊的条形码,但需要注意的是,它对条形码条的效果与直觉不同。 由于扩张会放大明亮的空间,因此会间接地稀释黑色条形码条等暗色元素(假设是白色背景)。 这使得过滤器在条形码条显得过粗或合并的情况下特别有效,但过度使用会使条形码过分变窄,从而降低扫描精度。

与上文类似,用户可以通过输入代表过滤器 kernelSize 的整数来增加过滤器的效果。

在下面的示例中,我们将使用较大的内核尺寸来展示 DilateFilter 的效果。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-dilate.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new DilateFilter(5),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("dilateFilter.jpg");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
原始图片
反转

从上图可以看出,过度使用DilateFilter可能会破坏条形码结构,合并间距较小的条形,并在条形码中创建空白区域。 用户应根据输入图像,通过增大或减小内核大小值来测试和改进他们想要对图像产生的效果。

组图均衡过滤器

HistogramEqualizationFilter是一种滤波器,可通过重新分配像素强度来增强图像对比度,从而提高清晰度。 它最常用于条形码对比度较低的情况,如褪色或冲淡的图像,或者光照不均匀的图像,如暗影或明亮的眩光。 通过分析图像直方图(即像素亮度分布图),它可以重新分配像素值,通过拉伸强度范围来增强对比度,使暗像素变暗,亮像素变亮。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-histogram-equalization-filter.cs
using IronBarCode;

BarcodeReaderOptions options = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new HistogramEqualizationFilter(),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.png", options);

// Export file to disk
results.ExportFilterImagesToDisk("histogramEqualizationFilter.jpg");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
原始图片
反转

从上图可以看出,与原图相比,黑条明显变暗,空格明显变亮。

模糊过滤器

高斯模糊过滤器

GaussianBlurFilter 用于对图像应用高斯模糊。 该过滤器通常用于减少图像中的噪音。

滤波器的工作原理是使用高斯函数平均图像中的相邻像素值。 该方法依赖于两个可调整的因素:

  • 内核:用于平均像素的矩阵。
  • Sigma:控制模糊强度的值。

默认内核大小为 3x3 像素,默认 Sigma 值为 3.0,可产生适度的模糊效果。 提高西格玛值将产生更强的模糊效果。 您还可以自定义内核,以控制模糊过滤器平均邻域的大小。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-gaussianblur.cs
using IronBarCode;

BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new GaussianBlurFilter(3, 3, 3.0f),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sharpen.webp", myOptionsExample);

// Export file to disk
results.ExportFilterImagesToDisk("gaussianBlur.png");
Imports IronBarCode

Private myOptionsExample As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New GaussianBlurFilter(3, 3, 3.0F)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sharpen.webp", myOptionsExample)

' Export file to disk
results.ExportFilterImagesToDisk("gaussianBlur.png")
$vbLabelText   $csharpLabel

将此过滤器应用到示例输入中将产生下图。

Default Sharpen
高斯模糊图像

双边过滤器

BilateralFilter 用于平滑图像,同时保留边缘。 简单的模糊技术会均匀地影响所有像素,而双边滤波器则不同,它同时考虑了颜色差异和像素间的距离,因此可以有效地进行边缘保护平滑处理。

该方法依赖于三个可调整的因素:

  • 邻域直径(NeighborhoodDiameter):指定用于筛选的像素邻域直径。 直径越大,过滤器中包含的周围像素越多。 默认值为 5。
  • SigmaColor:表示颜色的影响。 它可以确定相邻像素之间的色差对滤波的影响程度。 数值越大,表示不同颜色的像素之间的相互影响越大。 默认值为 75.0。
  • SigmaSpace:这代表空间影响。 它可以确定像素之间的距离对过滤的影响程度。 数值越大,表示相距较远的像素之间的相互影响越大。 默认值为 75.0。
:path=/static-assets/barcode/content-code-examples/how-to/image-correction-bilateral.cs
using IronBarCode;

BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new BilateralFilter(5, 75, 75),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sharpen.webp", myOptionsExample);

// Export file to disk
results.ExportFilterImagesToDisk("bilateral.png");
Imports IronBarCode

Private myOptionsExample As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New BilateralFilter(5, 75, 75)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sharpen.webp", myOptionsExample)

' Export file to disk
results.ExportFilterImagesToDisk("bilateral.png")
$vbLabelText   $csharpLabel

将该过滤器应用到示例输入中会生成下图。

Default Sharpen
双边图像

MedianBlur 滤镜

MedianBlurFilter(中值模糊过滤器)是一种过滤器,用于将每个像素的值替换为周围像素的中值,从而减少图像中的噪声。 该过滤器在去除噪音的同时,还能有效保留边缘。

  • 内核大小:定义用于计算中值的每个像素周围邻域的大小。 值必须是大于 0 的奇数,默认值为 5。
:path=/static-assets/barcode/content-code-examples/how-to/image-correction-medianblur.cs
using IronBarCode;

BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new MedianBlurFilter(5),
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sharpen.webp", myOptionsExample);

// Export file to disk
results.ExportFilterImagesToDisk("medianBlur.png");
Imports IronBarCode

Private myOptionsExample As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {New MedianBlurFilter(5)}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sharpen.webp", myOptionsExample)

' Export file to disk
results.ExportFilterImagesToDisk("medianBlur.png")
$vbLabelText   $csharpLabel

将该过滤器应用到示例输入中会生成下图。

Default Sharpen
MedianBlur 图像

保存迭代

在对 BarCode 应用多个过滤器时,很难查看每个过滤器方法之后的输出。 该功能允许在应用每个过滤器后,按照处理顺序保存过滤后的图像。 要启用此功能,请首先将 true 传递给 ImageFilterCollection 构造函数。 然后,使用 ExportFilterImagesToDisk 方法提供输出图像的路径和名称。

:path=/static-assets/barcode/content-code-examples/how-to/image-correction-save-iterations.cs
using IronBarCode;

BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
    // Choose which filters are to be applied (in order)
    ImageFilters = new ImageFilterCollection(true) {
        new SharpenFilter(3.5f),
        new AdaptiveThresholdFilter(0.5f),
        new ContrastFilter(2)
    },
};

// Apply options and read the barcode
BarcodeResults results = BarcodeReader.Read("sample.webp", myOptionsExample);

// Export file to disk
results.ExportFilterImagesToDisk("filteredImage.png");
Imports IronBarCode

Private myOptionsExample As New BarcodeReaderOptions() With {
	.ImageFilters = New ImageFilterCollection(True) From {
		New SharpenFilter(3.5F),
		New AdaptiveThresholdFilter(0.5F),
		New ContrastFilter(2)
	}
}

' Apply options and read the barcode
Private results As BarcodeResults = BarcodeReader.Read("sample.webp", myOptionsExample)

' Export file to disk
results.ExportFilterImagesToDisk("filteredImage.png")
$vbLabelText   $csharpLabel

过滤器按代码顺序应用,输出图像反映每次迭代的结果:

  • 锐化 -> 锐化后
  • 锐化 + 自适应阈值 -> 自适应阈值后
  • 锐化 + 自适应阈值 + 对比度 -> 后对比度
图片样本
1.5 Contrast
图片样本
1.5 Contrast

除了ImageFilters属性外,用户还可以向BarcodeReaderOptions添加其他属性,以实现更准确的读取; 请参阅此文章以获取更多信息。

常见问题解答

如何在 .NET C# 中提高条码可读性?

通过在 .NET C# 中使用 IronBarcode 应用图像校正滤镜,可以增强条码可读性。过滤器如 AdaptiveThresholdFilter 和 BrightnessFilter 可以解决图像缺陷并提高条码扫描的准确性。

如何以编程方式应用图像校正滤镜?

要使用 IronBarcode 程序化地应用图像校正滤镜,您需要下载库,实例化 ImageFilterCollection 类,配置所需的滤镜,然后通过 BarcodeReaderOptions 在处理条形码图像之前应用它们。

IronBarcode 中有哪些可用于增强图像质量的滤镜?

IronBarcode 提供了多种滤镜来增强图像质量,包括 AdaptiveThresholdFilterBinaryThresholdFilterBrightnessFilterContrastFilterInvertFilterSharpenFilter 和几种模糊滤镜,如 GaussianBlurFilterBilateralFilter

如何在 C# 中配置自适应阈值滤镜?

在 IronBarcode 中,可以使用 Bradley 自适应阈值技术配置 AdaptiveThresholdFilter。该滤镜自动确定二值化图像的阈值,特别适用于照明不均匀的条件。

是否可以在过滤的每个步骤保存图像?

是的,IronBarcode 允许您在每个过滤步骤中保存图像,通过在 ImageFilterCollection 中启用迭代保存,并使用 ExportFilterImagesToDisk 方法。

应用多个滤镜时应考虑哪些因素?

在 IronBarcode 中应用多个滤镜时,重要的是避免使用过多或不当的滤镜,因为这可能引入噪声或影响性能。了解每个滤镜的功能有助于仅应用必要的滤镜以获得最佳结果。

锐化滤镜会对图像产生什么影响?

IronBarcode中的SharpenFilter通过调整清晰度来增强图像清晰度。它可以通过Sigma值进行配置,对于改善条形码图像中的边缘定义非常有用。

反转滤镜在条码处理过程中扮演什么角色?

IronBarcode中的InvertFilter反转图像的颜色,使白色变为黑色,黑色变为白色。这对于具有非标准色彩方案或背景的条形码特别有用。

高斯与双边模糊滤镜如何改善图像处理?

在IronBarcode中,GaussianBlurFilter通过应用高斯模糊来减少图像噪声,而BilateralFilter在平滑图像的同时保留边缘,考虑了颜色差异和像素距离。

Hairil Hasyimi Bin Omar
软件工程师
如所有伟大的工程师一般,Hairil 是个热心的学习者。他正在提高对 C#、Python 和 Java 的知识,并利用这些知识为 Iron Software 团队成员增值。Hairil 从马来西亚的玛拉工业大学加入 Iron Software 团队,获得化学与工艺工程学士学位。
准备开始了吗?
Nuget 下载 1,979,979 | Version: 2025.11 刚刚发布