C# 画像補正フィルタを使用してバーコードデコードを改善する
IronBarcode は、SharpenFilter および ContrastFilter のような組み込みの画像補正フィルターを提供し、プログラムでぼやけたまたは不完全なバーコード画像を強化し、外部の画像編集ソフトウェアや画像の再撮影なしで読み取り精度を向上させます。
すべての画像が完璧というわけではなく、画質の悪さはIronBarcodeでのバーコード読み取りを成功させない主な要因の一つです。 IronBarcodeは、画像の再キャプチャや外部の画像補正ソフトウェアを使用する代わりに、プログラムによって画質を向上させる組み込みフィルタを提供します。 これらのフィルタは、IronBarcodeが難しい画像を読み取り、全体的な精度を向上させるのに役立ちます。
IronBarcodeで利用可能な画像補正フィルター、それらが画像に与える影響、およびそれらの適用方法についてさらにお読みください。 より包括的なバーコード読み取り技術については、バーコードの読み取りチュートリアルをご覧ください。
クイックスタート:シャープとコントラストフィルターを適用してバーコードの読み取りを改善わずか1ステップで、IronBarcode の SharpenFilter および ContrastFilter を BarcodeReaderOptions の中で ImageFilterCollection を使って適用します。 これは、最小限のセットアップと外部ツールの必要性ゼロでBarCodeスキャンを改善します。
-
1IronBarcode を NuGet Package Manager でインストールします
-
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) } });Dim results As BarcodeResults = IronBarCode.BarcodeReader.Read("input.png", New IronBarCode.BarcodeReaderOptions With {.ImageFilters = New IronBarCode.ImageFilterCollection() {New IronBarCode.SharpenFilter(3.5F), New IronBarCode.ContrastFilter(2.0F)}})Dim results As BarcodeResults = IronBarCode.BarcodeReader.Read("input.png", New IronBarCode.BarcodeReaderOptions With {.ImageFilters = New IronBarCode.ImageFilterCollection() {New IronBarCode.SharpenFilter(3.5F), New IronBarCode.ContrastFilter(2.0F)}}) -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronBarcodeを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- 画像補正フィルタを使うためのC#ライブラリをダウンロード
- 利用可能なすべての画像補正フィルターを探索します
- カスタム値で各フィルタを設定する
- 不完全な画像サンプルにフィルタを適用
- 強化された画像からバーコードの値を取得する
どのようにしてイメージフィルターを適用し、バーコード読み取りを改善するのか?
フィルタを適用するには、ImageFilterCollectionクラスをインスタンス化し、各フィルタのインスタンスを個別に作成します。 次に、オブジェクトを ImageFilters プロパティに BarcodeReaderOptions オブジェクトとして割り当てます。 オプションオブジェクトをサンプル画像と一緒にReadメソッドに渡します。 高度なインストールオプションについては、NuGetパッケージガイドをご覧ください。
以下の画像をサンプル画像として使用してください。

サンプル画像
画像がかなりぼやけて見えます。 しかし、明るさは許容範囲で、白黒の色は区別できます。 したがって、バーコードの読みやすさを向上させるために、少なくとも SharpenFilter および ContrastFilter を適用します。 以下のコードスニペットを参照して、画像にフィルタを適用し、それを読み取り、結果をコンソールに表示します。
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);
}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 resultImports 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上のコード・スニペットは、フィルタを適用し、BarCodeを読み取り、フィルタリングされた画像をディスクにエクスポートします。 サンプル画像とフィルター画像の比較を以下に示します。

サンプル画像

フィルタリングされたサンプル
IronBarcodeではどのようなイメージ補正フィルターが使用可能か?
IronBarcodeは画像補正用に特別に設計された複数の画像フィルタを提供しています。 これらのフィルタは、不完全な BarCode 画像の読み取りを支援し、読み取り精度を向上させます。 しかし、適切なフィルタを選択し、多すぎるフィルタの使用や間違ったフィルタの使用によるパフォーマンスの問題を避けるために、これらのフィルタがどのように機能するかを理解してください。 利用可能なフィルタは次のとおりです:
AdaptiveThresholdFilterBinaryThresholdFilterBrightnessFilterContrastFilterInvertFilterSharpenFilterErodeFilterDilateFilterHistogramEqualizationFilter- Blur Filters
GaussianBlurFilterBilateralFilterMedianBlurFilter
フィルタの適用順序はImageFilterCollection内の配置に基づいています。 これらのフィルタに関する詳細なAPIドキュメントは、APIリファレンスをご覧ください。
適応閾値フィルターはどのように機能するのか?
AdaptiveThresholdFilterはIronBarcodeで利用可能なフィルタであり、画像にブラッドリー適応しきい値技術を適用し、画像の2値化のしきい値を自動的に決定します。 このフィルターは照明が不均一で背景強度が変化する画像に最適です。
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");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")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")以下は異なる値を使用してフィルターを適用した結果です。

