Skip to content

Fix review bugs and iterate contour alignment - #13

Merged
tengjuilin merged 1 commit into
mainfrom
review-fixes
Oct 22, 2026
Merged

tengjuilin merged 1 commit into
mainfrom
review-fixes

Conversation

@tengjuilin

Copy link
Copy Markdown
Owner

Summary

Fixes from the code review, plus iterative (generalized Procrustes) alignment.

Bugs

  • One principal component collapsed clustering. After the Normalizer, one PC maps every contour to +1 or -1, so K-means found at most 2 modes and empty modes were silently filled with the overall mean contour. Vampire now keeps at least 2 PCs (an int n_components < 2 raises; a variance fraction reached by one PC keeps 2), and fit raises when K-means leaves a mode empty.
  • read_images crashed on hidden files such as macOS ._name.tif sidecars. Hidden files are skipped; unreadable files raise OSError naming the file.
  • Tiny objects: new extract_properties(min_area=...); circularity is NaN instead of inf for zero perimeter.
  • Edge-truncated objects: new extract_properties(exclude_border=True) (skimage.segmentation.clear_border).
  • score depended on n_components (it was minus the K-means inertia in normalized PC space). It is now minus the mean squared point distance of each normalized contour to its mode's mean contour; inertia_ is unchanged.

Improvement

  • ContourAligner(max_iter=30, tol=1e-6) refines the reference by aligning to the mean, recomputing the mean, and repeating; passes are stored in n_iter_, and max_iter=1 keeps the old single pass. On the example images it converges in 12 passes and lowers the mean squared spread around the mean from 4.65 to 4.19.

Changed results: the example-image fit now keeps 21 components instead of 20 and has different mode sizes; tests/data/integration_golden.npz was regenerated for this intentional change.

Docs (method, choosing shape modes, data conventions, GUI differences, tutorial, agent summary) and the changelog are updated.

Test plan

  • uv run pytest: 358 passed (new tests for each fix and for alignment convergence, spread reduction and reference drift)
  • ruff check / ruff format --check
  • sphinx-build -E -W --keep-going passes; executed outputs checked against the prose

🤖 Generated with Claude Code

- Vampire keeps at least 2 principal components: with one, the Normalizer
  maps every score to +1 or -1 and K-means finds at most two modes. An
  integer n_components < 2 raises; a variance fraction reached by one
  component keeps 2.
- Vampire.fit raises when K-means leaves a shape mode empty instead of
  filling it with the overall mean contour.
- Vampire.score is minus the mean squared point distance of each normalized
  contour to its mode's mean contour, so it no longer depends on
  n_components (inertia_ still does).
- extract_properties: min_area and exclude_border options; circularity is
  NaN instead of inf for zero perimeter.
- read_images skips hidden files (macOS ._name.tif) and names the file when
  one cannot be read.
- ContourAligner refines its reference by generalized Procrustes analysis
  (max_iter=30, tol=1e-6, n_iter_); max_iter=1 keeps the single pass.

Integration golden data regenerated: iterative alignment intentionally
changes the example-image fit (n_components_ 20 -> 21, new mode sizes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tengjuilin
tengjuilin merged commit 60673e0 into main Oct 22, 2026
6 checks passed
@tengjuilin
tengjuilin deleted the review-fixes branch October 22, 2026 21:24
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.

1 participant