Skip to main content

Image Operations | Cordova Document Scanner

Apply Image Filter#

ScanbotSdk.applyImageFilterOnPage(args: {page: Page, imageFilter: ImageFilter})

Applies an image filter to the hi-res document image of a Page (documentImageFileUri) and refreshes the corresponding preview image (documentPreviewImageFileUri). The original, uncropped image of a Page (originalImageFileUri) will not be modified.

import ScanbotSdk, { Page } from 'cordova-plugin-scanbot-sdk';
private SDK = ScanbotSdk.promisify();public page: Page = ...
// Always make sure you have a valid license on runtime via SDK.getLicenseInfo()if (!licenseCheckMethod()) { return; }
const result = await this.SDK.applyImageFilterOnPage({  page: this.page,   imageFilter: 'BINARIZED'});
// use the updated page from resultthis.page = result.page;// reload the image preview, etc..

Supported Image Filters#

  • COLOR_ENHANCED - Optimizes colors, contrast and brightness.
  • GRAYSCALE - Grayscale filter.
  • BINARIZED - Standard binarization filter with contrast optimization. Creates an 8-bit grayscale image with mostly black or white pixels.
  • COLOR_DOCUMENT - MagicColor filter. Fixes white balance and cleans up the background.
  • PURE_BINARIZED - A filter for binarizing an image. Creates an image with pixel values set to either pure black or pure white.
  • BACKGROUND_CLEAN - Cleans up the background and tries to preserve photos within the image.
  • BLACK_AND_WHITE - Black and white filter with background cleaning. Creates an 8-bit grayscale image with mostly black or white pixels.
  • OTSU_BINARIZATION - A filter for black and white conversion using OTSU binarization.
  • DEEP_BINARIZATION - A filter for black and white conversion primary used for low-contrast documents.
  • EDGE_HIGHLIGHT - A filter that enhances edges in low-contrast documents.
  • LOW_LIGHT_BINARIZATION - Binarization filter primarily intended for use on low-contrast documents with heavy shadows.
  • LOW_LIGHT_BINARIZATION_2 - Binarization filter primarily intended for use on low-contrast documents with heavy shadows.
  • SENSITIVE_BINARIZATION - Binarization filter primarily intended for use on poor quality printed papers.
  • NONE - Removes any previously applied filter from the document image.

Get Filtered Preview Image#

ScanbotSdk.getFilteredDocumentPreviewUri(args: {page: Page, imageFilter: ImageFilter})

This API method just creates a temporary preview image of the document image of a Page based on the given filter. It does not modify the document image of the Page.

For instance, you can use this method to create previews, so the user can test and see the image filter results without applying the filters to the hi-res document images. If the user has decided on a filter, you can apply it on the actual hi-res document image via applyImageFilterOnPage.

public filteredPreviewImageUri: string;
const result = await this.SDK.getFilteredDocumentPreviewUri({    page: this.page,    imageFilter: 'LOW_LIGHT_BINARIZATION_2'});
// use the imageFileUri from result to show a preview image of an image filterthis.filteredPreviewImageUri = result.imageFileUri;
<img [src]="filteredPreviewImageUri" />

Estimate Blur#

ScanbotSdk.estimateBlur(args: {imageFileUri: string})

Estimates image blurriness of any image file. It is recommended to use the hi-res document image file URI (documentImageFileUri) of a scanned Page.

import ScanbotSdk, { Page } from 'cordova-plugin-scanbot-sdk';
private SDK = ScanbotSdk.promisify();public page: Page = ...
// Always make sure you have a valid license on runtime via SDK.getLicenseInfo()if (!licenseCheckMethod()) { return; }
const result = await this.SDK.estimateBlur({imageFileUri: this.page.documentImageFileUri});
// check the blurriness value, e.g.if (result.blur > 0.6) {  alert('This scanned image looks blurry. Consider rescanning it.');}

Result fields:

  • status: 'OK' or 'ERROR'
  • blur: Numeric blur value. Less is sharper, more is blurred. In broad terms, consider blur values as follows:
    • 0.0-0.3: This image is not blurry at all
    • 0.3-0.6: Somewhat blurry, should be okay
    • 0.6-1.0: I am skeptical of the usefulness of the image