@scanmate/diff 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/index.esm.js +4 -1
- package/dist/src/change-detection/annotate-overlay.use-case.d.ts +2 -2
- package/dist/src/change-detection/diff-pages.use-case.d.ts +2 -2
- package/dist/src/change-detection/index.d.ts +1 -1
- package/dist/src/change-detection/page-diff.contract.d.ts +17 -4
- package/dist/src/change-detection/probe-ink.use-case.d.ts +3 -3
- package/dist/src/change-detection/region-ink.use-case.d.ts +3 -3
- package/dist/src/index.d.ts +1 -1
- package/dist/src/region-comparison/compare-regions.use-case.d.ts +3 -3
- package/dist/src/region-comparison/ink-masks.use-case.d.ts +2 -2
- package/dist/src/region-comparison/region.model.d.ts +3 -3
- package/dist/src/region-comparison/render-diff.use-case.d.ts +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -26,11 +26,13 @@ const changes = await diffPages(await alignPages(pages), [
|
|
|
26
26
|
{ page: 1, id: 'date', x: 404, y: 577, width: 171, height: 22 },
|
|
27
27
|
], { sideBySide: true })
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
changes[0].
|
|
32
|
-
changes[0].
|
|
33
|
-
changes[0].
|
|
29
|
+
// Every page comes back carrying its comparison, so nothing has to be matched
|
|
30
|
+
// up again by index - and everything the page already had is still on it.
|
|
31
|
+
changes[0].diff.expected // [{ id, identified, addedInk, overfilled, ink: { ... } }]
|
|
32
|
+
changes[0].diff.unexpected // [{ x, y, width, height, inkArea, pixels }]
|
|
33
|
+
changes[0].diff.missing // printed ink the scan lost
|
|
34
|
+
changes[0].diff.diffImage // the overlay: violet where the ink differs, grey where it agrees
|
|
35
|
+
changes[0].aligned.raster // still the page you handed in
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
Rectangles are in PDF points from the page's top-left by default, the same frame `@scanmate/extract` reports text in; `units: 'pixels'` switches to the original's rendered pixels.
|
package/dist/index.esm.js
CHANGED
|
@@ -686,7 +686,10 @@ async function diffPages(pages, expected = [], options = {}) {
|
|
|
686
686
|
...options,
|
|
687
687
|
probes: (options.probes ?? []).filter(probe => probe.page === undefined || probe.page === page.page)
|
|
688
688
|
});
|
|
689
|
-
results.push(
|
|
689
|
+
results.push({
|
|
690
|
+
...page,
|
|
691
|
+
diff: result
|
|
692
|
+
});
|
|
690
693
|
onProgress?.({
|
|
691
694
|
stage: 'diff',
|
|
692
695
|
phase: 'done',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Raster,
|
|
1
|
+
import type { Raster, ScanmateRect, Rgba } from '@scanmate/ink';
|
|
2
2
|
/**
|
|
3
3
|
* Outline what the report says onto the overlay, so the picture and the numbers
|
|
4
4
|
* can be checked against each other at a glance.
|
|
@@ -30,7 +30,7 @@ export declare const EXPECTED_MARGIN: Rgba;
|
|
|
30
30
|
export declare const UNEXPECTED: Rgba;
|
|
31
31
|
export declare const MISSING: Rgba;
|
|
32
32
|
export interface Annotation {
|
|
33
|
-
rect:
|
|
33
|
+
rect: ScanmateRect;
|
|
34
34
|
color: Rgba;
|
|
35
35
|
}
|
|
36
36
|
export declare function annotateOverlay(overlay: Raster, annotations: readonly Annotation[], thickness?: number): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AlignedPage } from '@scanmate/ink';
|
|
2
|
-
import type { DiffOptions, ExpectedChange, PageDiff } from './page-diff.contract.js';
|
|
2
|
+
import type { ComparedPage, DiffOptions, ExpectedChange, PageDiff } from './page-diff.contract.js';
|
|
3
3
|
/**
|
|
4
4
|
* What changed on each page, and whether it was supposed to.
|
|
5
5
|
*
|
|
@@ -16,7 +16,7 @@ import type { DiffOptions, ExpectedChange, PageDiff } from './page-diff.contract
|
|
|
16
16
|
* Masks are built once per page and read four ways: the overlay, the expected
|
|
17
17
|
* regions, the added changes and the missing ones.
|
|
18
18
|
*/
|
|
19
|
-
export declare function diffPages(pages: readonly
|
|
19
|
+
export declare function diffPages<Page extends AlignedPage>(pages: readonly Page[], expected?: readonly ExpectedChange[], options?: DiffOptions): Promise<Array<ComparedPage<Page>>>;
|
|
20
20
|
/** One page. `expected` should already be the regions for this page. */
|
|
21
21
|
export declare function diffPage(page: AlignedPage, expected?: readonly ExpectedChange[], options?: DiffOptions): Promise<PageDiff>;
|
|
22
22
|
//# sourceMappingURL=diff-pages.use-case.d.ts.map
|
|
@@ -9,7 +9,7 @@ export type { Component, LabelledComponents, LabelOptions } from './connected-co
|
|
|
9
9
|
export { diffPage, diffPages } from './diff-pages.use-case.js';
|
|
10
10
|
export { mergeBoxes } from './merge-boxes.use-case.js';
|
|
11
11
|
export type { MergedBox } from './merge-boxes.use-case.js';
|
|
12
|
-
export type { Change, CoordinateUnits, DiffOptions, ExpectedChange, ExpectedResult, InkProbe, PageDiff, ProbeRect, RegionInkMetrics } from './page-diff.contract.js';
|
|
12
|
+
export type { Change, ComparedPage, CoordinateUnits, DiffOptions, ExpectedChange, ExpectedResult, InkProbe, PageDiff, ProbeRect, RegionInkMetrics } from './page-diff.contract.js';
|
|
13
13
|
export { measureRegionInk } from './region-ink.use-case.js';
|
|
14
14
|
export type { RegionInk, RegionInkOptions } from './region-ink.use-case.js';
|
|
15
15
|
export { composeSideBySide } from './side-by-side.use-case.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImageFormat, InkOptions, ProgressCallback, Raster,
|
|
1
|
+
import type { AlignedPage, ImageFormat, InkOptions, ProgressCallback, Raster, ScanmateRect } from '@scanmate/ink';
|
|
2
2
|
import type { Masks } from '../region-comparison/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Coordinates for regions going in and changes coming out.
|
|
@@ -20,6 +20,19 @@ export interface ExpectedChange {
|
|
|
20
20
|
width: number;
|
|
21
21
|
height: number;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* An aligned page with what the pixel comparison found on it.
|
|
25
|
+
*
|
|
26
|
+
* The comparison hands the page back rather than a bare result, so whatever the
|
|
27
|
+
* producer attached - the metadata, the page's partner in the scan, anything a
|
|
28
|
+
* caller added - is still there afterwards. A bare result carries only a page
|
|
29
|
+
* number, and matching those up again is a join the caller should never have to
|
|
30
|
+
* write: page numbers are the original's, and go non-contiguous the moment
|
|
31
|
+
* anyone extracts `'1-3,5'`.
|
|
32
|
+
*/
|
|
33
|
+
export type ComparedPage<Page extends AlignedPage = AlignedPage> = Page & {
|
|
34
|
+
diff: PageDiff;
|
|
35
|
+
};
|
|
23
36
|
export interface DiffOptions {
|
|
24
37
|
/** Units of `ExpectedChange` rectangles and of every rectangle reported back. Default `'points'`. */
|
|
25
38
|
units?: CoordinateUnits;
|
|
@@ -179,7 +192,7 @@ export interface RegionInkMetrics {
|
|
|
179
192
|
/** Ink in the largest change, in square millimetres. */
|
|
180
193
|
largestArea: number;
|
|
181
194
|
/** Box around all of it, in the requested units; `null` when there is none. */
|
|
182
|
-
bounds:
|
|
195
|
+
bounds: ScanmateRect | null;
|
|
183
196
|
/** `bounds` as a share of the region's width and height. */
|
|
184
197
|
widthRatio: number;
|
|
185
198
|
heightRatio: number;
|
|
@@ -196,13 +209,13 @@ export interface RegionInkMetrics {
|
|
|
196
209
|
}
|
|
197
210
|
/** A change found where nothing was expected, or ink that went missing. */
|
|
198
211
|
/** A place to measure the ink at; `page` selects the page when several are compared. */
|
|
199
|
-
export type ProbeRect =
|
|
212
|
+
export type ProbeRect = ScanmateRect & {
|
|
200
213
|
page?: number;
|
|
201
214
|
};
|
|
202
215
|
/** What the ink does inside one place that was asked about. */
|
|
203
216
|
export interface InkProbe {
|
|
204
217
|
/** The place asked about, in `units`. */
|
|
205
|
-
rect:
|
|
218
|
+
rect: ScanmateRect;
|
|
206
219
|
/** New ink there, in square millimetres. */
|
|
207
220
|
addedInk: number;
|
|
208
221
|
/** Printed ink lost there, in square millimetres. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ScanmateRect } from '@scanmate/ink';
|
|
2
2
|
import type { Masks } from '../region-comparison/index.js';
|
|
3
3
|
import type { CoordinateUnits, InkProbe } from './page-diff.contract.js';
|
|
4
4
|
/**
|
|
@@ -19,12 +19,12 @@ import type { CoordinateUnits, InkProbe } from './page-diff.contract.js';
|
|
|
19
19
|
* @param options - How to read `rects`, and the resolution they are in.
|
|
20
20
|
* @returns One probe per rectangle, in the same order, in square millimetres.
|
|
21
21
|
*/
|
|
22
|
-
export declare function probeInk(masks: Masks, rects: readonly
|
|
22
|
+
export declare function probeInk(masks: Masks, rects: readonly ScanmateRect[], options?: {
|
|
23
23
|
dpi?: number;
|
|
24
24
|
units?: CoordinateUnits;
|
|
25
25
|
}): InkProbe[];
|
|
26
26
|
/** Added, lost and shared ink inside one rectangle of the page, in pixels. */
|
|
27
|
-
export declare function inkWithin(rect:
|
|
27
|
+
export declare function inkWithin(rect: ScanmateRect, masks: Masks): {
|
|
28
28
|
added: number;
|
|
29
29
|
lost: number;
|
|
30
30
|
shared: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BinaryImage,
|
|
1
|
+
import type { BinaryImage, ScanmateRect } from '@scanmate/ink';
|
|
2
2
|
/**
|
|
3
3
|
* The shape of the new ink inside one expected region.
|
|
4
4
|
*
|
|
@@ -34,7 +34,7 @@ export interface RegionInk {
|
|
|
34
34
|
/** Pixels in the largest one. */
|
|
35
35
|
largest: number;
|
|
36
36
|
/** Box around every change that counts, in page pixels; `null` when there is none. */
|
|
37
|
-
bounds:
|
|
37
|
+
bounds: ScanmateRect | null;
|
|
38
38
|
/** Share of those pixels that lie in the band along the region's border. */
|
|
39
39
|
edgeTouch: number;
|
|
40
40
|
/** Share of the region's area that is counted new ink. */
|
|
@@ -43,5 +43,5 @@ export interface RegionInk {
|
|
|
43
43
|
formLines: number;
|
|
44
44
|
}
|
|
45
45
|
/** Analyse `added` (the page's new-ink mask) inside `rect` (page pixels). */
|
|
46
|
-
export declare function measureRegionInk(added: BinaryImage, rect:
|
|
46
|
+
export declare function measureRegionInk(added: BinaryImage, rect: ScanmateRect, options: RegionInkOptions): RegionInk;
|
|
47
47
|
//# sourceMappingURL=region-ink.use-case.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* different part of the page in each image.
|
|
16
16
|
*/
|
|
17
17
|
export { diffPage, diffPages } from './change-detection/index.js';
|
|
18
|
-
export type { Change, CoordinateUnits, DiffOptions, ExpectedChange, ExpectedResult, InkProbe, PageDiff, ProbeRect, RegionInkMetrics } from './change-detection/index.js';
|
|
18
|
+
export type { Change, ComparedPage, CoordinateUnits, DiffOptions, ExpectedChange, ExpectedResult, InkProbe, PageDiff, ProbeRect, RegionInkMetrics } from './change-detection/index.js';
|
|
19
19
|
export { compareRegions, diffDocument, renderDiff } from './region-comparison/index.js';
|
|
20
20
|
export type { DocumentDiff, Region, RegionOptions, RegionReport } from './region-comparison/index.js';
|
|
21
21
|
export { annotateOverlay, composePanels, composeSideBySide, connectedComponents, EXPECTED_MARGIN, IDENTIFIED, labelComponents, measureRegionInk, mergeBoxes, MISSING, NOT_IDENTIFIED, probeInk, REFERENCE, UNEXPECTED, UNSETTLED } from './change-detection/index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ScanmateSource } from '@scanmate/ink';
|
|
2
2
|
import type { Masks } from './ink-masks.use-case.js';
|
|
3
3
|
import type { DocumentDiff, Region, RegionOptions, RegionReport } from './region.model.js';
|
|
4
4
|
/**
|
|
@@ -23,9 +23,9 @@ import type { DocumentDiff, Region, RegionOptions, RegionReport } from './region
|
|
|
23
23
|
* original's canvas. Feeding a raw scan in produces confident nonsense, because
|
|
24
24
|
* every rectangle then names a different part of the page in each image.
|
|
25
25
|
*/
|
|
26
|
-
export declare function compareRegions(original:
|
|
26
|
+
export declare function compareRegions(original: ScanmateSource, aligned: ScanmateSource, regions: readonly Region[], options?: RegionOptions): Promise<RegionReport[]>;
|
|
27
27
|
/** Page-wide added/removed ink, plus per-region detail for any regions supplied. */
|
|
28
|
-
export declare function diffDocument(original:
|
|
28
|
+
export declare function diffDocument(original: ScanmateSource, aligned: ScanmateSource, regions?: readonly Region[], options?: RegionOptions): Promise<DocumentDiff>;
|
|
29
29
|
/** One region's added and removed ink, from masks already built. */
|
|
30
30
|
export declare function measureRegion(region: Region, masks: Masks, defaultThreshold: number): RegionReport;
|
|
31
31
|
//# sourceMappingURL=compare-regions.use-case.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BinaryImage,
|
|
1
|
+
import type { BinaryImage, ScanmateSource, InkOptions } from '@scanmate/ink';
|
|
2
2
|
/**
|
|
3
3
|
* The ink masks every comparison starts from, plus their tolerance bands.
|
|
4
4
|
*
|
|
@@ -32,5 +32,5 @@ export interface Masks {
|
|
|
32
32
|
}
|
|
33
33
|
/** Default for {@link buildMasks}' `faintInk`, measured against real scans. */
|
|
34
34
|
export declare const FAINT_INK = 0.25;
|
|
35
|
-
export declare function buildMasks(original:
|
|
35
|
+
export declare function buildMasks(original: ScanmateSource, aligned: ScanmateSource, ink: InkOptions | undefined, tolerance: number, faintInk?: number): Promise<Masks>;
|
|
36
36
|
//# sourceMappingURL=ink-masks.use-case.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { InkOptions,
|
|
1
|
+
import type { InkOptions, ScanmateRect } from '@scanmate/ink';
|
|
2
2
|
export interface Region {
|
|
3
3
|
id: string;
|
|
4
4
|
/** In the *original's* pixel coordinates - the whole point of aligning first. */
|
|
5
|
-
rect:
|
|
5
|
+
rect: ScanmateRect;
|
|
6
6
|
/** Fraction of the region that must be new ink before `filled` is true. Overrides the global default. */
|
|
7
7
|
threshold?: number;
|
|
8
8
|
}
|
|
@@ -24,7 +24,7 @@ export interface RegionOptions {
|
|
|
24
24
|
}
|
|
25
25
|
export interface RegionReport {
|
|
26
26
|
id: string;
|
|
27
|
-
rect:
|
|
27
|
+
rect: ScanmateRect;
|
|
28
28
|
/** Ink coverage of the region in the original, in `[0, 1]`. */
|
|
29
29
|
originalInk: number;
|
|
30
30
|
/** Ink coverage of the region in the aligned scan. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ScanmateSource, Raster, Rgba } from '@scanmate/ink';
|
|
2
2
|
import type { Masks } from './ink-masks.use-case.js';
|
|
3
3
|
import type { RegionOptions } from './region.model.js';
|
|
4
4
|
/**
|
|
@@ -14,7 +14,7 @@ import type { RegionOptions } from './region.model.js';
|
|
|
14
14
|
* measured separately and in millimetres. Here it would be a second colour
|
|
15
15
|
* carrying a distinction the eye does not need at this zoom.
|
|
16
16
|
*/
|
|
17
|
-
export declare function renderDiff(original:
|
|
17
|
+
export declare function renderDiff(original: ScanmateSource, aligned: ScanmateSource, options?: RegionOptions): Promise<Raster>;
|
|
18
18
|
/**
|
|
19
19
|
* Ink the two pages do not share. Violet rather than red, because red means
|
|
20
20
|
* "changed" on every annotated page in the pipeline and one colour cannot mean
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scanmate/diff",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "What changed between an original and its aligned scan: expected regions filled in, unexpected marks, lost ink, and a side-by-side evidence image.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eduardo Russo",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"!**/*.js.map"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@scanmate/ink": "^0.1
|
|
42
|
+
"@scanmate/ink": "^0.2.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@scanmate/align": "^0.1
|
|
48
|
+
"@scanmate/align": "^0.2.1"
|
|
49
49
|
}
|
|
50
50
|
}
|