IRONSOFTWAREHOME

Using C# Image Correction Filters to Improve Barcode Decoding

Hairil Hasyimi Bin Omar
Hairil Hasyimi Bin Omar
Updated: August 2, 2026

IronBarcode provides built-in image correction filters like SharpenFilter and ContrastFilter that programmatically enhance blurry or imperfect barcode images, improving reading accuracy without needing external image editing software or recapturing images.

Not every image is perfect, and poor image quality is one of the main factors preventing successful barcode reads in IronBarcode. Rather than recapturing images or using external image enhancement software, IronBarcode provides built-in filters that programmatically improve image quality. These filters help IronBarcode read difficult images and improve overall accuracy.

Continue reading to learn about available image correction filters in IronBarcode, their effects on images, and how to apply them. For more comprehensive barcode reading techniques, check our Reading Barcodes tutorial.

Quickstart: Apply Sharpen and Contrast Filters to Improve Barcode Readings

In just one step, apply IronBarcode's SharpenFilter and ContrastFilter using the ImageFilterCollection in BarcodeReaderOptions. This improves barcode scanning with minimal setup and zero need for external tools.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy 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) } });
    C#
  3. 3Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer

How Do I Apply Image Filters to Improve Barcode Reading?

To apply filters, instantiate the ImageFilterCollection class and create instances of each filter individually. Then assign the object to the ImageFilters property of the BarcodeReaderOptions object. Pass the options object into the Read method along with the sample image. For advanced installation options, visit our NuGet packages guide.

Use the image below as our sample image.

Blurred barcode with number 4900203187590 showing poor image quality before filtering enhancement

The image appears quite blurry. However, the brightness is acceptable, and the white and black colors are distinguishable. Therefore, apply at least the SharpenFilter and ContrastFilter to improve barcode readability. Refer to the code snippet below to apply filters to the image, read it, and display results on the console.

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);
}

The code snippet above applies filters, reads the barcode, and exports the filtered image to disk. The comparison between the sample and filtered images is shown below.

Blurry barcode image with number 4902030187590 demonstrating poor image quality
Barcode with improved readability after applying image filters, showing clear vertical lines and number 4902030187590

What Image Correction Filters Are Available in IronBarcode?

IronBarcode offers multiple image filters specifically designed for image correction. These filters assist in reading imperfect barcode images and enhancing reading accuracy. However, understand how these filters work to select suitable filters and avoid performance issues from using too many filters or using the wrong filter. Available filters include:

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

The order in which filters are applied is based on their placement inside the ImageFilterCollection. For detailed API documentation on these filters, visit our API Reference.

How Does the Adaptive Threshold Filter Work?

AdaptiveThresholdFilter is a filter available in IronBarcode that applies Bradley Adaptive Threshold technique to the image, which automatically determines the threshold for binarizing an image. This filter is ideal for images with non-uniform illumination and varying background intensity levels.

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");

Below are the outputs of applying the filter using different values.

Vertical lines showing different adaptive threshold filter outputs with solid and dashed patterns
Low-quality barcode image showing UPC number 902030187590 with significant visual distortion

The constructor accepts additional parameters for configuration:

  • Upper: Upper (white) color for thresholding.
  • Lower: Lower (black) color for thresholding.
  • Threshold: Threshold limit (0.0-1.0) for binarization.
  • Rectangle: Rectangle region to apply the processor on.

As shown in the output image above, the image is binarized to only have black and white colors. While it still does not seem ideal for barcode reading, filters need to be used in combinations. Experiment with the parameter sensitivity to achieve the best results.

How Does the Binary Threshold Filter Work?

The BinaryThresholdFilter filters an image by splitting the pixels at the given threshold, comparing the luminance of a color component. Similar to the AdaptiveThresholdFilter, this filter can introduce new or unwanted noise if not used correctly. However, IronBarcode has set default values for the filter properties.

Similar to the AdaptiveThresholdFilter, the BinaryThresholdFilter accepts the same additional parameters for configuration:

  • Upper: Upper (white) color for thresholding.
  • Lower: Lower (black) color for thresholding.
  • Threshold: Threshold limit (0.0-1.0) for binarization.
  • Rectangle: Rectangle region to apply the processor on.
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");

