Skip to content

feat: add step-wise visualization images in CropPage processor#274

Open
Meenakshi-1802 wants to merge 5 commits into
Udayraj123:masterfrom
Meenakshi-1802:add-step-images
Open

feat: add step-wise visualization images in CropPage processor#274
Meenakshi-1802 wants to merge 5 commits into
Udayraj123:masterfrom
Meenakshi-1802:add-step-images

Conversation

@Meenakshi-1802
Copy link
Copy Markdown

@Meenakshi-1802 Meenakshi-1802 commented Mar 28, 2026

Fixes #44

Added step-wise visualization images in CropPage processor for intuitive understanding of the processing pipeline.

Steps added (visible when show_image_level >= 4):

  1. 1_grayscale_input - Original grayscale image before processing
Screenshot 2026-03-28 152520
  1. 2_gaussian_blur - After Gaussian blur + normalize
image
  1. 3_threshold - After THRESH_TRUNC + normalize
image
  1. 4_morph_close - After morphological close (gap filling)
image
  1. 5_canny_edges - Canny edge detection result
image
  1. 6a_contour_on_image - Detected page contour drawn on image
image
  1. 6b_contour_on_edge - Detected page contour drawn on edge map
image

Tested on samples/sample1 with show_image_level: 5

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Add step-wise visualization images to CropPage processor

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add step-wise visualization images in CropPage processor
• Display intermediate processing stages at show_image_level >= 4
• Show 7 debug images: grayscale, blur, threshold, morph, edges, contours
• Lower threshold from 5 to 4 for more detailed debugging
Diagram
flowchart LR
  A["Input Image"] --> B["1. Grayscale Input"]
  B --> C["2. Gaussian Blur"]
  C --> D["3. Threshold"]
  D --> E["4. Morph Close"]
  E --> F["5. Canny Edges"]
  F --> G["6a. Contour on Image"]
  F --> H["6b. Contour on Edge"]
  G --> I["Output"]
  H --> I
Loading

Grey Divider

File Changes

1. src/processors/CropPage.py ✨ Enhancement +20/-3

Add intermediate step visualization images

• Added 7 intermediate visualization checkpoints throughout image processing pipeline
• Display images at show_image_level >= 4: grayscale input, gaussian blur, threshold, morphological
 close, canny edges, and two contour visualizations
• Changed edge detection debug threshold from level 5 to level 4 for consistency
• Added blank lines for improved code formatting and readability

src/processors/CropPage.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Mar 28, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider


Action required

1. Removed edge visual output📎
Description
The previous step-wise output named edge is no longer generated; it has been replaced with
5_canny_edges. This can break the expected/previous Rich Visuals step-wise outputs when running
with show_image_level 4 or 5.
Code

src/processors/CropPage.py[R121-122]

+        if config.outputs.show_image_level >= 4:
+            InteractionUtils.show("5_canny_edges", edge, config=config)
Evidence
PR Compliance ID 1 requires existing step-wise images to continue being generated and accessible at
show_image_level 4 or 5. The updated code now outputs 5_canny_edges and there is no remaining
InteractionUtils.show("edge", ...) call anywhere in src/, meaning the prior edge-named output
is no longer produced.

Step-wise visual output images are available at higher show_image_level settings
src/processors/CropPage.py[117-123]
src/processors/CropPage.py[121-122]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The step-wise visual output previously emitted as `edge` is no longer generated (it was renamed to `5_canny_edges`). Compliance requires that existing step-wise images remain available at `show_image_level` 4 or 5.
## Issue Context
Removing/renaming an existing visual output can break users’ expectations and any tooling/docs that reference the older `edge` image.
## Fix Focus Areas
- src/processors/CropPage.py[117-123]
## Suggested approach
- Either keep the original name (`edge`) or emit both names for backward compatibility (e.g., show `edge` and `5_canny_edges`, possibly gated so it doesn’t duplicate in normal usage).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Debug visuals block pipeline🐞
Description
CropPage now calls InteractionUtils.show() multiple times without overriding the default pause=1, so
runs with outputs.show_image_level >= 4 will repeatedly stop and wait for a user 'q' keypress before
continuing. This makes batch runs effectively non-progressing unless a user is present to advance
each step.
Code

