Skip to content

feat(filtering): add hough line detection operator - #389

Merged
ivantha merged 1 commit into
c2siorg:mainfrom
rishiraj38:fix/51-hough-lines
Oct 13, 2026
Merged

ivantha merged 1 commit into
c2siorg:mainfrom
rishiraj38:fix/51-hough-lines

Conversation

@rishiraj38

Copy link
Copy Markdown
Contributor

Description

Adds a filtering_houghlines operator built on cv2.HoughLinesP, following the BaseOperator.compute shape of canny_edge.py.

  • imagelab-backend/app/operators/filtering/hough_lines.py: converts the input to grayscale and runs Canny (fixed 50/150, aperture 3) on a copy, runs HoughLinesP on the edge map and draws the segments onto a copy of the original image. Reads rho, thetaDegrees, threshold, minLineLength, maxLineGap, color, thickness from self.params with defaults; thetaDegrees is converted to radians; color goes through hex_to_bgr. Out-of-range values raise ValueError with the same message style as contour_detection.py. Grayscale input is promoted to BGR and BGRA input keeps its alpha (lines drawn opaque), so the output channel count does not depend on whether lines were found. When HoughLinesP returns None the image is returned unchanged.
  • imagelab-backend/app/operators/registry.py: registers filtering_houghlines next to filtering_cannyedge.
  • imagelab-frontend/src/blocks/definitions/filtering.blocks.ts: new block with the seven fields, min/max limits matching the backend checks, and a tooltip noting the fixed Canny thresholds.
  • imagelab-frontend/src/blocks/categories.ts: adds "Hough Line Detection" to the Filtering category.
  • imagelab-frontend/src/data/operatorDocs.ts: docs entry for the operator and its parameters.

Only additions; no existing block types are renamed, so saved workspaces still load. The Canny thresholds are kept fixed because the issue scopes the block to the seven Hough/drawing parameters; exposing them is a follow-up if wanted.

Fixes #51

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

How Has This Been Tested?

Backend, imagelab-backend/tests/operators/filtering/test_hough_lines.py (31 tests): registry lookup; horizontal, vertical and 45 degree synthetic lines (3 px wide so Canny/Hough detection is deterministic) assert the drawn pixels lie within a few px of the known position and angle and span most of the line; segments are drawn on the original image, not the edge map; blank image returned unchanged; input not mutated; grayscale promoted to BGR with and without detections; BGRA keeps alpha; float input in [0,1]; thickness and colour honoured; a monkeypatched HoughLinesP test checks theta is passed in radians and the input is a binary edge map; 13 parameter validation cases plus invalid colour and unsupported shape; one round trip through POST /api/v1/pipeline/executions.

Frontend, imagelab-frontend/tests/blocks/houghLinesBlock.test.ts (5 tests): block defines the seven fields with the backend defaults, numeric fields clamp to the backend ranges, the block is listed in the Filtering category, docs cover every param, and extractPipeline on a real Blockly workspace emits the params by the names the backend reads.

Both files fail without the source change. Ran uv run ruff check ., uv run ruff format --check ., uv run pytest -q (822 passed; test_histogram_stats::test_calculate_channel_statistics_rgb fails on main as well, unrelated), npx eslint ., npx prettier --check, npx tsc -b, npx vitest run (212 passed).

Manual: ran backend and frontend locally, built Read image -> Hough Line Detection on a synthetic image with four lines and a rectangle, ran the pipeline and checked the processed output (screenshots below).

  • Existing tests pass
  • New tests added
  • Manual testing

Screenshots (if applicable)

Pipeline and output after running:

after-output

Operator input and output:

operator-input
operator-output

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review
  • I have added/updated documentation as needed
  • My changes generate no new warnings
  • Tests pass locally

@ivantha ivantha added enhancement New feature or request ready-for-maintainer Reviewed; looks mergeable, awaiting maintainer labels Oct 13, 2026
@ivantha

ivantha commented Oct 13, 2026

Copy link
Copy Markdown
Member

Automated review summary

Triage: enhancement | Recommendation: ready-for-maintainer

Findings

  • [nit/bug] imagelab-backend/app/operators/filtering/hough_lines.py:88 The draw colour is always a 0-255 BGR tuple, but the result canvas keeps the input dtype. Float [0,1] or uint16 inputs get saturated or near-black lines, because the input is only normalised to uint8 for Canny and not for drawing. The float test passes only because it asserts the raw 255.0 value. In practice the pipeline likely decodes to uint8, so this is low impact.
  • [nit/quality] imagelab-backend/app/operators/filtering/hough_lines.py:29 Validation does not reject NaN. A NaN rho or thetaDegrees passes both comparison checks and is passed on to OpenCV. Params come from JSON, so this is unlikely, but not (0.1 <= rho <= 10) would cover it.

Conventions

  • PR title: follows Conventional Commits
  • Description: clear and complete
  • Commits (1): clean, conventional history

This PR adds a filtering_houghlines operator built on cv2.HoughLinesP. It includes parameter validation, handling for grayscale and BGRA input, registry wiring, a Blockly block, operator docs, and thorough backend and frontend tests. The logic is correct and follows the existing operator patterns. The only remarks are non-blocking nits: the drawing colour is not scaled for float or uint16 images, and NaN slips through the range checks. It looks ready for maintainer review.

Generated by /review-prs. A maintainer will follow up.

Add a filtering_houghlines operator that runs Canny on a grayscale copy
of the input, feeds the edge map to cv2.HoughLinesP and draws the
detected segments onto the original image. rho, thetaDegrees, threshold,
minLineLength, maxLineGap, color and thickness are read from params with
defaults and range-checked; thetaDegrees is converted to radians.
Grayscale input is promoted to BGR and BGRA keeps its alpha so the output
channel count does not depend on whether any lines were found. When
HoughLinesP returns None the image comes back unchanged.

Register the operator, add the Blockly block to the Filtering category
with matching field limits, add an operatorDocs entry, and cover the
backend with synthetic line images, parameter validation and an API
round trip, plus a frontend test for the block definition.

Closes c2siorg#51
@ivantha
ivantha force-pushed the fix/51-hough-lines branch from 3578a6b to 8f27d7c Compare October 13, 2026 17:17
@ivantha
ivantha merged commit 073968b into c2siorg:main Oct 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-maintainer Reviewed; looks mergeable, awaiting maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Hough line detection operator

2 participants