Table of contents

ImageProcessor

The ImageProcessor class provides API to crop images based on specified regions.

Definition

Assembly: dynamsoft-capture-vision-react-native

class ImageProcessor

Methods

Method Description
cropImage Crops the image (as an ImageData object) to the region defined by the rectangle.
cropAndDeskewImage Crops the image (as an ImageData object) to the region defined by the Quadrilateral.
adjustBrightness Adjusts the brightness of the image (as an ImageData object) based on the specified brightness value.
adjustContrast Adjusts the contrast of the image (as an ImageData object) based on the specified contrast value.
filterImage Applies a filter (represented with EnumFilterType) to the image (as an ImageData object).
convertToGray Converts the image (as an ImageData object) to grayscale using specified channel weights.
convertToBinaryGlobal Converts the image (as an ImageData object) to a binary (black and white) format using global thresholding.
convertToBinaryLocal Converts the image (as an ImageData object) to a binary (black and white) format using local adaptive thresholding.

cropImage

Crops the image (as an ImageData object) to the region defined by the rectangle.

cropImage(imageData: ImageData | null | undefined, rect: DSRect | null | undefined): ImageData | null | undefined

Remarks

The method returns an ImageData object that represents the newly cropped image. The method returns null if the cropping fails (invalid rectangle, out of bounds, a null ImageData object, etc.).

cropAndDeskewImage

Crops the image (as an ImageData object) to the region defined by the Quadrilateral.

cropAndDeskewImage(imageData: ImageData | null | undefined, quad: Quadrilateral | null | undefined, dstWidth: number = 0, dstHeight: number = 0, padding: number = 0): ImageData | undefined | null

Remarks

The quadrilateral input parameter defines the region to extract as four corner points. The method returns an ImageData object that represents the newly cropped image. The method returns null if the cropping fails (invalid Quadrilateral, out of bounds, a null ImageData object, etc.).

adjustBrightness

Adjusts the brightness of the image (as an ImageData object) based on the specified brightness value.

adjustBrightness(imageData: ImageData | null | undefined, brightness: number): ImageData | null | undefined

Remarks

The brightness input parameter ranges from -100 to 100. Positive values increase brightness while negative values decrease it. The method returns null if the adjustment fails.

adjustContrast

Adjusts the contrast of the image (as an ImageData object) based on the specified contrast value.

adjustContrast(imageData: ImageData | null | undefined, contrast: number): ImageData | null | undefined

Remarks

The contrast input parameter ranges from -100 to 100. Positive values increase brightness while negative values decrease it. The method returns null if the adjustment fails.

filterImage

Applies a filter (represented with EnumFilterType) to the image (as an ImageData object).

filterImage(imageData: ImageData | null | undefined, filterType: EnumFilterType): ImageData | null | undefined

Remarks

The method returns null if the filtering fails.

convertToGray

Converts the image (as an ImageData object) to grayscale using specified channel weights.

convertToGray(imageData: ImageData | null | undefined, r: number = 0.3, g: number = 0.59, b: number = 0.11): ImageData | null | undefined

Remarks

  • r: Weight of the red channel (default value is 0.3).
  • g: Weight of the green channel (default value is 0.59).
  • b: Weight of the blue channel (default value is 0.11).

The method returns null if the conversion fails.

convertToBinaryGlobal

Converts the image (as an ImageData object) to a binary (black and white) format using global thresholding.

convertToBinaryGlobal(imageData: ImageData | null | undefined, threshold: number = -1, invert: boolean = false)

Remarks

  • threshold: A value that ranges between 0 and 255. If -1, Otsu’s method is used to determine the optimal threshold.
  • inverse: If true, inverts the binary colours, resulting in a negative filter on the image.

convertToBinaryLocal

Converts the image (as an ImageData object) to a binary (black and white) format using local adaptive thresholding.

convertToBinaryLocal(imageData: ImageData | null | undefined, blockSize: number = 0, compensation: number = 0, invert: boolean = false)

Remarks

  • blockSize: Size of the local region (must be odd and >= 3).
  • compensation: Value to adjust the threshold (typically 0-10).
  • inverse: If true, inverts the binary colours, resulting in a negative filter on the image.

This page is compatible for:

Is this page helpful?

YesYes NoNo

In this article: