Search Results for

    Show / Hide Table of Contents

    Class AdaptiveThresholdFilter

    A filter to apply adaptive thresholding to an image.

    Inheritance
    System.Object
    AdaptiveThresholdFilter
    Implements
    IImageFilter
    Namespace: IronBarCode
    Assembly: IronBarCode.dll
    Syntax
    public class AdaptiveThresholdFilter : Object, IImageFilter

    When a barcode image has uneven lighting, glare, or a shadow falling across part of the frame, a single global cutoff cannot cleanly separate the bars from the background, and AdaptiveThresholdFilter is the preprocessing step that handles it. It applies a Bradley adaptive threshold, computing a local cutoff for each region of the image rather than one value for the whole picture, so a barcode that is bright on one side and dim on the other still binarizes into clean black bars on a white field. This is the filter to reach for on photos and scans with non-uniform illumination, where a plain binary threshold would lose part of the code.

    The filter is one of the IImageFilter implementations that go into the ImageFilterCollection assigned to BarcodeReaderOptions.ImageFilters. The reader applies the filters in collection order before it attempts decoding, so an adaptive threshold typically sits early in the pipeline, ahead of a sharpen or contrast pass, because it produces the clean two-tone image those later steps refine. A developer constructs the filter, adds it to the collection, and passes the options to BarcodeReader.Read along with the source image.

    Several constructors trade off convenience against control. The parameterless form uses tuned defaults, while overloads accept a Threshold, the Lower and Upper replacement colors, and a Rectangle that confines the operation to a region of interest. The Threshold property sets the sensitivity of the local comparison, Lower and Upper choose the two output colors the pixels collapse to, and Rectangle restricts the filter to part of the frame when only one zone needs correcting. Tune Threshold first; the defaults already suit most documents with patchy lighting.

    using IronBarCode;
    
    var options = new BarcodeReaderOptions
    {
        ImageFilters = new ImageFilterCollection { new AdaptiveThresholdFilter() }
    };
    var results = BarcodeReader.Read("uneven-lighting.png", options);

    The image correction how-to walks through each filter on a sample barcode, and the imperfect barcode example shows a full read of a low-quality image. For images that are also skewed or rotated, the image orientation correction how-to is the companion guide.

    Constructors

    AdaptiveThresholdFilter()

    Initializes a new instance of the AdaptiveThresholdFilter class.

    Declaration
    public AdaptiveThresholdFilter()

    AdaptiveThresholdFilter(Color, Color, Single)

    Initializes a new instance of the AdaptiveThresholdFilter class.

    Declaration
    public AdaptiveThresholdFilter(Color upper, Color lower, float threshold)
    Parameters
    Type Name Description
    IronSoftware.Drawing.Color upper

    The color to use for pixels that are above the threshold.

    IronSoftware.Drawing.Color lower

    The color to use for pixels that are below the threshold.

    System.Single threshold

    Threshold limit (0.0-1.0) to consider for binarization.

    AdaptiveThresholdFilter(Single)

    Initializes a new instance of the AdaptiveThresholdFilter class.

    Declaration
    public AdaptiveThresholdFilter(float threshold)
    Parameters
    Type Name Description
    System.Single threshold

    Threshold limit (0.0-1.0) to consider for binarization.

    AdaptiveThresholdFilter(Single, Color, Color, Rectangle)

    Initializes a new instance of the AdaptiveThresholdFilter class.

    Declaration
    public AdaptiveThresholdFilter(float threshold, Color upper, Color lower, Rectangle rectangle)
    Parameters
    Type Name Description
    System.Single threshold

    Threshold limit (0.0-1.0) to consider for binarization.

    IronSoftware.Drawing.Color upper

    The color to use for pixels that are above the threshold.

    IronSoftware.Drawing.Color lower

    The color to use for pixels that are below the threshold.

    IronSoftware.Drawing.Rectangle rectangle

    Rectangular region to apply the threshold.

    AdaptiveThresholdFilter(Single, Rectangle)

    Initializes a new instance of the AdaptiveThresholdFilter class.

    Declaration
    public AdaptiveThresholdFilter(float threshold, Rectangle rectangle)
    Parameters
    Type Name Description
    System.Single threshold

    Threshold limit (0.0-1.0) to consider for binarization.

    IronSoftware.Drawing.Rectangle rectangle

    Rectangular region to apply the adaptive threshold.

    Properties

    Lower

    The color to use for pixels that are below the threshold. Default = Black.

    Declaration
    public Color Lower { get; set; }
    Property Value
    Type Description
    IronSoftware.Drawing.Color

    Rectangle

    Rectangle region to apply the filter on.

    Declaration
    public Rectangle Rectangle { get; set; }
    Property Value
    Type Description
    IronSoftware.Drawing.Rectangle

    Threshold

    Threshold limit (0.0-1.0) to consider for binarization. Default = 1.0.

    Declaration
    public float Threshold { get; set; }
    Property Value
    Type Description
    System.Single

    Upper

    The color to use for pixels that are above the threshold. Default = White.

    Declaration
    public Color Upper { get; set; }
    Property Value
    Type Description
    IronSoftware.Drawing.Color

    Implements

    IImageFilter
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget
    IronBarcode_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronBarcode