Skip to content

fix: align preprocess_image preflight order with IEP-0004#2

Open
titusz wants to merge 1 commit into
mainfrom
fix/preflight-order-iep-0004
Open

fix: align preprocess_image preflight order with IEP-0004#2
titusz wants to merge 1 commit into
mainfrom
fix/preflight-order-iep-0004

Conversation

@titusz
Copy link
Copy Markdown
Member

@titusz titusz commented May 14, 2026

Closes #1.

Summary

  • Swap trim_border and remove_transparency in iscc_sci/code_semantic_image.py:preprocess_image so the order is exif_transpose → remove_transparency → trim_border → resize, matching the normative order in IEP-0004 and iscc_sdk.image.image_normalize.
  • Filling transparency first gives trim_border a deterministic, encoder-independent reference pixel (img.getpixel((0,0))) and prevents bilinear resize from pulling RGB values out from under transparent pixels.
  • Update test fixtures for demo.gif (the only sample with transparency); all other samples (bmp, jpg, png, psd, tif) produce bit-identical codes before/after.

See #1 for full rationale, impact table, and references.

Output-byte impact (verified on iscc_samples)

File Code before Code after Δ
demo.bmp ISCC:CEAQ2WTPK2QPZTK4 ISCC:CEAQ2WTPK2QPZTK4 identical
demo.gif ISCC:CEAQ2WT7K2Q7YTO4 ISCC:CEAQ2UTPK2Q7ZTK4 changed (palette transparency)
demo.jpg ISCC:CEAQYWTPK2Q7ZTK4 ISCC:CEAQYWTPK2Q7ZTK4 identical
demo.png ISCC:CEAQ2WTPK2Q7ZTK4 ISCC:CEAQ2WTPK2Q7ZTK4 identical
demo.psd ISCC:CEAQ2WTPK2Q7ZTK4 ISCC:CEAQ2WTPK2Q7ZTK4 identical
demo.tif ISCC:CEAQYWTPK2Q7ZTK4 ISCC:CEAQYWTPK2Q7ZTK4 identical

Pre-1.0 the project explicitly allows incompatible Semantic-Codes between releases, so backward compatibility on the alpha+border subset is not a constraint.

Test plan

  • uv run pytest tests/ — 27 passed
  • Capture codes on all iscc_samples images, before vs. after — only demo.gif (palette transparency) changes; opaque inputs are bit-identical
  • Update test_code_image_semantic_256bit and test_code_image_semantic_embedding_precision fixtures for the new demo.gif output

Swap trim_border and remove_transparency in preprocess_image so the
order matches IEP-0004 (exif_transpose -> remove_transparency ->
trim_border -> resize) and iscc-sdk.image_normalize.

Running remove_transparency first gives trim_border a deterministic,
encoder-independent reference pixel and avoids alpha-edge halos
during the subsequent resize.

For opaque inputs the resulting tensor is bit-identical; only inputs
combining transparency and a uniform border can produce different
Semantic-Codes. Pre-1.0 the project allows this kind of change.

Refs #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preflight order in preprocess_image deviates from IEP-0004 normative order

1 participant