デフォルト値

0.9の値
コンストラクタは、設定のための追加パラメータを受け付けます:
Upper: しきい値の上限(白)色。Lower: しきい値の下限(黒)色。Threshold: 2値化のしきい値制限(0.0-1.0)。Rectangle: プロセッサを適用する矩形領域。
上の出力画像に示されているように、画像は黒と白の色だけを持つように2値化されています。 バーコードの読み取りにはまだ理想的ではないようですが、フィルターは組み合わせて使用する必要があります。 最良の結果を得るために、パラメータ感度を試してください。
バイナリ閾値フィルターはどのように機能するのか?
BinaryThresholdFilterは、指定したしきい値でピクセルを分割し、色成分の輝度を比較することにより画像をフィルタリングします。 AdaptiveThresholdFilterに似ており、このフィルタは正しく使用しないと新しいまたは不必要なノイズを追加する可能性があります。 ただし、IronBarcodeはフィルタのプロパティにデフォルト値を設定しています。
AdaptiveThresholdFilter と同様に、BinaryThresholdFilter も同じ追加パラメータの設定を受け入れます:
Upper: しきい値の上限(白)色。Lower: しきい値の下限(黒)色。Threshold: 2値化のしきい値制限(0.0-1.0)。Rectangle: プロセッサを適用する矩形領域。
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");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")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")以下はサンプル画像にフィルターを適用した出力例です。

デフォルト値

0.9の値
上の出力画像を見ると、サンプルは白黒に2値化されています。 しかし、バーコードバーが除去され、新たなノイズが混入しているため、このフィルタがこの画像に適していないことは明らかです。 難しいバーコードのシナリオに対応するには、未認識バーコードのトラブルシューティングガイドを参照してください。
バーコード読み取りを向上させるために、イメージの明るさをどのように調整するのか?
BrightnessFilterはIronBarcodeの画像フィルタコレクションにおけるもう一つの重要なフィルタです。 名前が示すように、このフィルターはバーコード画像の明るさを調整します。 このコンストラクタへの入力は、出力画像の明るさの量を変化させます。 デフォルト値は1で、画像は変更されません。 0を指定すると真っ黒な画像になり、1を超えると明るい画像になります。
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");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")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")以下はこのフィルターをサンプル入力に適用した後の出力画像です。

デフォルト値

1.5 値
コントラストフィルターを使用してバーコードイメージをどのように改善するのか?
ContrastFilterは画像のコントラストレベルを調整します。 画像のコントラストは、画像中のさまざまな要素間の色の強度の違いを指します。 コントラストレベルの向上は、詳細の視認性を向上させ、画像を鮮やかで印象的なものにし、コントラストを減少させると、画像をより柔らかく抑えたものにします。 バーコードのカスタマイズに関する詳細については、バーコードスタイルのカスタマイズガイドをご覧ください。
デフォルト値は1で、画像は変更されません。 値0は完全なグレー画像を作成し、値1以上は画像のコントラストを増加させます。
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");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")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")このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

デフォルト値

1.5 値
反転フィルターはいつ使用すべきか?
このフィルタは、画像内の色を反転させ、白が黒に、黒が白になるように反対色にします。背景色のある BarCode 画像を読み取るときに特に便利です。 BinaryThresholdFilterとは異なり、このフィルタは感度を指定することなく直接色を反転させます。 さらに、このフィルタはCropRectangleと一緒に使うことで、画像全体の色を反転させるのではなく、画像の中で色の反転が必要な場所を指定することができます。 トリミング領域の指定については、トリミング領域のチュートリアルをご覧ください。
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");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")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")下の出力画像は、サンプルの入力画像にこのフィルタを適用した結果です。

