@blazediff/cli 4.0.5 → 5.0.0
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 +35 -0
- package/dist/cli.js +213 -31
- package/dist/commands/core-native.js +3 -21
- package/dist/commands/interpret.js +208 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -105,6 +105,36 @@ Integral image-based SSIM implementation for faster computation.
|
|
|
105
105
|
blazediff-cli hitchhikers-ssim image1.png image2.png [options]
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
### `interpret` - What changed, not just where
|
|
109
|
+
Structured region analysis: each change gets a type, a shape, a position and the
|
|
110
|
+
statistics behind them. Every other command answers *where* pixels differ or
|
|
111
|
+
*how alike* two images are; this one describes the change.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
blazediff-cli interpret image1.png image2.png [output] [options]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`output` is written by the `pixel` source only — the metric sources and
|
|
118
|
+
`--regions` have no diff visualization to write, and passing one is an error
|
|
119
|
+
rather than a silently ignored path.
|
|
120
|
+
|
|
121
|
+
**Options:**
|
|
122
|
+
- `--source <name>` - How to locate regions: `pixel` (default), `ssim`, `ms-ssim`, `hitchhikers-ssim`
|
|
123
|
+
- `-t, --threshold <num>` - Color difference threshold (0 to 1, default: 0.1). `pixel` only
|
|
124
|
+
- `-a, --antialiasing` - Exclude anti-aliased pixels. `pixel` only
|
|
125
|
+
- `-c, --compression <num>` - PNG compression level (0-9, default: 0)
|
|
126
|
+
- `--window-size <num>` - Local window size for the metric sources (default: 11)
|
|
127
|
+
- `--region-floor <num>` - Window score at or below which it counts as changed (default: 0.99)
|
|
128
|
+
- `--regions <json>` - Skip the search and classify these boxes instead
|
|
129
|
+
- `--json` - Print the full result as JSON
|
|
130
|
+
- `-h, --help` - Show help message
|
|
131
|
+
|
|
132
|
+
The metric sources locate regions by thresholding a similarity map, so their boxes
|
|
133
|
+
are as coarse as that map's grid. The numbers are not: every box is refined against
|
|
134
|
+
the source pixels first, so pixel counts stay per-pixel.
|
|
135
|
+
|
|
136
|
+
Exits 0 when nothing actionable changed, 1 when it did, 2 on error.
|
|
137
|
+
|
|
108
138
|
## Examples
|
|
109
139
|
|
|
110
140
|
```bash
|
|
@@ -119,6 +149,11 @@ blazediff-cli core image1.png image2.png -o diff.png -t 0.05
|
|
|
119
149
|
blazediff-cli gmsd image1.png image2.png
|
|
120
150
|
blazediff-cli gmsd image1.png image2.png -o gms-map.png
|
|
121
151
|
|
|
152
|
+
# Describe what changed
|
|
153
|
+
blazediff-cli interpret image1.png image2.png
|
|
154
|
+
blazediff-cli interpret image1.png image2.png --source ms-ssim
|
|
155
|
+
blazediff-cli interpret image1.png image2.png --json
|
|
156
|
+
|
|
122
157
|
# SSIM structural similarity
|
|
123
158
|
blazediff-cli ssim image1.png image2.png
|
|
124
159
|
blazediff-cli ssim image1.png image2.png -o ssim-map.png
|
package/dist/cli.js
CHANGED
|
@@ -52,15 +52,14 @@ Options:
|
|
|
52
52
|
-a, --antialiasing Enable anti-aliasing detection
|
|
53
53
|
--diff-mask Output only differences (transparent background)
|
|
54
54
|
-c, --compression <num> PNG compression level (0-9, default: 0)
|
|
55
|
-
--interpret Run structured interpretation (region detection + classification)
|
|
56
|
-
--output-format <fmt> Output format: png (default) or html (interpret report)
|
|
57
55
|
-h, --help Show this help message
|
|
58
56
|
|
|
59
57
|
Examples:
|
|
60
58
|
blazediff-cli core-native image1.png image2.png diff.png
|
|
61
59
|
blazediff-cli core-native image1.png image2.png diff.png -t 0.05 -a
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
|
|
61
|
+
For region analysis of what changed, use the interpret command:
|
|
62
|
+
blazediff-cli interpret image1.png image2.png
|
|
64
63
|
`);
|
|
65
64
|
}
|
|
66
65
|
async function main() {
|
|
@@ -121,9 +120,6 @@ async function main() {
|
|
|
121
120
|
i3++;
|
|
122
121
|
}
|
|
123
122
|
break;
|
|
124
|
-
case "--interpret":
|
|
125
|
-
options.interpret = true;
|
|
126
|
-
break;
|
|
127
123
|
default:
|
|
128
124
|
console.error(`Unknown option: ${arg}`);
|
|
129
125
|
printUsage();
|
|
@@ -131,17 +127,6 @@ async function main() {
|
|
|
131
127
|
}
|
|
132
128
|
}
|
|
133
129
|
const startTime = performance.now();
|
|
134
|
-
if (options.interpret && !output) {
|
|
135
|
-
const result2 = await (0, import_core_native.interpret)(image1, image2, {
|
|
136
|
-
threshold: options.threshold,
|
|
137
|
-
antialiasing: options.antialiasing
|
|
138
|
-
});
|
|
139
|
-
const duration2 = performance.now() - startTime;
|
|
140
|
-
console.log(`completed in: ${duration2.toFixed(2)}ms`);
|
|
141
|
-
console.log(JSON.stringify(result2, null, 2));
|
|
142
|
-
process.exit(result2.diffPercentage === 0 ? 0 : 1);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
130
|
const result = await (0, import_core_native.compare)(image1, image2, output, options);
|
|
146
131
|
const duration = performance.now() - startTime;
|
|
147
132
|
console.log(`completed in: ${duration.toFixed(2)}ms`);
|
|
@@ -163,9 +148,6 @@ async function main() {
|
|
|
163
148
|
if (output) {
|
|
164
149
|
console.log(`diff output: ${output}`);
|
|
165
150
|
}
|
|
166
|
-
if ("interpretation" in result && result.interpretation) {
|
|
167
|
-
console.log(JSON.stringify(result.interpretation, null, 2));
|
|
168
|
-
}
|
|
169
151
|
process.exit(1);
|
|
170
152
|
}
|
|
171
153
|
} catch (error) {
|
|
@@ -9590,10 +9572,10 @@ function parseRGB(colorStr) {
|
|
|
9590
9572
|
}
|
|
9591
9573
|
return [parts[0], parts[1], parts[2]];
|
|
9592
9574
|
}
|
|
9593
|
-
function parseCoreArgs(args,
|
|
9575
|
+
function parseCoreArgs(args, printUsage10) {
|
|
9594
9576
|
if (args.length < 2) {
|
|
9595
9577
|
console.error("Error: Two image paths are required");
|
|
9596
|
-
|
|
9578
|
+
printUsage10();
|
|
9597
9579
|
process.exit(1);
|
|
9598
9580
|
}
|
|
9599
9581
|
const parsed = {
|
|
@@ -9669,7 +9651,7 @@ function parseCoreArgs(args, printUsage9) {
|
|
|
9669
9651
|
break;
|
|
9670
9652
|
default:
|
|
9671
9653
|
console.error(`Unknown option: ${arg}`);
|
|
9672
|
-
|
|
9654
|
+
printUsage10();
|
|
9673
9655
|
process.exit(1);
|
|
9674
9656
|
}
|
|
9675
9657
|
}
|
|
@@ -10979,9 +10961,203 @@ var init_hitchhikers_ssim2 = __esm({
|
|
|
10979
10961
|
}
|
|
10980
10962
|
});
|
|
10981
10963
|
|
|
10982
|
-
// src/
|
|
10964
|
+
// src/commands/interpret.ts
|
|
10965
|
+
var interpret_exports = {};
|
|
10966
|
+
__export(interpret_exports, {
|
|
10967
|
+
default: () => main8
|
|
10968
|
+
});
|
|
10983
10969
|
function printUsage8() {
|
|
10984
10970
|
console.log(`
|
|
10971
|
+
Usage: blazediff-cli interpret <image1> <image2> [output] [options]
|
|
10972
|
+
|
|
10973
|
+
Describes *what* changed between two images \u2014 region by region, with a change
|
|
10974
|
+
type, position and shape \u2014 rather than only which pixels differ.
|
|
10975
|
+
|
|
10976
|
+
Arguments:
|
|
10977
|
+
image1 Path to the first image
|
|
10978
|
+
image2 Path to the second image
|
|
10979
|
+
output Path for the diff visualization (optional; the pixel source
|
|
10980
|
+
writes it, the metric sources and --regions do not)
|
|
10981
|
+
|
|
10982
|
+
Options:
|
|
10983
|
+
--source <name> How to locate regions: pixel (default), ssim,
|
|
10984
|
+
ms-ssim, hitchhikers-ssim
|
|
10985
|
+
-t, --threshold <num> Color difference threshold (0 to 1, default: 0.1).
|
|
10986
|
+
pixel source only
|
|
10987
|
+
-a, --antialiasing Exclude anti-aliased pixels. pixel source only
|
|
10988
|
+
-c, --compression <num> PNG compression level (0-9, default: 0)
|
|
10989
|
+
--window-size <num> Local window size for the metric sources (default: 11)
|
|
10990
|
+
--region-floor <num> Window score at or below which it counts as changed
|
|
10991
|
+
(0 to 1, default: 0.99). Metric sources only
|
|
10992
|
+
--regions <json> Skip the search and classify these boxes instead.
|
|
10993
|
+
A JSON array of { x, y, width, height }
|
|
10994
|
+
--json Print the full result as JSON
|
|
10995
|
+
-h, --help Show this help message
|
|
10996
|
+
|
|
10997
|
+
The metric sources locate regions by thresholding a similarity map, so their
|
|
10998
|
+
boxes are as coarse as that map's grid. The numbers are not: every box is
|
|
10999
|
+
refined against the source pixels first, so pixel counts stay per-pixel.
|
|
11000
|
+
|
|
11001
|
+
Examples:
|
|
11002
|
+
blazediff-cli interpret image1.png image2.png
|
|
11003
|
+
blazediff-cli interpret image1.png image2.png diff.png -t 0.05 -a
|
|
11004
|
+
blazediff-cli interpret image1.png image2.png --source ms-ssim
|
|
11005
|
+
blazediff-cli interpret image1.png image2.png --json
|
|
11006
|
+
blazediff-cli interpret image1.png image2.png --regions '[{"x":0,"y":0,"width":64,"height":64}]'
|
|
11007
|
+
`);
|
|
11008
|
+
}
|
|
11009
|
+
function parseNumber(value, flag, min, max) {
|
|
11010
|
+
const parsed = Number.parseFloat(value ?? "");
|
|
11011
|
+
if (Number.isNaN(parsed) || parsed < min || parsed > max) {
|
|
11012
|
+
throw new Error(
|
|
11013
|
+
`Invalid ${flag}: ${value}. Must be between ${min} and ${max}`
|
|
11014
|
+
);
|
|
11015
|
+
}
|
|
11016
|
+
return parsed;
|
|
11017
|
+
}
|
|
11018
|
+
function printSummary(result) {
|
|
11019
|
+
console.log(result.summary);
|
|
11020
|
+
for (const region of result.regions) {
|
|
11021
|
+
const { x, y, width, height } = region.bbox;
|
|
11022
|
+
console.log(
|
|
11023
|
+
` ${region.changeType} ${region.shape} at ${region.position} \u2014 ${width}x${height} at (${x}, ${y}), ${region.pixelCount}px (${region.percentage.toFixed(2)}%)`
|
|
11024
|
+
);
|
|
11025
|
+
}
|
|
11026
|
+
}
|
|
11027
|
+
async function main8() {
|
|
11028
|
+
try {
|
|
11029
|
+
const args = process.argv.slice(2);
|
|
11030
|
+
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
|
|
11031
|
+
printUsage8();
|
|
11032
|
+
process.exit(0);
|
|
11033
|
+
}
|
|
11034
|
+
if (args.length < 2) {
|
|
11035
|
+
console.error("Error: Two image paths are required");
|
|
11036
|
+
printUsage8();
|
|
11037
|
+
process.exit(1);
|
|
11038
|
+
}
|
|
11039
|
+
const image1 = args[0];
|
|
11040
|
+
const image2 = args[1];
|
|
11041
|
+
const options = {};
|
|
11042
|
+
let output;
|
|
11043
|
+
let regions;
|
|
11044
|
+
let json = false;
|
|
11045
|
+
let optStart = 2;
|
|
11046
|
+
if (args.length > 2 && !args[2].startsWith("-")) {
|
|
11047
|
+
output = args[2];
|
|
11048
|
+
optStart = 3;
|
|
11049
|
+
}
|
|
11050
|
+
for (let i3 = optStart; i3 < args.length; i3++) {
|
|
11051
|
+
const arg = args[i3];
|
|
11052
|
+
const nextArg = args[i3 + 1];
|
|
11053
|
+
switch (arg) {
|
|
11054
|
+
case "--source":
|
|
11055
|
+
if (!nextArg || !SOURCES.includes(nextArg)) {
|
|
11056
|
+
throw new Error(
|
|
11057
|
+
`Invalid source: ${nextArg}. Must be one of: ${SOURCES.join(", ")}`
|
|
11058
|
+
);
|
|
11059
|
+
}
|
|
11060
|
+
options.source = nextArg;
|
|
11061
|
+
i3++;
|
|
11062
|
+
break;
|
|
11063
|
+
case "-t":
|
|
11064
|
+
case "--threshold":
|
|
11065
|
+
options.threshold = parseNumber(nextArg, "threshold", 0, 1);
|
|
11066
|
+
i3++;
|
|
11067
|
+
break;
|
|
11068
|
+
case "-a":
|
|
11069
|
+
case "--antialiasing":
|
|
11070
|
+
options.antialiasing = true;
|
|
11071
|
+
break;
|
|
11072
|
+
case "-c":
|
|
11073
|
+
case "--compression":
|
|
11074
|
+
options.compression = parseNumber(nextArg, "compression", 0, 9);
|
|
11075
|
+
i3++;
|
|
11076
|
+
break;
|
|
11077
|
+
case "--window-size":
|
|
11078
|
+
options.windowSize = parseNumber(nextArg, "window-size", 1, 1024);
|
|
11079
|
+
i3++;
|
|
11080
|
+
break;
|
|
11081
|
+
case "--region-floor":
|
|
11082
|
+
options.regionFloor = parseNumber(nextArg, "region-floor", 0, 1);
|
|
11083
|
+
i3++;
|
|
11084
|
+
break;
|
|
11085
|
+
case "--regions":
|
|
11086
|
+
if (!nextArg) {
|
|
11087
|
+
throw new Error("--regions requires a JSON array");
|
|
11088
|
+
}
|
|
11089
|
+
regions = nextArg;
|
|
11090
|
+
i3++;
|
|
11091
|
+
break;
|
|
11092
|
+
case "--json":
|
|
11093
|
+
json = true;
|
|
11094
|
+
break;
|
|
11095
|
+
default:
|
|
11096
|
+
console.error(`Unknown option: ${arg}`);
|
|
11097
|
+
printUsage8();
|
|
11098
|
+
process.exit(1);
|
|
11099
|
+
}
|
|
11100
|
+
}
|
|
11101
|
+
const startTime = performance.now();
|
|
11102
|
+
let result;
|
|
11103
|
+
if (regions !== void 0) {
|
|
11104
|
+
if (output !== void 0) {
|
|
11105
|
+
throw new Error(
|
|
11106
|
+
"--regions does not write a diff visualization; drop the output path"
|
|
11107
|
+
);
|
|
11108
|
+
}
|
|
11109
|
+
let parsed;
|
|
11110
|
+
try {
|
|
11111
|
+
parsed = JSON.parse(regions);
|
|
11112
|
+
} catch {
|
|
11113
|
+
throw new Error("--regions must be valid JSON");
|
|
11114
|
+
}
|
|
11115
|
+
if (!Array.isArray(parsed)) {
|
|
11116
|
+
throw new Error("--regions must be a JSON array of boxes");
|
|
11117
|
+
}
|
|
11118
|
+
result = await (0, import_interpret_native.interpretRegions)(image1, image2, parsed);
|
|
11119
|
+
} else {
|
|
11120
|
+
result = await (0, import_interpret_native.interpret)(image1, image2, output, options);
|
|
11121
|
+
}
|
|
11122
|
+
const duration = performance.now() - startTime;
|
|
11123
|
+
console.log(`completed in: ${duration.toFixed(2)}ms`);
|
|
11124
|
+
if (json) {
|
|
11125
|
+
console.log(JSON.stringify(result, null, 2));
|
|
11126
|
+
} else {
|
|
11127
|
+
printSummary(result);
|
|
11128
|
+
if (output && result.diffCount > 0) {
|
|
11129
|
+
console.log(`diff output: ${output}`);
|
|
11130
|
+
}
|
|
11131
|
+
}
|
|
11132
|
+
process.exit(result.totalRegions === 0 ? 0 : 1);
|
|
11133
|
+
} catch (error) {
|
|
11134
|
+
console.error(
|
|
11135
|
+
"Error:",
|
|
11136
|
+
error instanceof Error ? error.message : String(error)
|
|
11137
|
+
);
|
|
11138
|
+
process.exit(2);
|
|
11139
|
+
}
|
|
11140
|
+
}
|
|
11141
|
+
var import_interpret_native, SOURCES;
|
|
11142
|
+
var init_interpret = __esm({
|
|
11143
|
+
"src/commands/interpret.ts"() {
|
|
11144
|
+
"use strict";
|
|
11145
|
+
import_interpret_native = require("@blazediff/interpret-native");
|
|
11146
|
+
SOURCES = [
|
|
11147
|
+
"pixel",
|
|
11148
|
+
"ssim",
|
|
11149
|
+
"ms-ssim",
|
|
11150
|
+
"hitchhikers-ssim"
|
|
11151
|
+
];
|
|
11152
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
11153
|
+
main8();
|
|
11154
|
+
}
|
|
11155
|
+
}
|
|
11156
|
+
});
|
|
11157
|
+
|
|
11158
|
+
// src/cli.ts
|
|
11159
|
+
function printUsage9() {
|
|
11160
|
+
console.log(`
|
|
10985
11161
|
Usage: blazediff-cli<command> <image1> <image2> [options]
|
|
10986
11162
|
|
|
10987
11163
|
Commands:
|
|
@@ -10992,6 +11168,7 @@ Commands:
|
|
|
10992
11168
|
ssim Structural Similarity Index (Gaussian-based)
|
|
10993
11169
|
msssim Multi-Scale Structural Similarity Index
|
|
10994
11170
|
hitchhikers-ssim Hitchhiker's SSIM (fast, integral image-based)
|
|
11171
|
+
interpret Describe what changed: regions, change types, severity
|
|
10995
11172
|
|
|
10996
11173
|
Options:
|
|
10997
11174
|
-h, --help Show this help message
|
|
@@ -11002,7 +11179,8 @@ Examples:
|
|
|
11002
11179
|
blazediff-cli ssim image1.png image2.png -o ssim-map.png
|
|
11003
11180
|
blazediff-cli msssim image1.png image2.png
|
|
11004
11181
|
blazediff-cli hitchhikers-ssim image1.png image2.png
|
|
11005
|
-
blazediff-cli image1.png image2.png
|
|
11182
|
+
blazediff-cli interpret image1.png image2.png
|
|
11183
|
+
blazediff-cli interpret image1.png image2.png --source ms-ssim
|
|
11006
11184
|
|
|
11007
11185
|
# Default command (diff) if no command specified
|
|
11008
11186
|
blazediff-cli image1.png image2.png
|
|
@@ -11011,10 +11189,10 @@ For command-specific help, use:
|
|
|
11011
11189
|
blazediff-cli <command> --help
|
|
11012
11190
|
`);
|
|
11013
11191
|
}
|
|
11014
|
-
async function
|
|
11192
|
+
async function main9() {
|
|
11015
11193
|
const args = process.argv.slice(2);
|
|
11016
11194
|
if (args.length === 0) {
|
|
11017
|
-
|
|
11195
|
+
printUsage9();
|
|
11018
11196
|
process.exit(0);
|
|
11019
11197
|
}
|
|
11020
11198
|
const command = args[0];
|
|
@@ -11025,11 +11203,12 @@ async function main8() {
|
|
|
11025
11203
|
"gmsd",
|
|
11026
11204
|
"ssim",
|
|
11027
11205
|
"msssim",
|
|
11028
|
-
"hitchhikers-ssim"
|
|
11206
|
+
"hitchhikers-ssim",
|
|
11207
|
+
"interpret"
|
|
11029
11208
|
];
|
|
11030
11209
|
const isCommand = validCommands.includes(command);
|
|
11031
11210
|
if ((args.includes("-h") || args.includes("--help")) && !isCommand) {
|
|
11032
|
-
|
|
11211
|
+
printUsage9();
|
|
11033
11212
|
process.exit(0);
|
|
11034
11213
|
}
|
|
11035
11214
|
if (isCommand) {
|
|
@@ -11056,13 +11235,16 @@ async function main8() {
|
|
|
11056
11235
|
case "hitchhikers-ssim":
|
|
11057
11236
|
await Promise.resolve().then(() => (init_hitchhikers_ssim2(), hitchhikers_ssim_exports));
|
|
11058
11237
|
break;
|
|
11238
|
+
case "interpret":
|
|
11239
|
+
await Promise.resolve().then(() => (init_interpret(), interpret_exports));
|
|
11240
|
+
break;
|
|
11059
11241
|
}
|
|
11060
11242
|
} else {
|
|
11061
11243
|
await Promise.resolve().then(() => (init_core_native(), core_native_exports));
|
|
11062
11244
|
}
|
|
11063
11245
|
}
|
|
11064
11246
|
if (typeof require !== "undefined" && require.main === module) {
|
|
11065
|
-
|
|
11247
|
+
main9();
|
|
11066
11248
|
}
|
|
11067
11249
|
/*! Bundled license information:
|
|
11068
11250
|
|
|
@@ -39,15 +39,14 @@ Options:
|
|
|
39
39
|
-a, --antialiasing Enable anti-aliasing detection
|
|
40
40
|
--diff-mask Output only differences (transparent background)
|
|
41
41
|
-c, --compression <num> PNG compression level (0-9, default: 0)
|
|
42
|
-
--interpret Run structured interpretation (region detection + classification)
|
|
43
|
-
--output-format <fmt> Output format: png (default) or html (interpret report)
|
|
44
42
|
-h, --help Show this help message
|
|
45
43
|
|
|
46
44
|
Examples:
|
|
47
45
|
blazediff-cli core-native image1.png image2.png diff.png
|
|
48
46
|
blazediff-cli core-native image1.png image2.png diff.png -t 0.05 -a
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
|
|
48
|
+
For region analysis of what changed, use the interpret command:
|
|
49
|
+
blazediff-cli interpret image1.png image2.png
|
|
51
50
|
`);
|
|
52
51
|
}
|
|
53
52
|
async function main() {
|
|
@@ -108,9 +107,6 @@ async function main() {
|
|
|
108
107
|
i++;
|
|
109
108
|
}
|
|
110
109
|
break;
|
|
111
|
-
case "--interpret":
|
|
112
|
-
options.interpret = true;
|
|
113
|
-
break;
|
|
114
110
|
default:
|
|
115
111
|
console.error(`Unknown option: ${arg}`);
|
|
116
112
|
printUsage();
|
|
@@ -118,17 +114,6 @@ async function main() {
|
|
|
118
114
|
}
|
|
119
115
|
}
|
|
120
116
|
const startTime = performance.now();
|
|
121
|
-
if (options.interpret && !output) {
|
|
122
|
-
const result2 = await (0, import_core_native.interpret)(image1, image2, {
|
|
123
|
-
threshold: options.threshold,
|
|
124
|
-
antialiasing: options.antialiasing
|
|
125
|
-
});
|
|
126
|
-
const duration2 = performance.now() - startTime;
|
|
127
|
-
console.log(`completed in: ${duration2.toFixed(2)}ms`);
|
|
128
|
-
console.log(JSON.stringify(result2, null, 2));
|
|
129
|
-
process.exit(result2.diffPercentage === 0 ? 0 : 1);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
117
|
const result = await (0, import_core_native.compare)(image1, image2, output, options);
|
|
133
118
|
const duration = performance.now() - startTime;
|
|
134
119
|
console.log(`completed in: ${duration.toFixed(2)}ms`);
|
|
@@ -150,9 +135,6 @@ async function main() {
|
|
|
150
135
|
if (output) {
|
|
151
136
|
console.log(`diff output: ${output}`);
|
|
152
137
|
}
|
|
153
|
-
if ("interpretation" in result && result.interpretation) {
|
|
154
|
-
console.log(JSON.stringify(result.interpretation, null, 2));
|
|
155
|
-
}
|
|
156
138
|
process.exit(1);
|
|
157
139
|
}
|
|
158
140
|
} catch (error) {
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/commands/interpret.ts
|
|
22
|
+
var interpret_exports = {};
|
|
23
|
+
__export(interpret_exports, {
|
|
24
|
+
default: () => main
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(interpret_exports);
|
|
27
|
+
var import_interpret_native = require("@blazediff/interpret-native");
|
|
28
|
+
var SOURCES = [
|
|
29
|
+
"pixel",
|
|
30
|
+
"ssim",
|
|
31
|
+
"ms-ssim",
|
|
32
|
+
"hitchhikers-ssim"
|
|
33
|
+
];
|
|
34
|
+
function printUsage() {
|
|
35
|
+
console.log(`
|
|
36
|
+
Usage: blazediff-cli interpret <image1> <image2> [output] [options]
|
|
37
|
+
|
|
38
|
+
Describes *what* changed between two images \u2014 region by region, with a change
|
|
39
|
+
type, position and shape \u2014 rather than only which pixels differ.
|
|
40
|
+
|
|
41
|
+
Arguments:
|
|
42
|
+
image1 Path to the first image
|
|
43
|
+
image2 Path to the second image
|
|
44
|
+
output Path for the diff visualization (optional; the pixel source
|
|
45
|
+
writes it, the metric sources and --regions do not)
|
|
46
|
+
|
|
47
|
+
Options:
|
|
48
|
+
--source <name> How to locate regions: pixel (default), ssim,
|
|
49
|
+
ms-ssim, hitchhikers-ssim
|
|
50
|
+
-t, --threshold <num> Color difference threshold (0 to 1, default: 0.1).
|
|
51
|
+
pixel source only
|
|
52
|
+
-a, --antialiasing Exclude anti-aliased pixels. pixel source only
|
|
53
|
+
-c, --compression <num> PNG compression level (0-9, default: 0)
|
|
54
|
+
--window-size <num> Local window size for the metric sources (default: 11)
|
|
55
|
+
--region-floor <num> Window score at or below which it counts as changed
|
|
56
|
+
(0 to 1, default: 0.99). Metric sources only
|
|
57
|
+
--regions <json> Skip the search and classify these boxes instead.
|
|
58
|
+
A JSON array of { x, y, width, height }
|
|
59
|
+
--json Print the full result as JSON
|
|
60
|
+
-h, --help Show this help message
|
|
61
|
+
|
|
62
|
+
The metric sources locate regions by thresholding a similarity map, so their
|
|
63
|
+
boxes are as coarse as that map's grid. The numbers are not: every box is
|
|
64
|
+
refined against the source pixels first, so pixel counts stay per-pixel.
|
|
65
|
+
|
|
66
|
+
Examples:
|
|
67
|
+
blazediff-cli interpret image1.png image2.png
|
|
68
|
+
blazediff-cli interpret image1.png image2.png diff.png -t 0.05 -a
|
|
69
|
+
blazediff-cli interpret image1.png image2.png --source ms-ssim
|
|
70
|
+
blazediff-cli interpret image1.png image2.png --json
|
|
71
|
+
blazediff-cli interpret image1.png image2.png --regions '[{"x":0,"y":0,"width":64,"height":64}]'
|
|
72
|
+
`);
|
|
73
|
+
}
|
|
74
|
+
function parseNumber(value, flag, min, max) {
|
|
75
|
+
const parsed = Number.parseFloat(value ?? "");
|
|
76
|
+
if (Number.isNaN(parsed) || parsed < min || parsed > max) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Invalid ${flag}: ${value}. Must be between ${min} and ${max}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
83
|
+
function printSummary(result) {
|
|
84
|
+
console.log(result.summary);
|
|
85
|
+
for (const region of result.regions) {
|
|
86
|
+
const { x, y, width, height } = region.bbox;
|
|
87
|
+
console.log(
|
|
88
|
+
` ${region.changeType} ${region.shape} at ${region.position} \u2014 ${width}x${height} at (${x}, ${y}), ${region.pixelCount}px (${region.percentage.toFixed(2)}%)`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function main() {
|
|
93
|
+
try {
|
|
94
|
+
const args = process.argv.slice(2);
|
|
95
|
+
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
|
|
96
|
+
printUsage();
|
|
97
|
+
process.exit(0);
|
|
98
|
+
}
|
|
99
|
+
if (args.length < 2) {
|
|
100
|
+
console.error("Error: Two image paths are required");
|
|
101
|
+
printUsage();
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
const image1 = args[0];
|
|
105
|
+
const image2 = args[1];
|
|
106
|
+
const options = {};
|
|
107
|
+
let output;
|
|
108
|
+
let regions;
|
|
109
|
+
let json = false;
|
|
110
|
+
let optStart = 2;
|
|
111
|
+
if (args.length > 2 && !args[2].startsWith("-")) {
|
|
112
|
+
output = args[2];
|
|
113
|
+
optStart = 3;
|
|
114
|
+
}
|
|
115
|
+
for (let i = optStart; i < args.length; i++) {
|
|
116
|
+
const arg = args[i];
|
|
117
|
+
const nextArg = args[i + 1];
|
|
118
|
+
switch (arg) {
|
|
119
|
+
case "--source":
|
|
120
|
+
if (!nextArg || !SOURCES.includes(nextArg)) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`Invalid source: ${nextArg}. Must be one of: ${SOURCES.join(", ")}`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
options.source = nextArg;
|
|
126
|
+
i++;
|
|
127
|
+
break;
|
|
128
|
+
case "-t":
|
|
129
|
+
case "--threshold":
|
|
130
|
+
options.threshold = parseNumber(nextArg, "threshold", 0, 1);
|
|
131
|
+
i++;
|
|
132
|
+
break;
|
|
133
|
+
case "-a":
|
|
134
|
+
case "--antialiasing":
|
|
135
|
+
options.antialiasing = true;
|
|
136
|
+
break;
|
|
137
|
+
case "-c":
|
|
138
|
+
case "--compression":
|
|
139
|
+
options.compression = parseNumber(nextArg, "compression", 0, 9);
|
|
140
|
+
i++;
|
|
141
|
+
break;
|
|
142
|
+
case "--window-size":
|
|
143
|
+
options.windowSize = parseNumber(nextArg, "window-size", 1, 1024);
|
|
144
|
+
i++;
|
|
145
|
+
break;
|
|
146
|
+
case "--region-floor":
|
|
147
|
+
options.regionFloor = parseNumber(nextArg, "region-floor", 0, 1);
|
|
148
|
+
i++;
|
|
149
|
+
break;
|
|
150
|
+
case "--regions":
|
|
151
|
+
if (!nextArg) {
|
|
152
|
+
throw new Error("--regions requires a JSON array");
|
|
153
|
+
}
|
|
154
|
+
regions = nextArg;
|
|
155
|
+
i++;
|
|
156
|
+
break;
|
|
157
|
+
case "--json":
|
|
158
|
+
json = true;
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
console.error(`Unknown option: ${arg}`);
|
|
162
|
+
printUsage();
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const startTime = performance.now();
|
|
167
|
+
let result;
|
|
168
|
+
if (regions !== void 0) {
|
|
169
|
+
if (output !== void 0) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
"--regions does not write a diff visualization; drop the output path"
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
let parsed;
|
|
175
|
+
try {
|
|
176
|
+
parsed = JSON.parse(regions);
|
|
177
|
+
} catch {
|
|
178
|
+
throw new Error("--regions must be valid JSON");
|
|
179
|
+
}
|
|
180
|
+
if (!Array.isArray(parsed)) {
|
|
181
|
+
throw new Error("--regions must be a JSON array of boxes");
|
|
182
|
+
}
|
|
183
|
+
result = await (0, import_interpret_native.interpretRegions)(image1, image2, parsed);
|
|
184
|
+
} else {
|
|
185
|
+
result = await (0, import_interpret_native.interpret)(image1, image2, output, options);
|
|
186
|
+
}
|
|
187
|
+
const duration = performance.now() - startTime;
|
|
188
|
+
console.log(`completed in: ${duration.toFixed(2)}ms`);
|
|
189
|
+
if (json) {
|
|
190
|
+
console.log(JSON.stringify(result, null, 2));
|
|
191
|
+
} else {
|
|
192
|
+
printSummary(result);
|
|
193
|
+
if (output && result.diffCount > 0) {
|
|
194
|
+
console.log(`diff output: ${output}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
process.exit(result.totalRegions === 0 ? 0 : 1);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error(
|
|
200
|
+
"Error:",
|
|
201
|
+
error instanceof Error ? error.message : String(error)
|
|
202
|
+
);
|
|
203
|
+
process.exit(2);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
207
|
+
main();
|
|
208
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazediff/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Command-line interface for the blazediff image comparison library",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -37,9 +37,10 @@
|
|
|
37
37
|
"homepage": "https://blazediff.dev",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@blazediff/core-native": "
|
|
40
|
+
"@blazediff/core-native": "6.0.0",
|
|
41
41
|
"@blazediff/core": "1.10.0",
|
|
42
|
-
"@blazediff/core-wasm": "
|
|
42
|
+
"@blazediff/core-wasm": "6.0.0",
|
|
43
|
+
"@blazediff/interpret-native": "6.0.0",
|
|
43
44
|
"@blazediff/gmsd": "1.7.1",
|
|
44
45
|
"@blazediff/codec-pngjs": "4.0.0",
|
|
45
46
|
"@blazediff/codec-sharp": "4.0.0",
|