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 fromIt 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
limitcaps crops per page;0means all. A detector having a bad day on a noisy scan can produce hundreds of boxes, and each crop is an encode.returnEmpty: trueemits the whole page when nothing was detected, instead of throwingImageError('No boxes to crop')into the row'sexception. 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
| Parameter | Type | Default | Meaning |
|---|---|---|---|
inputCols | string[] (2) | ['image', 'boxes'] | The page image, then the box column to cut from it. |
boxCol | string | 'box' | Where each crop’s source box is written. |
padding | number | 0 | Grow each box by this many pixels before cropping. |
limit | number | 0 | Maximum crops per page; 0 means all of them. |
autoRotate | boolean | true | Turn portrait crops a quarter turn, so text reads horizontally. |
returnEmpty | boolean | false | Emit the whole page when nothing was detected, instead of failing. |
imageType | 'png' | 'webp' | 'jpeg' | 'png' | Image format |