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

バーコードのデコードを改善するための C# 画像補正フィルタの使用

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

IronBarcodeは、外部の画像編集ソフトウェアや画像の再キャプチャーを必要とせずに、ぼやけたまたは不完全なバーコード画像をプログラム的に強化し、読み取り精度を向上させるためにContrastFilterなどの組み込みの画像訂正フィルターを提供しています。

すべての画像が完璧というわけではなく、画質の悪さはIronBarcodeでのバーコード読み取りを成功させない主な要因の一つです。 IronBarcodeは、画像の再キャプチャや外部の画像補正ソフトウェアを使用する代わりに、プログラムによって画質を向上させる組み込みフィルタを提供します。 これらのフィルタは、IronBarcodeが難しい画像を読み取り、全体的な精度を向上させるのに役立ちます。

IronBarcodeで利用可能な画像補正フィルター、それらが画像に与える影響、およびそれらの適用方法についてさらにお読みください。 より包括的なバーコード読み取り技術については、バーコード読み取りチュートリアルをご覧ください。

クイックスタート:シャープとコントラストフィルターを適用してバーコードの読み取りを改善

1ステップで、IronBarcodeのBarcodeReaderOptionsに適用します。 これは、最小限のセットアップと外部ツールの必要性ゼロでBarCodeスキャンを改善します。

  1. IronBarcode をNuGetパッケージマネージャでインストール

    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クラスをインスタンス化し、それぞれのフィルターのインスタンスを個別に作成します。 次に、そのオブジェクトをImageFiltersプロパティに割り当てます。 サンプル画像と一緒にオプションオブジェクトをReadメソッドに渡します。 高度なインストールオプションについては、NuGetパッケージガイドをご覧ください。

以下の画像をサンプル画像として使用してください。

フィルター補正前の低画質を示す、数字 4900203187590 付きのぼやけたバーコード

画像がかなりぼやけて見えます。 しかし、明るさは許容範囲で、白黒の色は区別できます。 したがって、少なくともContrastFilterを適用してバーコードの読み取り可能性を向上させます。 以下のコードスニペットを参照して、画像にフィルタを適用し、それを読み取り、結果をコンソールに表示します。

: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を読み取り、フィルタリングされた画像をディスクにエクスポートします。 サンプル画像とフィルター画像の比較を以下に示します。

低画質を示す、数字 4902030187590 付きのぼやけたバーコード画像
画像フィルター適用後に読み取りやすさが向上したバーコード。鮮明な縦線と数字 4902030187590 が表示されている

IronBarcodeではどのような画像補正フィルタが利用できますか?

IronBarcodeは、特に画像補正のために設計された複数の画像フィルターを提供しています。 これらのフィルタは、不完全な BarCode 画像の読み取りを支援し、読み取り精度を向上させます。 しかし、適切なフィルタを選択し多すぎるフィルタの使用や間違ったフィルタの使用によるパフォーマンスの問題を避けるために、これらのフィルタがどのように機能するかを理解してください。 利用可能なフィルタは次のとおりです:

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

フィルターが適用される順序は、ImageFilterCollection内の配置に基づいています。 これらのフィルタの詳細なAPIドキュメントについては、API Referenceをご覧ください。

適応しきい値フィルターはどのように機能しますか?

AdaptiveThresholdFilterは、画像をバイナリー化するしきい値を自動的に決定するために、画像にBradley Adaptive Threshold技法を適用するIronBarcodeのフィルターです。 このフィルターは照明が不均一で背景強度が変化する画像に最適です。

: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

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

実線と破線のパターンで、異なる適応しきい値フィルター出力を示す縦線
著しい視覚的な歪みを伴う UPC 番号 902030187590 を示す低品質なバーコード画像

コンストラクタは、設定のための追加パラメータを受け付けます:

  • Upper: 閾値処理のための上位(白)色。
  • Lower: 閾値処理のための下位(黒)色。
  • Threshold: バイナリ化のためのしきい値制限 (0.0-1.0)。
  • Rectangle: プロセッサーを適用する矩形領域。

上の出力画像に示されているように、画像はの色だけを持つように2値化されています。 バーコードの読み取りにはまだ理想的ではないようですが、フィルターは組み合わせて使用する必要があります。 最良の結果を得るために、パラメータ感度を試してください。

