apertaluce 0.3.0 → 0.3.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/lib/image/mark.d.ts +4 -2
- package/lib/image/mark.js +34 -12
- package/package.json +1 -1
package/lib/image/mark.d.ts
CHANGED
|
@@ -59,8 +59,8 @@ export interface PixelMarkResult {
|
|
|
59
59
|
* shift of the grids the synchronisation peaks propose, so its cut is higher.
|
|
60
60
|
*
|
|
61
61
|
* Measured (docs/MEASURED.md) on unmarked pictures, as they are and inside a
|
|
62
|
-
* page. Search: 2,
|
|
63
|
-
* exponential fit to the top tenth puts the chance of passing 7.5 at about
|
|
62
|
+
* page. Search: 2,168 scores, no detection, highest 6.33, 99 % under 5.88; an
|
|
63
|
+
* exponential fit to the top tenth puts the chance of passing 7.5 at about 1 in
|
|
64
64
|
* a million per picture and key. Aligned test alone: 1,610 scores, highest 4.68;
|
|
65
65
|
* the same fit gives about 5 in ten million for 6.5. Both are extrapolations,
|
|
66
66
|
* not counts.
|
|
@@ -153,6 +153,8 @@ declare function searchByPeaks(w: Whitened & {
|
|
|
153
153
|
factor: number;
|
|
154
154
|
}, key: PixelKey, scratch: FoldScratch, sharp?: Whitened & {
|
|
155
155
|
factor: number;
|
|
156
|
+
}, middle?: Whitened & {
|
|
157
|
+
factor: number;
|
|
156
158
|
}): PeakSearchResult | null;
|
|
157
159
|
/** For the robustness bench and tests only. */
|
|
158
160
|
export declare const __internals: {
|
package/lib/image/mark.js
CHANGED
|
@@ -528,8 +528,8 @@ export function pixelMarkPlane(width, height, key, tilesPerShortSide = TILES_PER
|
|
|
528
528
|
* shift of the grids the synchronisation peaks propose, so its cut is higher.
|
|
529
529
|
*
|
|
530
530
|
* Measured (docs/MEASURED.md) on unmarked pictures, as they are and inside a
|
|
531
|
-
* page. Search: 2,
|
|
532
|
-
* exponential fit to the top tenth puts the chance of passing 7.5 at about
|
|
531
|
+
* page. Search: 2,168 scores, no detection, highest 6.33, 99 % under 5.88; an
|
|
532
|
+
* exponential fit to the top tenth puts the chance of passing 7.5 at about 1 in
|
|
533
533
|
* a million per picture and key. Aligned test alone: 1,610 scores, highest 4.68;
|
|
534
534
|
* the same fit gives about 5 in ten million for 6.5. Both are extrapolations,
|
|
535
535
|
* not counts.
|
|
@@ -930,7 +930,7 @@ export function detectPixelMark(image, key, options = {}) {
|
|
|
930
930
|
// The peaks are looked for in a reduced picture; the grid they give is then checked on one
|
|
931
931
|
// sharp enough to still hold the fine part of the mark.
|
|
932
932
|
const sharp = w.factor === 1 ? w : whiten(image, 1100);
|
|
933
|
-
const found = searchByPeaks(coarse, key, scratch, sharp.factor < coarse.factor ? sharp : coarse);
|
|
933
|
+
const found = searchByPeaks(coarse, key, scratch, sharp.factor < coarse.factor ? sharp : coarse, w);
|
|
934
934
|
if (found && found.score >= SEARCH_CUT) {
|
|
935
935
|
return {
|
|
936
936
|
detected: true,
|
|
@@ -1050,7 +1050,7 @@ function peakSpectrum(w) {
|
|
|
1050
1050
|
const v = i >> 10;
|
|
1051
1051
|
const fu = u < half ? u : u - n;
|
|
1052
1052
|
const fv = v < half ? v : v - n;
|
|
1053
|
-
if (fu * fu + fv * fv <
|
|
1053
|
+
if (fu * fu + fv * fv < MIN_PEAK_RADIUS_SQ)
|
|
1054
1054
|
continue;
|
|
1055
1055
|
const value = peaks[i] > PEAK_CAP ? PEAK_CAP : peaks[i];
|
|
1056
1056
|
sum += value;
|
|
@@ -1060,6 +1060,13 @@ function peakSpectrum(w) {
|
|
|
1060
1060
|
const peakMean = sum / count;
|
|
1061
1061
|
return { n, power, peaks, peakMean, peakSpread: Math.sqrt(Math.max(1e-6, sumSq / count - peakMean * peakMean)) };
|
|
1062
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Bins nearer the centre of the spectrum than this hold what is left of the picture's own slow
|
|
1065
|
+
* changes (and of a page's layout) after whitening, not peaks; a constellation point that falls
|
|
1066
|
+
* there does not count.
|
|
1067
|
+
*/
|
|
1068
|
+
const MIN_PEAK_RADIUS = 24;
|
|
1069
|
+
const MIN_PEAK_RADIUS_SQ = MIN_PEAK_RADIUS * MIN_PEAK_RADIUS;
|
|
1063
1070
|
/** How many turned grids the search hands on to be checked by folding. */
|
|
1064
1071
|
const SQUARE_GRIDS_KEPT = 12;
|
|
1065
1072
|
/** A peak far above its ring counts no more than this: one line of the picture must not outvote the constellation. */
|
|
@@ -1112,7 +1119,7 @@ function constellationScore(spectrum, sync, fu, fv) {
|
|
|
1112
1119
|
const [u, v] = sync[i];
|
|
1113
1120
|
const kx = Math.round(n * (u * fu[0] + v * fv[0]));
|
|
1114
1121
|
const ky = Math.round(n * (u * fu[1] + v * fv[1]));
|
|
1115
|
-
if (kx >= half - 1 || kx <= 1 - half || ky >= half - 1 || ky <= 1 - half || kx * kx + ky * ky <
|
|
1122
|
+
if (kx >= half - 1 || kx <= 1 - half || ky >= half - 1 || ky <= 1 - half || kx * kx + ky * ky < MIN_PEAK_RADIUS_SQ)
|
|
1116
1123
|
continue;
|
|
1117
1124
|
const value = peaks[((ky + n) % n) * n + ((kx + n) % n)];
|
|
1118
1125
|
const part = i < SYNC_PEAKS ? 0 : 1;
|
|
@@ -1148,7 +1155,7 @@ function searchSquareGrids(spectrum, key, minPeriod, maxPeriod) {
|
|
|
1148
1155
|
for (let i = 0; i < count; i++) {
|
|
1149
1156
|
const kx = Math.round(cos[i] * inverse);
|
|
1150
1157
|
const ky = Math.round(sin[i] * inverse);
|
|
1151
|
-
if (kx >= half - 1 || kx <= 1 - half || ky >= half - 1 || ky <= 1 - half || kx * kx + ky * ky <
|
|
1158
|
+
if (kx >= half - 1 || kx <= 1 - half || ky >= half - 1 || ky <= 1 - half || kx * kx + ky * ky < MIN_PEAK_RADIUS_SQ)
|
|
1152
1159
|
continue;
|
|
1153
1160
|
const value = peaks[((ky + n) & (n - 1)) * n + ((kx + n) & (n - 1))];
|
|
1154
1161
|
const capped = value > PEAK_CAP ? PEAK_CAP : value;
|
|
@@ -1209,7 +1216,7 @@ function searchAnyGrids(spectrum, key, minPeriod, maxPeriod) {
|
|
|
1209
1216
|
for (let kx = -half + 2; kx < half - 2; kx++) {
|
|
1210
1217
|
if (ky === 0 && kx <= 0)
|
|
1211
1218
|
continue;
|
|
1212
|
-
if (kx * kx + ky * ky <
|
|
1219
|
+
if (kx * kx + ky * ky < MIN_PEAK_RADIUS_SQ)
|
|
1213
1220
|
continue;
|
|
1214
1221
|
const row = ky * n;
|
|
1215
1222
|
const col = (kx + n) & (n - 1);
|
|
@@ -1379,10 +1386,12 @@ function refineGrid(w, key, scratch, start, first) {
|
|
|
1379
1386
|
}
|
|
1380
1387
|
return best;
|
|
1381
1388
|
}
|
|
1382
|
-
function searchByPeaks(w, key, scratch, sharp = w) {
|
|
1389
|
+
function searchByPeaks(w, key, scratch, sharp = w, middle) {
|
|
1383
1390
|
if (key.sync.length < 2 * SYNC_PEAKS - 2)
|
|
1384
1391
|
return null;
|
|
1385
|
-
|
|
1392
|
+
let spectrum = peakSpectrum(w);
|
|
1393
|
+
/** What the spectrum in use was taken from; candidate grids are in its pixels. */
|
|
1394
|
+
let from = w;
|
|
1386
1395
|
const maxPeriod = Math.max(w.width, w.height) * 1.5;
|
|
1387
1396
|
const minPeriod = 24;
|
|
1388
1397
|
let best = null;
|
|
@@ -1390,8 +1399,8 @@ function searchByPeaks(w, key, scratch, sharp = w) {
|
|
|
1390
1399
|
for (const candidate of candidates) {
|
|
1391
1400
|
const fitted = fitGrid(spectrum, key.sync, candidate);
|
|
1392
1401
|
for (const grid of fitted ? [fitted] : [candidate]) {
|
|
1393
|
-
// Cycles per pixel of the
|
|
1394
|
-
const ratio = sharp.factor /
|
|
1402
|
+
// Cycles per pixel of the picture the spectrum came from, in pixels of the sharp one.
|
|
1403
|
+
const ratio = sharp.factor / from.factor;
|
|
1395
1404
|
const onSharp = { score: grid.score, fu: [grid.fu[0] * ratio, grid.fu[1] * ratio], fv: [grid.fv[0] * ratio, grid.fv[1] * ratio] };
|
|
1396
1405
|
let result = verifyGrid(sharp, key, scratch, onSharp);
|
|
1397
1406
|
// The peaks give the grid to about a bin of the spectrum; the fine part of the mark only
|
|
@@ -1399,7 +1408,8 @@ function searchByPeaks(w, key, scratch, sharp = w) {
|
|
|
1399
1408
|
// mark faintly is nudged in scale and angle to where it shows best.
|
|
1400
1409
|
if (result.score >= REFINE_FROM)
|
|
1401
1410
|
result = refineGrid(sharp, key, scratch, onSharp, result);
|
|
1402
|
-
|
|
1411
|
+
// Reported in pixels of the reduced picture, as the caller expects.
|
|
1412
|
+
result.period = [(result.period[0] * sharp.factor) / w.factor, (result.period[1] * sharp.factor) / w.factor];
|
|
1403
1413
|
result.sync = constellationScore(spectrum, key.sync, grid.fu, grid.fv);
|
|
1404
1414
|
if (!best || result.score > best.score)
|
|
1405
1415
|
best = result;
|
|
@@ -1411,6 +1421,18 @@ function searchByPeaks(w, key, scratch, sharp = w) {
|
|
|
1411
1421
|
};
|
|
1412
1422
|
if (consider(searchUprightGrids(spectrum, key, minPeriod, maxPeriod)))
|
|
1413
1423
|
return best;
|
|
1424
|
+
const reduced = spectrum;
|
|
1425
|
+
if (middle && middle.factor < w.factor) {
|
|
1426
|
+
// The reduced picture has lost the fine peaks. An upright copy is looked for once more in a
|
|
1427
|
+
// sharper one (its middle, when it is larger than the transform), where they still stand.
|
|
1428
|
+
spectrum = peakSpectrum(middle);
|
|
1429
|
+
from = middle;
|
|
1430
|
+
const found = consider(searchUprightGrids(spectrum, key, minPeriod, Math.max(middle.width, middle.height) * 1.5));
|
|
1431
|
+
spectrum = reduced;
|
|
1432
|
+
from = w;
|
|
1433
|
+
if (found)
|
|
1434
|
+
return best;
|
|
1435
|
+
}
|
|
1414
1436
|
if (consider(searchSquareGrids(spectrum, key, minPeriod, maxPeriod)))
|
|
1415
1437
|
return best;
|
|
1416
1438
|
consider(searchAnyGrids(spectrum, key, minPeriod, maxPeriod).slice(0, 4));
|
package/package.json
CHANGED