Below is the sample output of applying filters to the sample image.

Three examples of binary threshold filter outputs showing sparse, dotted, and dense vertical line patterns
Barcode image processed with 0.9 binary threshold filter showing black and white contrast

Observing the output image above, the sample has been binarized into black and white color. However, this filter is clearly not suitable for this image due to barcode bars being eliminated and new noise being introduced. For handling difficult barcode scenarios, refer to our troubleshooting guide for unrecognized barcodes.

How Do I Adjust Image Brightness for Better Barcode Reading?

BrightnessFilter is another essential filter in the image filter collection in IronBarcode. As the name suggests, this filter adjusts the brightness of the barcode image. The input to this constructor varies the Amount of brightness in the output image. The default value is 1, which leaves the image unchanged. A value of 0 creates a completely black image, while values above 1 make the image brighter.

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");

Below is the output image after applying this filter to the sample input.

Blurry UPC barcode sample showing default brightness level before filter enhancement
Blurry barcode with product number 4902030187590, demonstrating low brightness or poor image quality

How Do I Use the Contrast Filter to Enhance Barcode Images?

The ContrastFilter adjusts the level of contrast in an image. Image contrast refers to the difference in color intensity between various elements in an image. Increasing the level of contrast enhances the visibility of details, making the image appear vivid and striking, while reducing contrast makes the image appear softer and more subdued. For more details on barcode customization, see our guide on customizing barcode styles.

The default value is 1, which leaves the image unchanged. A value of 0 creates a completely gray image, while values above 1 increase the image contrast.

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");

Applying this filter to the sample input produces the image below.

Blurry barcode with number 4902030187590 demonstrating default contrast filter settings
Blurry barcode with number 4902030187590 demonstrating low contrast image quality

When Should I Use the Invert Filter?

This filter inverts the colors inside an image, making opposite colors, such as white becomes black and black becomes white. It's particularly useful when reading a barcode image with a background color. Unlike the BinaryThresholdFilter, this filter inverts the colors directly without needing to specify sensitivity. Moreover, this filter can be used with a CropRectangle to specify the location in the image that needs the color inverted, instead of inverting colors for the entire image. Learn more about specifying crop regions in our crop region tutorial.

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");

The output image below is the result of applying this filter to the sample input image.

Blurry UPC barcode showing number 480203187590 - original image before invert filter application
Blurry inverted barcode showing white bars on dark background with number sequence 4902030187590

How Do I Fix Blurry Barcode Images with the Sharpen Filter?

IronBarcode provides a sharpening filter. This filter enhances the sharpness of an image and is very useful when dealing with blurry images. Manipulate this filter to adjust the sharpness of an image by adjusting the Sigma value when instantiating the filter object. The default value is 3. Increase the sigma value to increase the image sharpness. For other performance optimization options, check our guide on reading speed options.

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");

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

Blurry barcode image demonstrating unsharpened quality before applying sharpen filter
Blurred barcode example showing effects of image quality degradation

Comparing the image above with the original image, it appears sharper and helps in barcode reading using IronBarcode. In most cases, SharpenFilter is always applied together with other filters in the ImageFilterCollection class.

What Is the Erode Filter Used For?

The ErodeFilter removes tiny white noise and thickens barcode bars by removing pixels near the edge of shapes. This filter is best used in scenarios where the barcode background has lots of white speckles or if the barcode image is too low resolution or blurred, resulting in merged bars. The ErodeFilter makes bars thicker while removing white specks in the background. For more information on handling imperfect images, see our imperfect barcode example.

Increase the erosion's effect by inputting an integer representing kernelSize for the filter. The bigger the kernel size, the stronger the effect on the input image. Note that the kernelSize is a square and in this example would be a 5x5 kernel.

As an example, use the ErodeFilter with a larger kernel size to showcase the filter's effects.

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");
Blurry barcode showing number 4002030187590 - example for erode filter demonstration
Blurred barcode showing vertical black and white stripes with numerical code