src/processors/CropPage.py[R69-77]

+        config = self.tuning_config
+        if config.outputs.show_image_level >= 4:
+            InteractionUtils.show("1_grayscale_input", image, config=config)
+
    image = normalize(cv2.GaussianBlur(image, DEFAULT_GAUSSIAN_BLUR_KERNEL, 0))
+        if config.outputs.show_image_level >= 4:
+            InteractionUtils.show("2_gaussian_blur", image, config=config)
+
Evidence
The new step visualizations are triggered at show_image_level>=4 and call InteractionUtils.show()
with no pause argument. InteractionUtils.show() defaults pause=1 and explicitly blocks in wait_q()
until the user presses 'q' or ESC, meaning each added step introduces a new manual stop.

src/processors/CropPage.py[68-80]
src/utils/interaction.py[27-80]
src/defaults/config.py[27-33]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`CropPage` added multiple `InteractionUtils.show(...)` calls gated by `show_image_level >= 4`, but these calls rely on `InteractionUtils.show()` defaults (`pause=1`). This blocks processing until the user presses `q` for every step.
## Issue Context
`InteractionUtils.show()` blocks when `pause` is truthy (default), via `wait_q()`.
## Fix Focus Areas
- src/processors/CropPage.py[68-77]
- src/processors/CropPage.py[103-123]
- src/processors/CropPage.py[155-157]
## Suggested fix
Pass `pause=0` for intermediate step images (or add a dedicated config flag controlling pause behavior), and optionally pause only on the final step if you still want a step-through experience.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

3. Contour step shown on failure🐞
Description
find_page() always shows the '6a_contour_on_image'/'6b_contour_on_edge' windows even when no valid
page contour was found (sheet remains empty), so the step name implies a detected contour when the
visualization may contain none. This can mislead debugging because the failure case is visualized
under a success-sounding label.
Code

src/processors/CropPage.py[R155-157]

+        if config.outputs.show_image_level >= 4:
+            InteractionUtils.show("6a_contour_on_image", image, config=config)
+            InteractionUtils.show("6b_contour_on_edge", edge, config=config)
Evidence
sheet starts as an empty list and is only populated inside the validate_rect(approx) branch; the
new InteractionUtils.show("6a..."/"6b...") calls are outside the contour-validation block and run
regardless of whether sheet was populated. The caller treats an empty sheet as an error and
returns None, meaning these windows can appear even in the failure path.

src/processors/CropPage.py[130-157]
src/processors/CropPage.py[79-84]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The contour visualization step names (`6a_contour_on_image`, `6b_contour_on_edge`) are shown even when no contour is found, which can mislead users during debugging.
## Issue Context
`sheet` remains empty when no validated rectangle contour is found, but the step-6 visualizations are shown unconditionally.
## Fix Focus Areas
- src/processors/CropPage.py[130-157]
- src/processors/CropPage.py[155-157]
## Suggested fix
Either:
1) Only show step-6 windows when `len(sheet) != 0`, OR
2) Rename the windows to reflect that they are the "contour search result" (success or failure), and/or add a distinct label when no contour was detected.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread src/processors/CropPage.py Outdated
@Meenakshi-1802
Copy link
Copy Markdown
Author

Hi @Udayraj123, I have addressed the bot's feedback:

  1. Preserved the original edge visual output at level 5 for backward compatibility
  2. Fixed contour visualization to only show when a page is detected

Please review when you get a chance. Thanks!

@Udayraj123
Copy link
Copy Markdown
Owner

@Meenakshi-1802 thanks for adding this, can you please divide the show image thresholds into different start values, keep a few images visible only on higher values like 5 and 6

@Meenakshi-1802
Copy link
Copy Markdown
Author

Hi @Udayraj123, done! Images are now tiered:

  • = 4 → 1_grayscale_input, 3_threshold, 4_morph_close

  • = 5 → 2_gaussian_blur, 5_canny_edges, edge

  • = 6 → 6a_contour_on_image, 6b_contour_on_edge (only when page is detected)

All intermediate calls use pause=0 to avoid blocking batch runs. Please take a look!

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.

[Learning][Core] Add more step-wise output images for intuitive understanding

2 participants