ImageFilter#

The ImageFilter class provides methods to work with image filters applied a PDF document.

Method / Attribute

Short Description

ImageFilter.AutoDeskew()

Automatically detects and corrects image skew (rotation).

ImageFilter.ApplyDilation()

Applies dilation filter to correct broken letters.

ImageFilter.RemoveLines()

Removes lines from the image (either horizontal or vertical).

ImageFilter.RemoveVerticalLines()

Removes vertical lines from the image.

ImageFilter.RemoveHorizontalLines()

Removes horizontal lines from the image.

ImageFilter.CollectLines()

Detects and collects line segments from the image without removing them.

ImageFilter.ApplyMedian()

Applies median filter to reduce noise in the image.

ImageFilter.AdjustGamma()

Adjusts the gamma correction of the image.

ImageFilter.AdjustContrast()

Adjusts the contrast of the image.

ImageFilter.ApplyBlur()

Applies blur filter to the image.

ImageFilter.ToGrayscale()

Converts the image to grayscale.

ImageFilter.ApplyInvert()

Inverts the colors of the image.

ImageFilter.ScaleImage()

Scales the image by the specified factor while maintaining aspect ratio.

ImageFilter.Fit()

Scales the image to fit within the specified maximum dimension while maintaining aspect ratio.

ImageFilter.ApplyFilters()

Applies a sequence of image processing filters to the image in the order specified.

ImageFilter.EnsureColorType()

Ensures the bitmap has the specified color type and alpha type.

Class API

class ImageFilter#
ImageFilter()#

Instantiation method.

AutoDeskew(ref SKBitmap image, double minAngle = DeskewFilterOptions.DEFAULT_TILT_CORRECTION_ANGLE_THRESHOLD)#

Automatically detects and corrects image skew (rotation) using projection-based analysis.

Parameters:
  • image (SKBitmap) – The image to deskew. Will be replaced with the corrected image.

  • minAngle (double) – Minimum angle in degrees required to apply correction. Default is 0.4 degrees.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

ApplyDilation(ref SKBitmap image)#

Applies dilation filter to correct broken letters by expanding dark pixels. Useful for repairing fragmented text in scanned documents.

Parameters:

image (SKBitmap) – The image to process. Will be replaced with the processed image.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

RemoveLines(ref SKBitmap image, bool vertical)#

Removes lines from the image (either horizontal or vertical). Uses advanced algorithms to preserve text while removing table borders and separator lines.

Parameters:
  • image (SKBitmap) – The image to process. Will be replaced with the processed image.

  • vertical (bool) – True to remove vertical lines, false to remove horizontal lines.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

RemoveVerticalLines(ref SKBitmap image)#

Removes vertical lines from the image (table borders, separators, etc.).

Parameters:

image (SKBitmap) – The image to process. Will be replaced with the processed image.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

RemoveHorizontalLines(ref SKBitmap image)#

Removes horizontal lines from the image (table borders, separators, etc.).

Parameters:

image (SKBitmap) – The image to process. Will be replaced with the processed image.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

CollectLines(ref SKBitmap image)#

Detects and collects line segments from the image without removing them. Returns both horizontal and vertical line segments found in the image.

Parameters:

image (SKBitmap) – The image to analyze.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

A tuple containing lists of horizontal and vertical line segments.

Return type:

(List<LineRemover.Segment> Horizontal, List<LineRemover.Segment> Vertical)

CollectLines(ref SKBitmap image, ref List<LineRemover.Segment> horizontal, ref List<LineRemover.Segment> vertical)#

Detects and collects line segments from the image into provided lists.

Parameters:
  • image (SKBitmap) – The image to analyze.

  • horizontal (List<LineRemover.Segment>) – List to populate with horizontal line segments. Will be created if null.

  • vertical (List<LineRemover.Segment>) – List to populate with vertical line segments. Will be created if null.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies horizontal and vertical lists in place via ref parameters)

ApplyMedian(ref SKBitmap image, int kernelSize = 3)#

Applies median filter to reduce noise in the image. Each pixel is replaced with the median value of its neighboring pixels.

Parameters:
  • image (SKBitmap) – The image to process. Will be replaced with the processed image.

  • kernelSize (int) – Size of the median filter kernel (must be odd). Default is 3.

Raises:
  • ArgumentNullException – Thrown when image is null.

  • ArgumentOutOfRangeException – Thrown when kernelSize is not positive.

Returns:

None (modifies image in place via ref parameter)

Note

If kernelSize is even, it will be automatically incremented by 1 to make it odd.

AdjustGamma(ref SKBitmap image, double gamma)#

Adjusts the gamma correction of the image. Gamma values less than 1.0 darken the image, values greater than 1.0 brighten it.

Parameters:
  • image (SKBitmap) – The image to process. Will be replaced with the processed image.

  • gamma (double) – Gamma correction value. Must be greater than zero. 1.0 means no change.

Raises:
  • ArgumentNullException – Thrown when image is null.

  • ArgumentOutOfRangeException – Thrown when gamma is not greater than zero.

Returns:

None (modifies image in place via ref parameter)

AdjustContrast(ref SKBitmap image, int contrastLevel)#

Adjusts the contrast of the image. Requires RGB color format. The image will be converted if necessary.

Parameters:
  • image (SKBitmap) – The image to process. Will be replaced with the processed image.

  • contrastLevel (int) – Contrast adjustment from -100 to +100. 0 means no change.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