Comparing the input and output images above, some bars are visibly thicker due to the more aggressive nature of inputting a larger kernel size to filter. However, the white speckles in the overall picture have decreased. By nature of the erosion filter, the larger the kernel size, you might erase thin bars if applied too aggressively, as shown in the picture above. Test and refine the effect by changing the kernel size value input to the ErodeFilter.

How Does the Dilate Filter Help with Barcode Reading?

The DilateFilter functions as the inverse of the ErodeFilter, operating by expanding bright regions - typically the background - through the addition of pixels to object boundaries. While this filter repairs damaged or faint barcodes by filling in small gaps or enhancing low-contrast areas, note that its effect on barcode bars differs from intuition. Since dilation enlarges bright spaces, it indirectly thins out dark elements such as black barcode bars (assuming a white background). This makes the filter particularly effective in scenarios where barcode bars appear overly thick or merged, but excessive use can degrade scan accuracy by excessively narrowing the bars.

Similar to above, increase the filter's effect by inputting an integer representing the kernelSize for the filter.

For the example below, use a larger kernel size to showcase the effects of the 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");
Blurry barcode image showing number 4902030187590 - example for dilate filter processing
Blurred barcode with numerical sequence below vertical bars

As shown in the image above, aggressive use of DilateFilter can potentially destroy the barcode structure, merging closely spaced bars and creating quiet zones in the barcodes. Test and refine the effects on the image by changing the kernel size value to be larger or smaller, depending on the input image.

When Should I Use the HistogramEqualization Filter?

The HistogramEqualizationFilter enhances image contrast by redistributing pixel intensities to improve clarity. It is most commonly used when the barcode has either low contrast, such as faded or washed out images, or images with uneven lighting, such as dark shadows or bright glare. By analyzing the image histogram, which is the distribution of pixel brightness, it redistributes the pixel values by boosting contrast by stretching the intensity range, where dark pixels become darker and light pixels become lighter.

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");
Blurry barcode with number 4902030187590 used as test image for histogram equalization filter
Barcode with vertical black and white stripes showing number 4902030187590

As shown in the image above, the black bars are visibly darker, and the spaces are visibly brighter compared to the original image.

Which Blur Filters Can Help with Barcode Noise Reduction?

How Does GaussianBlur Filter Reduce Image Noise?

The GaussianBlurFilter applies a Gaussian blur to an image. This filter commonly reduces noise in an image. For a comprehensive guide on dealing with imperfect barcodes, refer to our image orientation correction tutorial.

The filter works by averaging neighboring pixel values in the image using a Gaussian function. The method relies on two adjustable factors:

  • Kernel: a matrix used for averaging the pixels.
  • Sigma: a value controlling the blur intensity.

The default kernel size is 3x3 pixels, and the default Sigma value is 3.0, producing a moderate blur. Increasing the Sigma value results in a stronger blur effect. You can also customize the kernel to control the size of the neighborhood that the blur filter averages.

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");

Applying this filter to the sample input produces the image below.

Blurry barcode with number 4902030187590 demonstrating poor image quality
Barcode image with Gaussian blur filter applied, showing blurred vertical lines and distorted numbers

When Should I Use the Bilateral Filter?

The BilateralFilter smooths images while preserving edges. Unlike simple blur techniques affecting all pixels uniformly, the Bilateral Filter takes both color differences and pixel distance into account, making it effective for edge-preserving smoothing.

