How to use Image Correction Filters For Barcode Using C#

Using C# Image Correction Filters to Improve Barcode Decoding

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.

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

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.

: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

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.

: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

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.
: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

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.

: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

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.

: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

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.

: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

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.

: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

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.

: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
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.

: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
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.

: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
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.

: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

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).
: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

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).
: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

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.

: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

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 are image correction filters and why are they needed for barcode reading?

Image correction filters in IronBarcode are built-in tools that programmatically enhance blurry or imperfect barcode images. They're essential because poor image quality is one of the main factors preventing successful barcode reads. IronBarcode provides filters like SharpenFilter and ContrastFilter that improve reading accuracy without requiring external image editing software or recapturing images.

How do I apply image correction filters to improve barcode scanning?

To apply filters in IronBarcode, create an ImageFilterCollection instance and add individual filter instances to it. Then assign this collection to the ImageFilters property of BarcodeReaderOptions and pass it to the Read method. For example: new BarcodeReaderOptions { ImageFilters = new ImageFilterCollection() { new SharpenFilter(3.5f), new ContrastFilter(2.0f) } }.

Which image filters are recommended for blurry barcode images?

For blurry barcode images, IronBarcode recommends using at least the SharpenFilter and ContrastFilter. The SharpenFilter enhances edge definition in blurry images, while the ContrastFilter improves the distinction between light and dark areas. These filters work together to make barcodes more readable without external image processing.

Can I customize the strength of image correction filters?

Yes, IronBarcode allows you to configure each filter with custom values. For example, SharpenFilter accepts a float parameter (like 3.5f) to control sharpening intensity, and ContrastFilter accepts a parameter (like 2.0f) to adjust contrast levels. This customization helps optimize filter effectiveness for different image conditions.

Do I need external image editing tools to enhance barcode images?

No, IronBarcode eliminates the need for external image editing tools by providing built-in image correction filters. These programmatic filters like SharpenFilter and ContrastFilter can enhance image quality directly within your .NET application, saving time and avoiding dependencies on third-party software.

Hairil Hasyimi Bin Omar
Software Engineer
Like all great engineers, Hairil is an avid learner. He’s refining his knowledge of C#, Python, and Java, using that knowledge to add value to team members across Iron Software. Hairil joined the Iron Software team from Universiti Teknologi MARA in Malaysia, where he graduated with a Bachelor's degree ...
Read More
Ready to Get Started?
Nuget Downloads 2,002,059 | Version: 2025.12 just released