Nodes/comfyui-panels/Detect Panels In Image
ComfyUI Node

Detect Panels In Image

Turn a drawing of a page into real panel polygons

By bmad4ever·Created 12 months ago·Updated 2 months ago· 41
Detect Panels In Image
  • image
  • POLYGON
threshold240
min_rel_area0.025
simplifynone
max_vertices6
recover_non_convextrue

Sometimes you don't want to build a panel layout from rules - you want to trace one from an image you already drew. Maybe you sketched a rough page, or you found a clean manga page whose panel structure you want to copy, or you painted a mask in an editor and want it as geometry. Detect Panels In Image is the node that does that tracing: it finds the panel-shaped blobs in an image and returns them as shapely polygons.

The author is honest about what it's good at: it's a "simple" CV algorithm that performs best on blank images where the background is white and panels are black shapes. Clean, explicit comic or manga pages work too. A busy, shaded, screentone-filled page will not - the threshold just doesn't survive real artwork. So think of this as a sketch-to-layout tool, not an automatic page-ripper.

How it works

The pipeline lives in the pack's MangaPanelExtractor: the image is thresholded to a binary mask, contours are found, and contours smaller than a minimum relative area are discarded. Each remaining contour becomes a panel polygon. Because real contours are never clean rectangles, the node runs a vertex-simplification pass (max_vertices caps the allowed complexity) and can optionally recover non-convex shapes - which the pack treats as a distinct, more advanced recovery path.

The simplify dropdown then does a final pass: none keeps the detected shape, bounding_box turns each panel into its axis-aligned bounding rectangle, and max_area_combination merges overlapping shapes toward a largest-area interpretation. For a clean page you'll usually leave it on none; for noisy input, bounding_box is the escape hatch.

The inputs that matter

  • image - your page. White background, black panels, as per the description.
  • threshold - default 240. The binary threshold for separating panels from background. Lower it if your "white" isn't clean white.
  • min_rel_area - default 0.025 (2.5% of image area). Contours smaller than this get discarded - raise it to filter out specks.
  • simplify - none / bounding_box / max_area_combination.
  • max_vertices and recover_non_convex - fine-tuning; the tooltips say to use defaults for most cases, and they may change in future versions.

Output is a list of POLYGONs, ready for anything in the pack.

Installing it

Part of comfyui-panels - Manager, search "comfyui-panels", or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels

Restart, install deps (shapely, matplotlib, opencv-python - opencv does the heavy CV lifting here). No models, no downloads.

Where people get burned

Feeding it real, shaded artwork and expecting magic is the classic disappointment - this is a contour detector, not a segmentation model. Clean input, clean output. If your detected panels look overly jagged, raise min_rel_area and switch simplify to bounding_box; if panels merge when they shouldn't, check that the gutters between them are actually white above your threshold. The pack's example workflows "Custom Panel Layout from Mask like Image" and the "Manga Panel Extraction" examples show the input style it wants - worth loading before you fight it.

CategoryBmad/Panels

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
thresholdINT2401–254binary threshold when analysing the image
min_rel_areaFLOAT0.0250.001–0.999contours with an area percentage with respect to the image size inferior to this value are discarded
simplifyCOMBOnoneSimplify the final polygons according to the provided criteria.
max_verticesINT63–9Simplify contour shapes with higher vertex count when analysing the contours. For most use cases use the default value.
recover_non_convexBOOLEANtrueIf set to False, discards non convex shapes when detecting the contours. For most use cases use the default value.

Outputs (1)

NameTypeDescription
POLYGONPOLYGONPanels (Shapely Polygons)