C#でバーコードの画像補正フィルターを使用する方法

How to use Image Correction Filters

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を1ステップで適用します。 これにより、最小のセットアップで外部ツールを必要とせずにバーコードスキャンが改善されます。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. Copy and run this code snippet.

    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. Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小のワークフロー (5ステップ)

  1. 画像補正フィルターを使用するためにC#ライブラリをダウンロードする
  2. 利用可能なすべての画像補正フィルターを探索する
  3. 各画像補正フィルターをカスタム値で設定する
  4. 不完全な画像サンプルにフィルターを適用する
  5. フィルターの助けを借りて画像からバーコード値を取得する

画像フィルターを使用して読み取り例を向上させる

フィルターを適用するには、ImageFilterCollectionクラスをインスタンス化し、各フィルターのインスタンスを個別に作成します。 次に、オブジェクトをBarcodeReaderOptionsオブジェクトのImageFiltersプロパティに割り当てます。 オプションオブジェクトをサンプル画像と一緒にReadメソッドに渡します。

下の画像をサンプル画像として使用しましょう。

class="content-img-align-center">
class="center-image-wrapper"> サンプル画像

画像の初見では、非常にぼやけているように見えます。 しかし、明るさは許容範囲で、白黒の色は区別できます。 したがって、バーコードの読みやすさを改善するために少なくともSharpenFilterContrastFilterを適用する必要があります。 下記のコードスニペットを参照して、画像にフィルターを適用して、コンソールに表示する方法を学びましょう。

: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

上記のコードスニペットから、フィルターの適用とバーコードの読み取りの他に、フィルターを適用した画像をディスクにエクスポートしました。 サンプル画像とフィルター画像の比較が下に示されています。

class="competitors-section__wrapper-even-1">
サンプル画像
フィルター適用サンプル

画像補正フィルターの探索

IronBarcodeは、画像補正のために特別に設計された複数の画像フィルターを提供しています。 これらのフィルターは不完全なバーコード画像を読み取り、読み取り精度を向上させるのに役立ちます。 ただし、ユーザーはフィルターの動作を理解し、適切なフィルターを選択し、過度の使用や不適切なフィルター使用によるパフォーマンスの問題を回避する必要があります。 以下は利用可能なすべてのフィルターです:

  • AdaptiveThresholdFilter
  • BinaryThresholdFilter
  • BrightnessFilter
  • ContrastFilter
  • InvertFilter
  • SharpenFilter
  • ErodeFilter
  • DilateFilter
  • HistogramEqualizationFilter
  • Blur Filters
  • GaussianBlurFilter
  • BilateralFilter
  • MedianBlurFilter

これらのフィルターが適用される順序は、ImageFilterCollection内の配置に基づいています。

アダプティブしきい値フィルター

AdaptiveThresholdFilterは、IronBarcodeで利用可能なフィルターの1つで、画像にBradley Adaptive Threshold技術を適用し、画像の2値化しきい値を自動的に決定します。 このフィルターは照明が不均一で背景強度が変化する画像に最適です。

: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

以下は異なる値を使用してフィルターを適用した結果です。

class="competitors-section__wrapper-even-1">
デフォルトの適応しきい値
0.9適応しきい値

このコンストラクタは構成のための追加パラメータも受け入れます:

  • Upper: しきい値での上限(白)色。
  • Lower: しきい値での下限(黒)色。
  • Threshold: 2値化のしきい値(0.0-1.0)。
  • Rectangle: プロセッサを適用する領域。

上記の出力画像のように、画像はの色だけに2値化されます。 しかし、バーコードの読み取りに理想的とは言えず、フィルターは組み合わせて使用する必要があります。 ユーザーは最良の結果を得るためにパラメータの感度を調整して試験する必要があります。

2値化しきい値フィルター

BinaryThresholdFilterは、指定されたしきい値でピクセルを分割することにより画像をフィルタリングし、色成分の明度を比較するために使用されます。 AdaptiveThresholdFilterと同様に、このフィルターは正しく使用されないと新しいノイズや望ましくないノイズを導入することがあります。 しかし、IronBarcodeはフィルターのプロパティに対してデフォルト値を設定しています。

AdaptiveThresholdFilterと同様に、BinaryThresholdFilterは構成のための追加パラメータも受け入れます:

  • Upper: しきい値での上限(白)色。
  • Lower: しきい値での下限(黒)色。
  • Threshold: 2値化のしきい値(0.0-1.0)。
  • Rectangle: プロセッサを適用する領域。
: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

