IRONSOFTWAREHOME
Imperfect Barcodes and Image Correction
using IronBarCode;
using IronSoftware.Drawing;

// Choose which filters are to be applied (in order)
// Set cacheAtEachIteration = true to save the intermediate image data after each filter is applied
var filtersToApply = new ImageFilterCollection(cacheAtEachIteration: true) {
    new SharpenFilter(),
    new InvertFilter(),
    new ContrastFilter(),
    new BrightnessFilter(),
    new AdaptiveThresholdFilter(),
    new BinaryThresholdFilter(),
    new GaussianBlurFilter(),
    new MedianBlurFilter(),
    new BilateralFilter()
};

BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
    // Set chosen filters in BarcodeReaderOptions
    ImageFilters = filtersToApply,

    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
};

// Read with the options applied
BarcodeResults results = BarcodeReader.Read("screenshot.png", myOptionsExample);

AnyBitmap[] filteredImages = results.FilterImages();

// Export intermediate image files to disk
for (int i = 0 ; i < filteredImages.Length ; i++)
    filteredImages[i].SaveAs($"{i}_barcode.png");

// Or
results.ExportFilterImagesToDisk("filter-result.jpg");
Imports IronBarCode
Imports IronSoftware.Drawing

' Choose which filters are to be applied (in order)
' Set cacheAtEachIteration = true to save the intermediate image data after each filter is applied
Dim filtersToApply As New ImageFilterCollection(cacheAtEachIteration:=True) From {
    New SharpenFilter(),
    New InvertFilter(),
    New ContrastFilter(),
    New BrightnessFilter(),
    New AdaptiveThresholdFilter(),
    New BinaryThresholdFilter(),
    New GaussianBlurFilter(),
    New MedianBlurFilter(),
    New BilateralFilter()
}

Dim myOptionsExample As New BarcodeReaderOptions() With {
    .ImageFilters = filtersToApply,

    .Speed = ReadingSpeed.Balanced,
    .ExpectMultipleBarcodes = True
}

' Read with the options applied
Dim results As BarcodeResults = BarcodeReader.Read("screenshot.png", myOptionsExample)

Dim filteredImages As AnyBitmap() = results.FilterImages()

' Export intermediate image files to disk
For i As Integer = 0 To filteredImages.Length - 1
    filteredImages(i).SaveAs($"{i}_barcode.png")
Next

' Or
results.ExportFilterImagesToDisk("filter-result.jpg")
NuGet Download
PM > Install-Package BarCode
Imperfect Barcodes and Image Correction

Imperfect Barcodes and Image Correction

IronBarcode offers many image pre-processing filters to choose from that are easily applied within BarcodeReaderOptions. Select the filters that may improve reading of your image such as Sharpen, Binary Threshold, and Contrast. Please keep in mind that the order in which you choose them is the order that they are applied.

There is the option of saving the image data of the intermediate images with each filter applied. This can be toggled with the CacheAtEachIteration property of ImageFilterCollection.

Key Points from the Featured Code Example:

  • We create an instance of BarcodeReaderOptions and configure it with various image filters: Sharpen, Binary Threshold, and Contrast.
  • The filters are added in a specific order, indicating the sequence in which they should be applied.
  • By setting cacheAtEachIteration to true, the library saves intermediate images after each filter application, which is useful for debugging and analysis.
  • Finally, we read the barcode from the image and print the barcode type and value to the console.
Learn More About Image Correction in IronBarcode
View on GitHub

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required