The method relies on three adjustable factors:

  • NeighborhoodDiameter: Diameter of pixel neighborhood (default: 5).
  • SigmaColor: Color influence determining color difference impact (default: 75.0).
  • SigmaSpace: Spatial influence determining distance impact (default: 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");

Applying this filter to the sample input produces the image below.

Blurred barcode demonstrating poor image quality with vertical lines and numbers 4902030187590
Blurred barcode with numbers 4902030187590 demonstrating poor image quality

What Makes MedianBlur Filter Different for Noise Reduction?

The MedianBlurFilter reduces noise in an image by replacing each pixel's value with the median value of the surrounding pixels. This filter particularly excels at preserving edges while removing noise. To explore more about barcode reading settings, visit our barcode reader settings guide.

  • KernelSize: Size of neighborhood for median calculation (must be odd, default: 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");

Applying this filter to the sample input produces the image below.

Blurry barcode example showing poor image quality with digital artifacts and reduced readability
Barcode with median blur filter applied showing blurred vertical lines and number 4902030187590

How Can I Save Filtered Images at Each Processing Step?

When applying multiple filters to the barcode, viewing the output after each filter method can be difficult. This feature allows saving the filtered image after each filter is applied, in the order they are processed. To enable this feature, first pass true to the ImageFilterCollection constructor. Then use the ExportFilterImagesToDisk method to provide the path and name for the output images. For more examples on saving barcodes, see our convert barcode to image example.

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");

The filters are applied in the order of the code, and the output images reflect the results of each iteration:

  • Sharpen -> After Sharpen
  • Sharpen + AdaptiveThreshold -> After AdaptiveThreshold
  • Sharpen + AdaptiveThreshold + Contrast -> After Contrast
Blurry barcode with number 4902030187590
Blurry UPC barcode showing number 4902030187590
Degraded barcode example showing poor image quality with number 9020301875905
Heavily pixelated barcode with UPC number 902030187590

Apart from the ImageFilters properties, add other properties to BarcodeReaderOptions for more accurate reading; see this article for more information.

Frequently Asked Questions

What image correction filters are available in IronBarcode?

IronBarcode offers a variety of image correction filters such as SharpenFilter, ContrastFilter, AdaptiveThresholdFilter, BinaryThresholdFilter, BrightnessFilter, InvertFilter, ErodeFilter, DilateFilter, HistogramEqualizationFilter, and several Blur filters including GaussianBlurFilter, BilateralFilter, and MedianBlurFilter. These filters enhance barcode reading accuracy by improving image quality.

How do I apply the Sharpen and Contrast filters in IronBarcode?

To apply the Sharpen and Contrast filters in IronBarcode, instantiate the ImageFilterCollection class with these filters and assign it to the ImageFilters property of a BarcodeReaderOptions object. Pass this options object to the Read method along with the image to enhance barcode readability.

What is the purpose of the Adaptive Threshold Filter?

The Adaptive Threshold Filter uses the Bradley Adaptive Thresholding technique to automatically determine thresholds for binarizing an image, which is particularly useful for images with non-uniform illumination and varying background intensities.

How does the Invert Filter work?

The Invert Filter inverts the colors of an image, converting white to black and vice versa, which is beneficial for barcode images with a background color. It can be applied to the entire image or specified sections using CropRectangle.

What is the effect of the Erode Filter on barcode images?

The Erode Filter thickens barcode bars by removing pixels near the edges, which reduces white noise in the background. It is useful for low-resolution or blurred images but may require careful adjustment to avoid erasing thin bars.

When should I use the HistogramEqualization Filter?

The HistogramEqualization Filter enhances contrast by redistributing pixel intensities, making it suitable for barcodes with low contrast or uneven lighting. This filter stretches the intensity range to improve readability.

What does the GaussianBlur Filter do?

The GaussianBlur Filter reduces noise in an image by averaging pixel values using a Gaussian function. It is configurable via kernel size and sigma value, and it applies a moderate blur to help reduce image noise.

How does the Bilateral Filter differ from other blur filters?

The Bilateral Filter reduces noise while preserving edges and takes into account both color differences and pixel distance. It smooths images by considering neighborhood diameter, sigma color, and sigma space parameters.

What is the primary use of the MedianBlur Filter?

The MedianBlur Filter excels at preserving edges while minimizing noise by replacing each pixel's value with the median of its neighbors, making it effective for noise reduction with edge preservation.

How can I save images after each filter is applied in IronBarcode?

In IronBarcode, enable exporting images after each filter step by passing true to the ImageFilterCollection constructor, then use the ExportFilterImagesToDisk method to save the output images at each processing step.

Ready to Get Started?

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

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

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