以下はサンプル画像にフィルターを適用した出力例です。

class="competitors-section__wrapper-even-1">
デフォルト2値化しきい値
0.9二値化しきい値

上記の出力画像から、サンプルが黒と白色に2値化されていることがわかります。 しかし、バーコードバーが消去され、新しいノイズが導入されたため、このフィルターがこの画像には適していないことが明らかです。

明るさフィルター

BrightnessFilterは、IronBarcodeの画像フィルターコレクションでのもう一つの重要なフィルターです。 名前が示すように、このフィルターはバーコード画像の明るさを調整します。 このコンストラクタへの入力により、出力画像のが変化します。 デフォルト値は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

以下はこのフィルターをサンプル入力に適用した後の出力画像です。

class="competitors-section__wrapper-even-1">
デフォルトの明るさ
1.5明るさ

コントラストフィルター

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

このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

class="competitors-section__wrapper-even-1">
デフォルトコントラスト
1.5コントラスト

反転フィルター

このフィルターを使用すると、画像内の色を反転させ、白が黒になり、黒が白になります。特に背景色のあるバーコード画像を読み取る場合に便利です。 BinaryThresholdFilterとは異なり、このフィルターは感度指定なしで色を直接反転します。 さらに、このフィルターは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

以下はサンプル入力画像にこのフィルターを適用した結果です。

class="competitors-section__wrapper-even-1">
元の画像
反転

シャープフィルター

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.

class="competitors-section__wrapper-even-1">
デフォルトシャープ
0.5シャープ

上記の画像と元の画像を比較すると、よりシャープになり、IronBarcodeを使用したバーコードの読み取りに役立つでしょう。 ほとんどの場合、SharpenFilterImageFilterCollectionクラスの他のフィルターと一緒に常に適用されます。

エローディフィルター

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
class="competitors-section__wrapper-even-1">
元の画像
反転

上記の入力画像と出力画像を比較すると、よりアグレッシブなフィルターリングのために、いくつかのバーがより厚くなっていることがわかります。 ただし、全体的な画像の白斑点は減少しました。 浸食フィルターの性質上、カーネルサイズが大きくなると、あまりにもアグレッシブに適用される場合、細いバーを削除する問題が発生する可能性があります。上記の画像でも示されていますが、開発者は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
class="competitors-section__wrapper-even-1">
元の画像
反転

上記の画像からもわかるように、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
class="competitors-section__wrapper-even-1">
元の画像
反転

上記の画像からもわかるように、黒いバーは明らかに暗くなり、スペースは元の画像と比べて明るくなっています。

ぼかしフィルター

ガウシアンぼかしフィルター

GaussianBlurFilterは、画像にガウシアンぼかしを適用するためのものです。 このフィルターは、画像のノイズを軽減するためによく使用されます。

フィルターは、ガウス関数を使用して画像の隣接するピクセル値を平均することによって機能します。 この方法は、2つの調整可能な要素に依存しています:

  • カーネル: ピクセルを平均するために使用される行列。
  • シグマ: ぼかしの強度を制御する値。

デフォルトのカーネルサイズは3x3ピクセルで、デフォルトのシグマ値は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

このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

class="competitors-section__wrapper-even-1">
デフォルトシャープ
ガウシアンぼやけ画像

バイラテラルフィルター

BilateralFilterは、エッジを保持しながら画像をスムーズに処理するために使用されます。 単純なぼかし技術とは異なり、すべてのピクセルに均一に影響を及ぼしますが、バイラテラルフィルターは色の差異とピクセルの距離の両方を考慮に入れ、エッジを保持したスムージングに効果的です。

このメソッドは3つの調整可能な要素に依存しています:

  • NeighborhoodDiameter: フィルタリングに使用するピクセル近接の直径を指定します。 直径が大きいほど、フィルターにされる周辺のピクセルが多く含まれます。 デフォルト値は5です。
  • シグマカラー: これは色の影響を表します。 これは、隣接ピクセル間の色の違いがフィルタリングにどれだけ影響するかを決定します。 より高い値は、異なる色のピクセルが互いに影響し合うことを意味します。 デフォルト値は75.0です。
  • シグマスペース: これは空間的な影響を表します。 これは、ピクセル間の距離がフィルタリングにどれだけ影響するかを決定します。 より高い値は、より離れたピクセルが互いに影響し合うことを意味します。 デフォルト値は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

このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

class="competitors-section__wrapper-even-1">
デフォルトシャープ
バイラテラル画像

メディアンブラー

