From 6402325fc503139ccc00881fdd60a51fb8558b71 Mon Sep 17 00:00:00 2001 From: Pruthviraj Gojare Date: Sun, 22 Nov 2026 00:27:53 +0530 Subject: [PATCH 1/2] Add Laplacian filter doctests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../filters/laplacian_filter.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 69b9616e4d30..8a589690376a 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -27,6 +27,20 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: Traceback (most recent call last): ... ValueError: ksize must be in (1, 3, 5, 7) + + The supported kernel sizes process a small grayscale array without an + image file. The 5x5 and 7x7 kernels also work with an image smaller than + the kernel, using OpenCV's default border handling. + + >>> image = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=np.uint8) + >>> my_laplacian(image, 1).tolist() + [[4.0, -2.0, 4.0], [-2.0, 0.0, -2.0], [4.0, -2.0, 4.0]] + >>> my_laplacian(image, 3).tolist() + [[-4.0, 2.0, -4.0], [2.0, 0.0, 2.0], [-4.0, 2.0, -4.0]] + >>> my_laplacian(image, 5).tolist() + [[-4.0, -4.0, -4.0], [-4.0, 12.0, -4.0], [-4.0, -4.0, -4.0]] + >>> my_laplacian(image, 7).tolist() + [[56.0, -30.0, 56.0], [-30.0, -28.0, -30.0], [56.0, -30.0, 56.0]] """ kernels = { 1: np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]]), From 245b0540ea3580b64dc264a1ce46eb562d1d07f0 Mon Sep 17 00:00:00 2001 From: Pruthviraj Gojare Date: Sun, 22 Nov 2026 00:28:02 +0530 Subject: [PATCH 2/2] Record Laplacian coverage evidence Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- work/R23-T050/BASELINE.md | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 work/R23-T050/BASELINE.md diff --git a/work/R23-T050/BASELINE.md b/work/R23-T050/BASELINE.md new file mode 100644 index 000000000000..ed77d2148851 --- /dev/null +++ b/work/R23-T050/BASELINE.md @@ -0,0 +1,58 @@ +# Laplacian filter baseline + +## Input categories for `my_laplacian` + +- Valid: a NumPy grayscale or color image and a `ksize` of 1, 3, 5, or 7. +- Boundary: the smallest and largest supported kernel sizes (1 and 7), and a + 3x3 source array smaller than the 5x5 and 7x7 kernels. +- Invalid: a kernel size outside the supported set, such as 0. The existing + doctest verifies the `ValueError`; the invalid size is checked before the + source image is passed to OpenCV. + +## Coverage before the change + +The requested baseline command was attempted: + +```bash +uv run --python 3.12 --with numpy --with opencv-python-headless --with pytest --with pytest-cov pytest digital_image_processing/filters/laplacian_filter.py --cov=digital_image_processing/filters --cov-report=term-missing +``` + +It could not start because this checkout declares `requires-python = ">=3.15"`, +which rejects Python 3.12. The same test was run successfully using uv's +temporary, no-project mode: + +```bash +uv run --no-project --python 3.12 --with numpy --with opencv-python-headless --with pytest --with pytest-cov pytest digital_image_processing/filters/laplacian_filter.py --cov=digital_image_processing/filters --cov-report=term-missing +``` + +Baseline result: 1 test passed; `laplacian_filter.py` had 17 statements, 8 +missed, and 53% coverage. The uncovered lines were line 60 (the return path in +`my_laplacian`) and lines 67–81 (the interactive image-display example). The +invalid-`ksize` doctest already covered the error path. + +Coverage for the other filters in `digital_image_processing/filters` was not +the target of this task. The baseline command also warned that Python 3.12 +coverage could not parse the unrelated `local_binary_pattern.py`. + +## Results after the doctests + +The Python 3.12 no-project coverage command passed: 1 pytest item passed. +`laplacian_filter.py` reports 59% module coverage because only the interactive +`__main__` example (lines 81–95 after the doctest additions) remains uncovered. +All executable statements inside `my_laplacian` are covered: 6 of 6 (100%), +including each kernel-size lookup, the `ValueError` path, and the valid return +path. The same unrelated `local_binary_pattern.py` parsing warning remains. + +The direct doctest command was: + +```bash +uv run --no-project --python 3.12 --with numpy --with opencv-python-headless --with pytest python -m doctest -v digital_image_processing/filters/laplacian_filter.py +``` + +Its summary was: + +```text +6 tests in 2 items. +6 passed and 0 failed. +Test passed. +```