オリジナル画像

反転
シャープフィルターでぼやけたバーコードイメージをどのように修正するのか?
IronBarcodeはシャープフィルターを提供します。 このフィルターは画像のシャープネスを強化し、ぼやけた画像を処理する際に非常に有用です。 このフィルタを操作して、フィルタオブジェクトをインスタンス化するときにシグマ値を調整することで、画像のシャープネスを調整します。 デフォルト値は3です。シグマ値を増やすと画像のシャープネスが向上します。 その他のパフォーマンス最適化オプションについては、読み取り速度オプションガイドをお読みください。
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");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")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")下の画像は、サンプル入力画像のシャープバージョンです。

デフォルト値

0.5の値
上の画像と元の画像を比較すると、より鮮明に表示され、IronBarcodeを使用したバーコードの読み取りに役立ちます。 ほとんどの場合、SharpenFilter は ImageFilterCollection クラスの他のフィルターと一緒に常に適用されます。
エロージョンフィルターは何に使用されるのか?
ErodeFilterは、形状の縁近くのピクセルを削除することにより、小さな白色ノイズを除去し、バーコードバーの太さを厚くします。このフィルタは、バーコード背景に白い斑点がたくさんある場合や、バーコード画像が非常に低解像度またはぼやけている場合に最適で、バーが合体しているようなシナリオで最適に使用されます。 ErodeFilterは、背景の白い斑点を除去しながらバーを太くします。 不完全な画像の処理に関する詳細は、不完全なバーコードの例をご覧ください。
フィルタのためにkernelSizeを表す整数を入力することでエロージョンの効果を増やします。 カーネルサイズが大きいほど、入力画像に対する効果が強くなります。 注意:kernelSize は正方形であり、この例では 5x5 カーネルになります。
例として、フィルタの効果を示すためにErodeFilterを大きなカーネルサイズで使用します。
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");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");Imports IronBarCode
Dim options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection(True) From {
New ErodeFilter(5)
}
}
' Apply options and read the barcode
Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options)
' Export file to disk
results.ExportFilterImagesToDisk("erodeFilter.jpg")Imports IronBarCode
Dim options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection(True) From {
New ErodeFilter(5)
}
}
' Apply options and read the barcode
Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options)
' Export file to disk
results.ExportFilterImagesToDisk("erodeFilter.jpg")
オリジナル画像

侵食フィルタを適用
上の入力画像と出力画像を比較すると、フィルタリングに大きなカーネル・サイズを入力したため、いくつかのバーが目に見えて太くなっています。 ただし、全体的な画像の白斑点は減少しました。 エロージョンフィルターの性質上、カーネルサイズが大きくなると、上の写真のように、強引に適用しすぎると細いバーを消してしまう可能性があります。 カーネルサイズの値を変更してErodeFilterに入力し、効果をテストおよび微調整します。
膨張フィルターはバーコード読み取りにどのような効果があるのか?
DilateFilter は ErodeFilter の逆として機能し、通常は背景を輝度領域として拡大し、オブジェクトの境界にピクセルを追加します。 このフィルタは、小さなギャップを埋めたり、低コントラスト領域を強調したりすることで、損傷したバーコードや淡いバーコードを修復しますが、バーコードバーへの効果は直感とは異なることに注意してください。 ディレーションは明るいスペースを拡大するため、(背景が白であると仮定した場合)黒いBarCodeバーのような暗い要素は間接的に薄くなります。 これは、非常に太いまたは合併したバーコードバーが現れる場面で特に効果的であり、過剰な使用はバーを細くしすぎてスキャン精度を低下させる可能性があります。
前述のように、フィルタの効果を高めるためにフィルタ用のkernelSizeを表す整数を入力します。
以下の例では、DilateFilterの効果を示すためにより大きなカーネルサイズを使用します。
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");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");Imports IronBarCode
Dim options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection(True) From {
New DilateFilter(5)
}
}
' Apply options and read the barcode
Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options)
' Export file to disk
results.ExportFilterImagesToDisk("dilateFilter.jpg")Imports IronBarCode
Dim options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection(True) From {
New DilateFilter(5)
}
}
' Apply options and read the barcode
Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options)
' Export file to disk
results.ExportFilterImagesToDisk("dilateFilter.jpg")
オリジナル画像