MedianBlurFilterは、ノイズ除去のために周囲ピクセルの中央値で各ピクセルの値を置き換えるフィルターです。 このフィルターは、ノイズを除去しながらエッジを保持するために特に効果的です。

  • カーネルサイズ: 各ピクセルの周囲の近接を示す数値が、中央値を計算するのに使用されます。 The value must be an odd number greater than 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

このフィルターをサンプル入力に適用すると、以下の画像が生成されます。

class="competitors-section__wrapper-even-1">
デフォルトシャープ
MedianBlur画像

反復保存

バーコードに複数のフィルターを適用する場合、各フィルターメソッド後の出力を表示するのが難しいです。 この機能は各フィルターが適用される順序でフィルターを適用した後、フィルターされた画像を保存します。 この機能を有効にするには、まずtrueImageFilterCollectionコンストラクタに渡します。 次に、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コントラスト
class="competitors-section__wrapper-even-1">
サンプル画像
1.5コントラスト

コードの順序でフィルターを適用し、ImageFiltersプロパティの他に、BarcodeReaderOptionsに他のプロパティを追加して、より正確な読み取りを行うこともできます; 詳細については、この記事を参照してください。

よくある質問

.NET C# でバーコードの読みやすさをどのように改善できますか?

IronBarcode を使った画像補正フィルターを適用することで、.NET C# でバーコードの読みやすさを向上させることができます。AdaptiveThresholdFilter や BrightnessFilter といったフィルターは、画像の不完全さに対処し、バーコードスキャンの精度を向上させます。

プログラム上で画像補正フィルターを適用する手順は何ですか?

IronBarcode でプログラム的に画像補正フィルターを適用するには、ライブラリをダウンロードし、ImageFilterCollection クラスをインスタンス化し、希望のフィルターを設定して、バーコード画像を処理する前に BarcodeReaderOptions を通じてそれらを適用する必要があります。

IronBarcode で画像品質を向上させるために利用できるフィルターはどれですか?

IronBarcode は画像品質を向上させる様々なフィルターを提供しています。AdaptiveThresholdFilterBinaryThresholdFilterBrightnessFilterContrastFilterInvertFilterSharpenFilter、および GaussianBlurFilterBilateralFilter などのいくつかのぼかしフィルターがあります。

C# で Adaptive Threshold Filter をどのように設定しますか?

IronBarcode では、AdaptiveThresholdFilter を Bradley Adaptive Threshold 技術を使用して設定できます。このフィルターは特に不均一な照明条件に有用であり、画像の二値化の閾値を自動的に決定します。

フィルタリングの各ステップで画像を保存することは可能ですか?

はい、IronBarcode では、ImageFilterCollection で反復保存を有効にし、ExportFilterImagesToDisk メソッドを使用することで、フィルタリングの各ステップで画像を保存することができます。

複数のフィルターを適用する際に考慮すべきことは何ですか?

IronBarcode で複数のフィルターを適用する際には、過剰なまたは不適切なフィルターを使用しないように注意することが重要です。これがノイズを導入したり、パフォーマンスに影響を与える可能性があります。それぞれのフィルターの機能を理解することで、最適な結果を得るために必要なフィルターのみを適用できます。

シャープフィルターが画像にどのように影響を与えるのですか?

IronBarcode の SharpenFilter は画像の鮮明さを向上させるためにシャープネスを調整します。これは Sigma 値で設定可能で、バーコード画像のエッジ定義を向上させるのに役立ちます。

バーコード処理におけるインバートフィルターの役割は何ですか?

IronBarcode の InvertFilter は画像の色を反転させ、白を黒に、黒を白にします。これは非標準のカラースキームや背景を持つバーコードに特に有効です。

ガウシアンおよびバイラテラルぼかしフィルターが画像処理をどのように改善するのですか?

IronBarcode では、GaussianBlurFilter がガウシアンぼかしを適用して画像ノイズを低減し、BilateralFilter が色の差とピクセルの距離を考慮しながらエッジを保持しつつ画像を滑らかにします。

Hairil Hasyimi Bin Omar
ソフトウェアエンジニア
すべての優れたエンジニアのように、ハイリルは熱心な学習者です。彼はC#、Python、およびJavaの知識を磨いており、その知識を利用してIron Software全体のチームメンバーに価値を追加しています。ハイリルはマレーシアのマラ工科大学からIron Softwareチームに参加し、化学およびプロセス工学の学士号を取得しました。
準備はいいですか?
Nuget ダウンロード 1,935,276 | バージョン: 2025.11 ただ今リリースされました