Spaces:
Paused
Paused
File size: 2,787 Bytes
b5af7d6 f65c627 b5af7d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """A review result for every decodable pair; no fabricated confidence scores."""
import time
from .registration import register
from .common import RegistrationError
SCORE_DESCRIPTION = (
'Percentage of proposed feature matches consistent with the global transform. '
'Not iris similarity, percentage of aligned fibers, or accuracy. '
'A high percentage can still accompany an unreliable transformation.'
)
def review_pair(reference, moving, exposure=True, local=True, engine="classical"):
started = time.perf_counter()
try:
if engine == "learned":
from .learned_registration import register_learned
result = register_learned(reference, moving, exposure=exposure, local=local)
elif engine == "classical":
result = register(reference, moving, exposure=exposure, local=local)
else:
raise ValueError("Unknown registration engine.")
metrics = result['metrics']
metrics.update(status='review_required', status_label='Alignment preview — review required',
reason=None, suggestions=[
'Inspect corresponding fibers and crypts at 100% pixels before using the composite.',
'Review glare and occluded regions separately; they may have no usable counterpart.'
])
except RegistrationError as exc:
# Original images only: never relabel a failed warp as an aligned result.
metrics = dict(exc.diagnostics)
metrics.update(status='unaligned', status_label='Not aligned — reference preserved',
reason=str(exc), transform=None, fit_error_px=None,
exposure_gain=1., blended_fraction=0.,
local={'applied': False, 'reason': 'Alignment rejected'},
runtime_seconds=round(time.perf_counter()-started, 3),
warning='No registered or merged output was produced. The reference is unchanged.',
suggestions=[
'Crop both originals tightly around the same iris, keeping the entire iris visible.',
'Choose the clearest, better-exposed photograph as reference.',
'If it still fails, use landmark-assisted review rather than forcing a merge.'
])
result = {'metrics': metrics}
result.update(reference=reference, moving=moving)
metrics.setdefault('engine', 'learned_experimental' if engine == 'learned' else 'classical')
ratio = metrics.get('inlier_ratio')
metrics['match_support_percent'] = round(100 * ratio, 1) if ratio is not None else None
metrics['score_description'] = SCORE_DESCRIPTION
return result
|