膨張フィルタを適用しました
上記の画像で示されているように、DilateFilterを過剰に使用すると、バーコード構造を破壊し、密接に空間を空けたバーを統合し、バーコードに静かなゾーンを作成する可能性があります。 入力画像に応じてカーネル・サイズの値を大きくしたり小さくしたりして、画像への効果をテストし、改良してください。
ヒストグラム等化フィルターはいつ使用すべきか?
HistogramEqualizationFilterは、画像のコントラストを強調し、明瞭性を向上させるためにピクセルの輝度を再分配します。 バーコードのコントラストが低い場合(色あせた画像や洗いざらしの画像など)、または照明にムラがある場合(暗い影や明るいまぶしさなど)によく使用されます。 ピクセルの明るさの分布である画像ヒストグラムを分析することによって、暗いピクセルを暗くし、明るいピクセルを明るくするように、強度範囲をストレッチしてコントラストを高めることでピクセル値を再配布します。
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");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");Imports IronBarCode
Dim options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection(True) From {
New HistogramEqualizationFilter()
}
}
' Apply options and read the barcode
Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options)
' Export file to disk
results.ExportFilterImagesToDisk("histogramEqualizationFilter.jpg")Imports IronBarCode
Dim options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection(True) From {
New HistogramEqualizationFilter()
}
}
' Apply options and read the barcode
Dim results As BarcodeResults = BarcodeReader.Read("sample.png", options)
' Export file to disk
results.ExportFilterImagesToDisk("histogramEqualizationFilter.jpg")
オリジナル画像

ヒストグラム均等化フィルタを適用
上の画像に示されているように、元の画像と比較して、黒いバーが目に見えて暗くなり、スペースが目に見えて明るくなっています。
バーコードノイズの軽減に役立つブラー(ぼかし)フィルターはどれか?
ガウシアンブラー(GaussianBlur)フィルターはどのようにしてイメージノイズを軽減するのか?
GaussianBlurFilterは画像にガウスぼかしを適用します。 このフィルタは、一般的に画像のノイズを低減します。 不完全なバーコードに対処するためのガイドについては、画像の向き補正チュートリアルを参照してください。
フィルターは、画像内の隣接するピクセル値をガウス関数を使用して平均化することによって機能します。 この方法は、2つの調整可能な要素に依存しています:
- カーネル: ピクセルを平均するために使用される行列。
- シグマ: ぼかしの強度を制御する値。
デフォルトの kernel サイズは 3x3 ピクセルで、デフォルトの Sigma 値は 3.0 であり、適度なぼかしを生成します。 Sigma値を増加させると、ぼかし効果が強くなります。 ぼかしフィルタが平均する近傍サイズを制御するために、kernelをカスタマイズすることもできます。
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");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")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")このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

画像をシャープにする

ガウスぼかし画像
バイラテラルフィルターはいつ使用すべきか?
BilateralFilterは、エッジを保持しながら画像を滑らかにします。 すべてのピクセルに一様に影響を与える単純なぼかし技術とは異なり、バイラテラル・フィルターは色の違いとピクセルの距離の両方を考慮するため、エッジを維持したスムージングに効果的です。
このメソッドは3つの調整可能な要素に依存しています:
NeighborhoodDiameter: ピクセル近傍の直径(デフォルト:5)。SigmaColor: 色の違いの影響を決定する色影響(デフォルト:75.0)。SigmaSpace: 距離の影響を決定する空間影響(デフォルト:75.0)。
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");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")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")このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

画像をシャープにする

両側画像
メディアンブラー(MedianBlur)フィルターはノイズ軽減において何が異なるのか?
MedianBlurFilterは、周囲のピクセルの中央値で各ピクセルの値を置き換えることで、画像のノイズを軽減します。 このフィルタは、ノイズを除去しつつエッジを保持するのに特に優れています。バーコード読み取り設定について詳細を探るには、バーコードリーダー設定ガイドをご覧ください。
KernelSize: 中央計算のための近傍サイズ(奇数でなければならない、デフォルト:5)。
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");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")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")このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

画像をシャープにする