True if the operation succeeded, false if the image format is not supported.

Return type:

bool

ApplyBlur(ref SKBitmap image, int blurZoneSize)#

Applies blur filter to the image using a box blur algorithm. Requires RGB color format. The image will be converted if necessary.

Parameters:
  • image (SKBitmap) – The image to process. Will be replaced with the processed image.

  • blurZoneSize (int) – Size of the blur zone (1-10). Larger values create more blur.

Raises:
  • ArgumentNullException – Thrown when image is null.

  • ArgumentOutOfRangeException – Thrown when blurZoneSize is less than 1.

Returns:

None (modifies image in place via ref parameter)

ToGrayscale(ref SKBitmap image)#

Converts the image to grayscale using standard RGB weights (0.299R + 0.587G + 0.114B).

Parameters:

image (SKBitmap) – The image to process. Will be replaced with the grayscale image.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

ApplyInvert(ref SKBitmap image)#

Inverts the colors of the image (creates a negative effect).

Parameters:

image (SKBitmap) – The image to process. Will be replaced with the inverted image.

Raises:

ArgumentNullException – Thrown when image is null.

Returns:

None (modifies image in place via ref parameter)

ScaleImage(ref SKBitmap image, double scaleFactor, SKFilterQuality quality = SKFilterQuality.High)#

Scales the image by the specified factor while maintaining aspect ratio.

Parameters:
  • image (SKBitmap) – The image to scale. Will be replaced with the scaled image.

  • scaleFactor (double) – Scale factor (e.g., 0.5 for half size, 2.0 for double size). Must be greater than zero.

  • quality (SKFilterQuality) – Filter quality for scaling interpolation. Default is High.

Raises:
  • ArgumentNullException – Thrown when image is null.

  • ArgumentOutOfRangeException – Thrown when scaleFactor is not greater than zero.

Returns:

The new size of the scaled image.

Return type:

SKSizeI

Note

If scaleFactor is 1.0, the image remains unchanged and its current size is returned.

Fit(ref SKBitmap image, int maxDimension, SKFilterQuality quality = SKFilterQuality.High)#

Scales the image to fit within the specified maximum dimension while maintaining aspect ratio. If the image is already smaller than maxDimension, no scaling is performed.

Parameters:
  • image (SKBitmap) – The image to scale. Will be replaced with the scaled image.

  • maxDimension (int) – Maximum width or height in pixels. Must be greater than zero.

  • quality (SKFilterQuality) – Filter quality for scaling interpolation. Default is High.

Raises:
  • ArgumentNullException – Thrown when image is null.

  • ArgumentOutOfRangeException – Thrown when maxDimension is not greater than zero.

Returns:

The new size of the scaled image.

Return type:

SKSizeI

Note

The image is scaled proportionally to fit within a square of maxDimension × maxDimension pixels. If the image is already smaller than this size, it remains unchanged.

ApplyFilters(ref SKBitmap image, IEnumerable<PreprocessingFilter> filters)#

Applies a sequence of image processing filters to the image in the order specified. Each filter is applied sequentially, modifying the image in-place.

Parameters:
  • image (SKBitmap) – The image to process. Will be replaced with the processed image.

  • filters (IEnumerable<PreprocessingFilter>) – Collection of preprocessing filters to apply. Null or empty collection is ignored.

Raises:
  • ArgumentNullException – Thrown when image is null.

  • NotSupportedException – Thrown when an unsupported filter type is encountered.

Returns:

None (modifies image in place via ref parameter)

Note

Null filters within the collection are automatically skipped during processing.

Supported Filter Types:

  • Deskew: Automatically detects and corrects image skew: ImageProcessingFilterType.Deskew

  • Dilate: Expands dark pixels to repair broken letters: ImageProcessingFilterType.Dilate

  • RemoveVerticalLines: Removes vertical lines from the image: ImageProcessingFilterType.RemoveVerticalLines

  • RemoveHorizontalLines: Removes horizontal lines from the image: ImageProcessingFilterType.RemoveHorizontalLines

  • Median: Applies median filter to reduce noise: ImageProcessingFilterType.Median

  • Gamma: Adjusts gamma correction: ImageProcessingFilterType.Gamma

  • Contrast: Adjusts image contrast: ImageProcessingFilterType.Contrast

  • Grayscale: Converts image to grayscale: ImageProcessingFilterType.Grayscale

  • Invert: Inverts image colors: ImageProcessingFilterType.Invert

  • Scale: Scales image by a specified factor: ImageProcessingFilterType.Scale

  • Fit: Scales image to fit within maximum dimensions: ImageProcessingFilterType.Fit

EnsureColorType(ref SKBitmap bitmap, SKColorType colorType, SKAlphaType? alphaType = null)#

Ensures the bitmap has the specified color type and alpha type. Converts the bitmap if necessary, disposing the original and replacing it with the converted version.

Parameters:
  • bitmap (SKBitmap) – The bitmap to check and convert if needed. Will be replaced if conversion is necessary.

  • colorType (SKColorType) – The required color type.

  • alphaType (SKAlphaType?) – The required alpha type. If null, the original alpha type is preserved.

Returns:

None (modifies bitmap in place via ref parameter if conversion is needed)

Note

If the bitmap already has the specified color type and alpha type, no conversion is performed. When conversion occurs, the original bitmap is disposed and replaced with the converted version.