バイナリしきい値フィルターはどのように機能しますか?

BinaryThresholdFilterは、指定されたしきい値で画素を分割し、色成分の輝度を比較することによって画像をフィルタリングします。 AdaptiveThresholdFilterと同様に、このフィルターを正しく使用しないと、新たなまたは不要なノイズを引き起こす可能性があります。 ただし、IronBarcodeはフィルタのプロパティにデフォルト値を設定しています。

BinaryThresholdFilterは設定のために同じ追加パラメーターを受け入れます:

  • Upper: 閾値処理のための上位(白)色。
  • Lower: 閾値処理のための下位(黒)色。
  • Threshold: バイナリ化のためのしきい値制限 (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

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

疎、点線、密の縦線パターンを示す、二値しきい値フィルター出力の 3 つの例
白黒のコントラストを示す 0.9 の二値化しきい値フィルターで処理されたバーコード画像

上の出力画像を見ると、サンプルは白黒に2値化されています。 しかし、バーコードバーが除去され、新たなノイズが混入しているため、このフィルタがこの画像に適していないことは明らかです。 難しい BarCode シナリオの処理については、troubleshooting guide for unrecognized barcodes を参照してください。

バーコードの読み取りを向上させるために画像の明るさを調整するにはどうすればよいですか?

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

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

Blurry UPC barcode sample showing default brightness level before filter enhancement
低い明るさまたは低画質を示す、製品番号 4902030187590 付きのぼやけたバーコード

バーコード画像を強調するためにコントラスト フィルターを使用するには?

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

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

デフォルトのコントラストフィルター設定を示す、数字 4902030187590 付きのぼやけたバーコード
低コントラストの画質を示す、数字 4902030187590 付きのぼやけたバーコード

いつ反転フィルタを使用すべきですか?

このフィルタは、画像内の色を反転させ、白が黒に、黒が白になるように反対色にします。背景色のある BarCode 画像を読み取るときに特に便利です。 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

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

数字 480203187590 を示すぼやけた UPC バーコード - 反転フィルター適用前の元画像
数字の並び 4902030187590 とともに、暗い背景に白い棒を示すぼやけた反転バーコード

鮮明化フィルタを使用して、ぼやけた BarCode 画像を修正するにはどうすればよいですか?

IronBarcodeはシャープフィルターを提供します。 このフィルターは画像のシャープネスを強化し、ぼやけた画像を処理する際に非常に有用です。 このフィルタを操作して、フィルタオブジェクトをインスタンス化するときにシグマ値を調整することで、画像のシャープネスを調整します。 デフォルト値は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

下の画像は、サンプル入力画像のシャープバージョンです。

シャープ化フィルター適用前の非シャープな品質を示す、ぼやけたバーコード画像
画質低下の影響を示す、ぼやけたバーコードの例

上の画像と元の画像を比較すると、より鮮明に表示され、IronBarcodeを使用したバーコードの読み取りに役立ちます。 ほとんどのケースで、ImageFilterCollectionクラスの他のフィルターと組み合わせて使用されます。

エロード フィルターは何に使用されますか?

ErodeFilterは、形状の端にある画素を除去して、微細な白ノイズを除去し、バーコードの棒を太くします。このフィルターは、バーコードの背景に多くの白い斑点がある場合、またはバーコード画像が低解像度すぎるかぼやけてしまっている場合に、結合した棒が生成される状況での使用に最適です。 ErodeFilterは、背景の白い斑点を除去しながら、棒を太くします。 不完全な画像の処理については、不完全なバーコードの例を参照してください。

フィルターの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");
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")
$vbLabelText   $csharpLabel
数字 4002030187590 を示すぼやけたバーコード - 収縮フィルターのデモンストレーションの例
数字コード付きの黒と白の縦縞を示す、ぼやけたバーコード

上の入力画像と出力画像を比較すると、フィルタリングに大きなカーネル・サイズを入力したため、いくつかのバーが目に見えて太くなっています。 ただし、全体的な画像の白斑点は減少しました。 エロージョンフィルターの性質上、カーネルサイズが大きくなると、上の写真のように、強引に適用しすぎると細いバーを消してしまう可能性があります。 カーネルサイズの値をErodeFilterに入力して、効果をテストし精緻化します。

ディレート フィルターは BarCode 読み取りにどのように役立ちますか?

ErodeFilterの反対の機能を持ち、主に背景である明るい領域を拡大することによって物体の境界にピクセルを追加します。 このフィルタは、小さなギャップを埋めたり、低コントラスト領域を強調したりすることで、損傷したバーコードや淡いバーコードを修復しますが、バーコードバーへの効果は直感とは異なることに注意してください。 ディレーションは明るいスペースを拡大するため、(背景が白であると仮定した場合)黒いBarCodeバーのような暗い要素は間接的に薄くなります。 これは、非常に太いまたは合併したバーコードバーが現れる場面で特に効果的であり、過剰な使用はバーを細くしすぎてスキャン精度を低下させる可能性があります。

上記と同様に、フィルターの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");
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")
$vbLabelText   $csharpLabel
数字 4902030187590 を示すぼやけたバーコード画像 - 膨張フィルター処理の例
縦棒の下に数字の並びがある、ぼやけたバーコード

上記の画像に表示されているように、攻撃的な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");
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")
$vbLabelText   $csharpLabel
ヒストグラム均等化フィルターのテスト画像として使用される、数字 4902030187590 付きのぼやけたバーコード
数字 4902030187590 が表示された黒と白の縦縞のバーコード

上の画像に示されているように、元の画像と比較して、黒いバーが目に見えて暗くなり、スペースが目に見えて明るくなっています。

バーコードのノイズ除去に役立つぼかしフィルタはどれですか?

ガウスぼかしフィルタはどのように画像のノイズを減らしますか?

GaussianBlurFilterは、画像にガウスぼかしを適用します。 このフィルタは、一般的に画像のノイズを低減します。 不完全な BarCode を扱うための包括的なガイドについては、image orientation correction tutorial を参照してください。

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

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

デフォルトの3.0であり、中程度のぼかしを生成します。 Sigma値を増やすと、ぼかし効果が強くなります。 近隣のサイズを制御するためにkernelをカスタマイズし、ぼかしフィルターが平均化することもできます。

: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

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

低画質を示す、数字 4902030187590 付きのぼやけたバーコード
ガウシアンぼかしフィルターを適用したバーコード画像。ぼやけた縦線と歪んだ数字が表示されている

バイラテラル・フィルターはいつ使うべきですか?

BilateralFilterは、縁を残しながら画像をスムージングします。 すべてのピクセルに一様に影響を与える単純なぼかし技術とは異なり、バイラテラル・フィルターは色の違いとピクセルの距離の両方を考慮するため、エッジを維持したスムージングに効果的です。

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

  • 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

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

縦線と数字 4902030187590 を伴う低画質を示す、ぼやけたバーコード
低画質を示す、数字 4902030187590 付きのぼやけたバーコード

ノイズ除去におけるMedianBlurフィルターの違いは何ですか?

MedianBlurFilterは、各ピクセルの値を周囲のピクセルの中央値の値に置き換えることにより、画像のノイズを低減します。 このフィルタは、ノイズを除去しながらエッジを保持することに特に優れています。BarCode 読み取り設定の詳細については、バーコードリーダー設定ガイドをご覧ください。

  • KernelSize: メディアン計算のための近隣のサイズ (奇数でなければならない、デフォルト: 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

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

デジタルアーティファクトと読み取りやすさの低下を伴う低画質を示す、ぼやけたバーコードの例
メディアンぼかしフィルターを適用したバーコード。ぼやけた縦線と数字 4902030187590 が表示されている

処理ステップごとにフィルタリングされた画像を保存するにはどうすればよいですか?

バーコードに複数のフィルタを適用する場合、各フィルタメソッド後の出力を表示することは困難です。 この機能は各フィルターが適用される順序でフィルターを適用した後、フィルターされた画像を保存します。 この機能を有効にするには、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

フィルターはコードの順序で適用され、出力画像は各反復の結果を反映します:

  • Sharpen -> Sharpen
  • Sharpen + AdaptiveThreshold -> AdaptiveThreshold
  • Sharpen + AdaptiveThreshold + Contrast -> Contrast
数字 4902030187590 付きのぼやけたバーコード
Blurry UPC barcode showing number 4902030187590
数字 9020301875905 付きの低画質を示す、劣化したバーコードの例
UPC 番号 902030187590 付きの、著しくピクセル化したバーコード

BarcodeReaderOptionsに他のプロパティを追加してより正確な読み取りを行います; 詳細については、この記事を参照してください。

よくある質問

画像補正フィルタとは何ですか?また、なぜバーコードの読み取りに必要なのですか?

IronBarcodeの画像補正フィルターは、不鮮明または不完全なバーコード画像をプログラムで補正する組み込みツールです。画質の悪さはバーコードの読み取りを成功させない主な要因の一つであるため、必要不可欠なものです。IronBarcodeはSharpenFilterやContrastFilterなどのフィルターを提供し、外部の画像編集ソフトウェアや画像の再キャプチャを必要とせずに読み取り精度を向上させます。

バーコードスキャニングを向上させるために画像補正フィルタを適用する方法を教えてください。

IronBarcodeでフィルタを適用するには、ImageFilterCollectionインスタンスを作成し、そこに個々のフィルタインスタンスを追加します。次に、このコレクションをBarcodeReaderOptionsのImageFiltersプロパティに割り当て、Readメソッドに渡します。例えば: new BarcodeReaderOptions { ImageFilters = new ImageFilterCollection() { new SharpenFilter(3.5f), new ContrastFilter(2.0f) }.}.

不鮮明なバーコード画像にはどの画像フィルタが推奨されますか?

ぼやけたバーコード画像には、IronBarcodeは少なくともSharpenFilterとContrastFilterを使用することをお勧めします。SharpenFilterはぼやけた画像のエッジを強調し、ContrastFilterは明るい部分と暗い部分の区別を改善します。これらのフィルタを併用することで、外部で画像処理を行わなくてもバーコードの可読性を高めることができます。

画像補正フィルターの強さをカスタマイズできますか?

はい、IronBarcodeでは各フィルターにカスタム値を設定することができます。例えば、SharpenFilterはシャープネス強度を制御するためのfloatパラメータ(3.5fなど)を受け付け、ContrastFilterはコントラストレベルを調整するためのパラメータ(2.0fなど)を受け付けます。このようにカスタマイズすることで、さまざまな画像条件に対してフィルタの効果を最適化することができます。

バーコード画像を向上させるには、外部の画像編集ツールが必要ですか?

いいえ、IronBarcodeは組み込みの画像補正フィルターを提供することで、外部の画像編集ツールの必要性を排除します。SharpenFilterやContrastFilterのようなこれらのプログラムフィルタは、.NETアプリケーション内で直接画質を向上させることができ、時間を節約し、サードパーティのソフトウェアへの依存を避けることができます。

IronBarcodeをバーコード操作に使用するメリットは何ですか?

IronBarcodeは、統合の容易さ、多数のバーコード形式サポート、高品質の画像生成、強力な読み取り能力などのメリットを提供し、C#での総合的なバーコード操作ツールとなります。

IronBarcodeはバーコードの外観カスタマイズをサポートしていますか?

はい、IronBarcodeはカラー、サイズ、テキスト注釈を含むバーコードの外観に関する詳細なカスタマイズオプションを提供し、特定のデザイン要件に合わせて調整が可能です。

IronBarcodeはビジネスプロセスの効率向上にどのように役立ちますか?

IronBarcodeは迅速かつ正確なバーコード生成と読み取りを可能にし、手動データ入力エラーの減少、在庫および資産追跡の改善などにより、ビジネスプロセスの効率を向上させます。

プロジェクトにIronBarcodeを実装するために必要なプログラミングスキルは何ですか?

IronBarcodeをプロジェクトに実装するためには、C#プログラミングの基本的な知識があれば十分で、開発者をガイドするための簡単なメソッドと包括的なドキュメントが提供されています。

IronBarcodeは小規模プロジェクトと大規模エンタープライズアプリケーションの両方に適していますか?

IronBarcodeはスケーラブルかつ多用途に設計されており、小規模プロジェクトおよび強力なバーコードソリューションを必要とする大規模エンタープライズアプリケーションの両方に適しています。

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

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package BarCode
サンプルを実行する 文字列が BarCode になるのを見る。