MedianBlur画像
処理の各ステップでフィルターがかけられたイメージをどのように保存するのか?
バーコードに複数のフィルタを適用する場合、各フィルタメソッド後の出力を表示することは困難です。 この機能は各フィルターが適用される順序でフィルターを適用した後、フィルターされた画像を保存します。 この機能を有効にするには、まず true を ImageFilterCollection のコンストラクターに渡します。 次にExportFilterImagesToDiskメソッドを使用して、出力画像のパスと名前を指定します。 バーコード保存のさらなる例については、バーコードを画像へ変換する例をご覧ください。
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");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")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")フィルターはコードの順序で適用され、出力画像は各反復の結果を反映します:
Sharpen-> その後SharpenSharpen+AdaptiveThreshold-> その後AdaptiveThresholdSharpen+AdaptiveThreshold+Contrast-> その後Contrast

サンプル画像

シャープニング後

適応閾値後

コントラスト後
ImageFilters プロパティとは別に、BarcodeReaderOptions に他のプロパティを追加してより正確な読み取りを行います; 詳細については、この記事を参照してください。
よくある質問
IronBarcode で使用できる画像補正フィルターは何ですか?
IronBarcode は、SharpenFilter、ContrastFilter、AdaptiveThresholdFilter、BinaryThresholdFilter、BrightnessFilter、InvertFilter、ErodeFilter、DilateFilter、HistogramEqualizationFilter、および GaussianBlurFilter、BilateralFilter、MedianBlurFilter を含む複数のブラーフィルターなど、さまざまな画像補正フィルターを提供しています。これらのフィルターは、画像品質を向上させることでバーコード読み取り精度を高めます。
IronBarcode で Sharpen フィルターと Contrast フィルターを適用するにはどうすればよいですか?
IronBarcode で Sharpen フィルターと Contrast フィルターを適用するには、ImageFilterCollection クラスをこれらのフィルターでインスタンス化し、BarcodeReaderOptions オブジェクトの ImageFilters プロパティに割り当てます。このオプションオブジェクトを画像と共に Read メソッドに渡して、バーコードの読み取りを強化してください。
Adaptive Threshold Filter の目的は何ですか?
Adaptive Threshold Filter は、Bradley Adaptive Thresholding 技法を使用して画像を二値化するためのしきい値を自動的に決定します。これは、特に均一でない照明や背景強度が変化する画像に対して有用です。
Invert Filter はどのように動作しますか?
Invert Filter は画像の色を反転させ、白を黒に、黒を白に変換します。背景色のあるバーコード画像に有利です。CropRectangle を使って画像全体または特定の部分に適用できます。
Erode Filter はバーコード画像にどのような影響を与えますか?
Erode Filter はバーコードのバーを太くするために、エッジ付近のピクセルを削除し、背景のホワイトノイズを減少させます。低解像度やぼやけた画像に有用ですが、慎重に調整しなければ薄いバーを消去する可能性があります。
HistogramEqualization Filter はいつ使用するべきですか?
HistogramEqualization Filter は、ピクセルの強度を再配分してコントラストを強化するため、低コントラストや不均一な照明のバーコードに適しています。このフィルターは強度範囲を広げ、読みやすさを向上させます。
GaussianBlur Filter は何をしますか?
GaussianBlur Filter は、ガウス関数を用いてピクセル値を平均化することで画像内のノイズを減少させます。カーネルサイズとシグマ値を設定することができ、画像ノイズを減少させるために適度なブラーを適用します。
Bilateral Filter は他のぼかしフィルターとどのように異なりますか?
Bilateral Filter は、ノイズを減少させつつエッジを保持し、色の違いやピクセル距離の両方を考慮します。近隣直径、シグマカラー、およびシグマスペースのパラメータを考慮して画像を滑らかにします。
MedianBlur Filter の主な用途は何ですか?
MedianBlur Filter は、ノイズを最小限に抑えながらエッジを保持する上で優れています。各ピクセルの値をその近隣の中央値で置き換えることで、ノイズの低減とエッジの保持に効果的です。
IronBarcode で各フィルターを適用した後に画像を保存するにはどうすればよいですか?
IronBarcode では、ImageFilterCollection コンストラクタに true を渡すことで各フィルターステップの後に画像のエクスポートを有効にし、ExportFilterImagesToDisk メソッドを使用して各処理ステップで出力画像を保存します。