Skip to content

test: raise coverage of ImageSpatial from 62% to 97% and ImageProcessing from 72% to 98% - #223

Merged
petercorke merged 6 commits into
mainfrom
test/image-coverage-spatial-processing
Nov 22, 2026
Merged

petercorke merged 6 commits into
mainfrom
test/image-coverage-spatial-processing

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Second of three changes lifting coverage of the last Image*.py modules. ImageSpatial.py goes from 62% to 97% and ImageProcessing.py from 72% to 98%.

The tests are in two new files, tests/test_image_spatial_extra.py and tests/test_image_processing_extra.py. They use small synthetic images and work the expected values out directly in NumPy, so nothing is mocked:

  • ImageSpatial: convolve (every mode, padding with a value, image and Kernel kernels), gradients, direction, Harris_corner_strength, window, zerocross, scalespace, pyramid, canny on a square, rankfilter and medianfilter (compared with scipy.ndimage), distance_transform, labels_binary (4 and 8 connectivity), labels_MSER, labels_graphseg, the six similarity measures (compared with their formulae) and similarity, which must peak at the template's position.
  • ImageProcessing: apply, apply2, clip, roll, invert, LUT, normhist, stretch, every threshold method and the automatic otsu, triangle and percentile choices, the deprecated thresh, t= and opt= forms, threshold_adaptive, blend, choose and paste (every method and position, mono and color). The interactive threshold is driven with simulated mouse events on its slider, and the notebook-widget version runs where ipywidgets is installed.

Four bugs found while writing these are recorded as strict xfail tests, not fixed here, so whoever fixes one has to remove its marker:

  1. canny ignores sigma, th0 and th1: it takes its thresholds from the mean of the image.
  2. sad, ssd and ncc wrap around at 256 on uint8 images (ncc can exceed 1).
  3. similarity with a z metric subtracts the mean from the template in place, which changes the caller's template, and fails on uint8 images.
  4. blend(dtype="double"), and blending float64 images, return float32.

Testing

pytest tests: 1926 passed, 33 skipped, 12 xfailed. black, ruff check and mypy report no issues. Nothing is mocked except plt.show in the interactive threshold tests, which plays the part of the user dragging the slider. The graph segmentation test needs opencv-contrib-python and the notebook-widget test needs ipywidgets; each is skipped without its package. Not run: CI on Windows or OpenCV 4 (CI will).

This change was written with AI assistance (Claude Code) and the diff has been read by the maintainer.

🤖 Generated with Claude Code

petercorke and others added 2 commits November 22, 2026 20:02
…ing from 72% to 98%

The tests use small synthetic images with values worked out directly in NumPy:
rank filters are compared with scipy.ndimage, the similarity measures with
their formulae, and the interactive thresholds are driven with simulated mouse
events.

Four bugs are recorded as strict xfail tests: canny ignores sigma, th0 and th1,
sad, ssd and ncc wrap around on uint8 images, the z similarity metrics change
the caller's template and fail on uint8 images, and blend loses float64.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 192 complexity · 0 duplication

Metric Results
Complexity 192
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

petercorke and others added 4 commits November 22, 2026 20:42
OpenCV 5.1 gives 0.0156 at the match, not 0, from float32 sums of squares.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Some OpenCV 5.1 builds have cv2.ximgproc without its segmentation module.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke merged commit f790c6e into main Nov 22, 2026
32 checks passed
@petercorke
petercorke deleted the test/image-coverage-spatial-processing branch November 22, 2026 11:21
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