StagesTransform

ImageCropBoxes

Crop each detected box out of the page, one row per crop, straightening rotated ones.

Import
import { ImageCropBoxes } from '@stabrise/scaledp'
Group
Transform
Reads
image, boxes
Writes
image, box
Needs
nothing
Note
Expands one row into several.

Expands one page row into one row per crop. Each crop lands in outputCol and its source box in boxCol, so a crop always knows where it came from.

import { Pipeline, ImageCropBoxes } from '@stabrise/scaledp'
import { PdfToImage } from '@stabrise/scaledp/pdf'
import { SignatureDetector } from '@stabrise/scaledp/detect'

const rows = await new Pipeline([
    new PdfToImage({ resolution: 200 }),
    new SignatureDetector(),
    new ImageCropBoxes({ inputCols: ['image', 'signatures'], padding: 8 }),
]).transform(file)

rows[0].cropped_image   // ScaleDpImage
rows[0].box             // the Box it came from
Open in builder

It reads bboxes off either a DetectorOutput or a Document, so it crops what a detector found or what a recognizer read.

Rotated boxes are straightened

Cropped to the box's own axes rather than to its envelope, which is what makes the crops usable as recognizer input — an envelope crop of a 25° line is mostly neighbouring text.

autoRotate (on by default) then turns portrait crops a quarter turn counter-clockwise so text reads horizontally.

Two guards worth setting

  • limit caps crops per page; 0 means all. A detector having a bad day on a noisy scan can produce hundreds of boxes, and each crop is an encode.
  • returnEmpty: true emits the whole page when nothing was detected, instead of throwing ImageError('No boxes to crop') into the row's exception. Which you want depends on whether "no signatures on this page" is a result or a failure.

It multiplies rows

Two expanding stages reading the same pre-existing column multiply rather than subdivide. Cropping boxes found on a page that PdfToImage rendered is a subdivision — fine. See Columns are the wiring.

Crops have no page number of their own, so an interface paging through results numbers them by position.

Parameters

ParameterTypeDefaultMeaning
inputColsstring[] (2)['image', 'boxes']The page image, then the box column to cut from it.
boxColstring'box'Where each crop’s source box is written.
paddingnumber0Grow each box by this many pixels before cropping.
limitnumber0Maximum crops per page; 0 means all of them.
autoRotatebooleantrueTurn portrait crops a quarter turn, so text reads horizontally.
returnEmptybooleanfalseEmit the whole page when nothing was detected, instead of failing.
imageType'png' | 'webp' | 'jpeg''png'Image format

On this page