Class ContrastFilter
A filter to adjust image contrast.
Inheritance
Implements
Namespace: IronBarCode
Assembly: IronBarCode.dll
Syntax
public class ContrastFilter : Object, IImageFilter
ContrastFilter widens the difference in intensity between the light and dark regions of a barcode image, the correction for a washed-out or flat photo where the bars and the background sit too close in tone for a reliable read. Pushing the contrast up makes the black bars darker and the white spaces lighter, sharpening the boundary a decoder keys on; pulling it down has the opposite, softening effect. It is one of the most frequently applied passes, often paired with a sharpen step.
The filter implements IImageFilter and is added to the ImageFilterCollection on BarcodeReaderOptions.ImageFilters, run in collection order before decoding. A developer constructs it, adds it to the collection, and passes the options to BarcodeReader.Read. The single Amount property controls the strength: the default value of 1 leaves the image unchanged, 0 produces a fully gray image, and values above 1 increase contrast. The single-argument constructor sets Amount at creation.
using IronBarCode;
var options = new BarcodeReaderOptions
{
ImageFilters = new ImageFilterCollection { new ContrastFilter(2.0f) }
};
var results = BarcodeReader.Read("washed-out.png", options);The image correction how-to demonstrates the contrast pass on a sample, and the imperfect barcode example reads a degraded barcode after correction.
Constructors
ContrastFilter()
Initializes a new instance of the ContrastFilter class.
Declaration
public ContrastFilter()
ContrastFilter(Single)
Initializes a new instance of the ContrastFilter class with the specified amount.
Declaration
public ContrastFilter(float amount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | amount | The proportion of the conversion. Value must be between [0, 10]. |
Properties
Amount
The proportion of the conversion. Value must be between [0, 10]. Default = 1.0.
Declaration
public float Amount { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |