diff --git a/README.ko.md b/README.ko.md index f53787a..755f79c 100644 --- a/README.ko.md +++ b/README.ko.md @@ -15,9 +15,9 @@ ```text 블루 러프 패널 crop - -> OT Blue Line Cleanup - -> OT Line AutoClose - -> OT Region Palette Map + -> Blue Sketch Cleaner + -> Line Gap Closer + -> Color Region Finder -> Qwen Image Edit / MangaNinja / reference colorization -> panel reassemble ``` @@ -37,11 +37,18 @@ compositing입니다. 현재 연구에 필요한 것은 UI나 타임라인이 ## 노드 -### OT Blue Line Cleanup +자세한 파라미터 가이드: + +- [노드와 파라미터 가이드](docs/parameter_guide.ko.md) +- [영문 Parameter Guide](docs/parameter_guide.md) + +### Blue Sketch Cleaner 블루 러프 연필선을 분류하고, 검은 선/흰 배경 형태의 정규화된 line image와 overlay preview를 만듭니다. +내부 workflow id: `OTBlueLineCleanup` + 출력: - `clean_line`: 검출된 선을 검정으로 만든 흰 배경 이미지 @@ -49,21 +56,25 @@ preview를 만듭니다. - `transparent_line_preview`: 투명 line 출력을 흰 배경에서 확인하는 preview - `settings_json`: 사용한 파라미터 -### OT Line AutoClose +### Line Gap Closer line skeleton의 endpoint를 찾고, 거리와 방향이 맞는 짧은 gap을 자동으로 닫습니다. +내부 workflow id: `OTLineAutoClose` + 출력: - `closed_line`: gap closure 후 line image - `closure_overlay`: 원래 선은 검정, 새로 닫은 선은 빨강으로 표시 - `segments_json`: 닫은 segment 좌표 -### OT Region Palette Map +### Color Region Finder line art로 분리된 fillable region을 labeling하고 region metadata JSON을 반환합니다. OpenToonz식 indexed color editing으로 가기 위한 첫 단계입니다. +내부 workflow id: `OTRegionPaletteMap` + 출력: - `region_preview`: region label을 색으로 표시한 preview @@ -80,13 +91,7 @@ cd /path/to/ComfyUI/custom_nodes git clone https://github.com/l2dnjsrud/ComfyUI-OpenToonzLineTools.git ``` -현재 이 저장소는 private이므로, GitHub 인증이 없는 머신에서는 먼저 -인증한 뒤 clone합니다. - -```bash -gh auth login -gh repo clone l2dnjsrud/ComfyUI-OpenToonzLineTools /path/to/ComfyUI/custom_nodes/ComfyUI-OpenToonzLineTools -``` +이 저장소는 public이므로 GitHub 인증 없이 clone할 수 있습니다. 이 Mac에서는 개발 중인 폴더를 symlink로 연결해도 됩니다. @@ -126,9 +131,9 @@ examples/opentoonz_line_tools_basic_ui.json ```text LoadImage - -> OT Blue Line Cleanup - -> OT Line AutoClose - -> OT Region Palette Map + -> Blue Sketch Cleaner + -> Line Gap Closer + -> Color Region Finder -> SaveImage debug outputs ``` @@ -146,8 +151,8 @@ examples/opentoonz_line_tools_basic_api.json 고해상도 만화/웹툰 전체 페이지에는 가능하면 패널 검출과 crop 이후에 이 노드들을 사용하세요. -`OT Blue Line Cleanup`은 전체 페이지에서도 line extraction preview 용도로 -쓸 수 있습니다. 하지만 `OT Line AutoClose`와 `OT Region Palette Map`은 +`Blue Sketch Cleaner`는 전체 페이지에서도 line extraction preview 용도로 +쓸 수 있습니다. 하지만 `Line Gap Closer`와 `Color Region Finder`는 패널 crop이나 경계가 제한된 line-art 영역을 기준으로 설계되어 있습니다. 전체 페이지에는 패널 여러 개, 말풍선, 원근선, 컷 경계가 함께 들어 있어 endpoint 수가 너무 많아지거나 region map이 `max_regions` cap에 걸릴 수 diff --git a/README.md b/README.md index dbfe197..b372161 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ The intended upstream/downstream flow is: ```text blue rough panel crop - -> OT Blue Line Cleanup - -> OT Line AutoClose - -> OT Region Palette Map + -> Blue Sketch Cleaner + -> Line Gap Closer + -> Color Region Finder -> Qwen Image Edit / MangaNinja / reference colorization -> panel reassemble ``` @@ -38,11 +38,18 @@ Relevant OpenToonz references: ## Nodes -### OT Blue Line Cleanup +See the full parameter guide: + +- [Node and Parameter Guide](docs/parameter_guide.md) +- [Korean Parameter Guide](docs/parameter_guide.ko.md) + +### Blue Sketch Cleaner Classifies blue rough pencil strokes and emits a normalized black-on-white line image plus an overlay preview. +Internal workflow id: `OTBlueLineCleanup` + Outputs: - `clean_line`: white background with black extracted lines @@ -50,22 +57,26 @@ Outputs: - `transparent_line_preview`: line-only preview on white - `settings_json`: exact parameters used -### OT Line AutoClose +### Line Gap Closer Finds skeleton endpoints and draws short closure segments when endpoint distance and direction are compatible. +Internal workflow id: `OTLineAutoClose` + Outputs: - `closed_line`: line image after gap closure - `closure_overlay`: original black lines plus red closure strokes - `segments_json`: closure segment coordinates -### OT Region Palette Map +### Color Region Finder Labels fillable regions separated by line art and returns a JSON list of region metadata. This is the first step toward OpenToonz-style indexed color editing. +Internal workflow id: `OTRegionPaletteMap` + Outputs: - `region_preview`: colored region-label preview with black line art @@ -82,13 +93,8 @@ cd /path/to/ComfyUI/custom_nodes git clone https://github.com/l2dnjsrud/ComfyUI-OpenToonzLineTools.git ``` -Because this repository is currently private, authenticate first on machines -that do not already have GitHub credentials: - -```bash -gh auth login -gh repo clone l2dnjsrud/ComfyUI-OpenToonzLineTools /path/to/ComfyUI/custom_nodes/ComfyUI-OpenToonzLineTools -``` +The repository is public, so another ComfyUI install can clone it without +GitHub authentication. On this Mac, using the development copy by symlink is fine: @@ -127,9 +133,9 @@ This graph is: ```text LoadImage - -> OT Blue Line Cleanup - -> OT Line AutoClose - -> OT Region Palette Map + -> Blue Sketch Cleaner + -> Line Gap Closer + -> Color Region Finder -> SaveImage debug outputs ``` @@ -147,8 +153,8 @@ examples/opentoonz_line_tools_basic_api.json For high-resolution full manga/manhwa pages, use these nodes after panel detection and cropping whenever possible. -`OT Blue Line Cleanup` can be useful on full pages as a quick line-extraction -preview, but `OT Line AutoClose` and `OT Region Palette Map` are designed for +`Blue Sketch Cleaner` can be useful on full pages as a quick line-extraction +preview, but `Line Gap Closer` and `Color Region Finder` are designed for panel crops or other bounded line-art regions. On full pages with many panels, speech balloons, perspective grids, and layout borders, endpoint counts can become too high and region maps can hit the `max_regions` cap. diff --git a/docs/parameter_guide.ko.md b/docs/parameter_guide.ko.md new file mode 100644 index 0000000..8652727 --- /dev/null +++ b/docs/parameter_guide.ko.md @@ -0,0 +1,112 @@ +# 노드와 파라미터 가이드 + +이 문서는 ComfyUI에 보이는 쉬운 표시 이름 기준입니다. workflow 호환을 위해 +내부 node id는 그대로 유지합니다. + +- `OTBlueLineCleanup` -> `Blue Sketch Cleaner` +- `OTLineAutoClose` -> `Line Gap Closer` +- `OTRegionPaletteMap` -> `Color Region Finder` + +추천 흐름: + +```text +패널 crop + -> Blue Sketch Cleaner + -> Line Gap Closer + -> Color Region Finder + -> 채색 / 색 보정 +``` + +전체 페이지에는 먼저 패널 검출과 crop을 거친 뒤 쓰는 것이 좋습니다. MC/MS +전체 페이지는 gap closing과 region map의 기본 입력으로는 너무 복잡합니다. + +## Blue Sketch Cleaner + +첫 번째로 쓰는 노드입니다. 파란 러프 연필선을 검출해서 흰 배경의 검은 line +art로 바꿉니다. + +출력: + +- `clean_line`: 흰 배경 위 검은 line art. +- `line_overlay`: 원본 위에 검출된 파란 stroke를 빨간색으로 표시. +- `transparent_line_preview`: line-only preview를 흰 배경에서 확인. +- `settings_json`: 설정값과 이미지별 line 통계. + +파라미터: + +| Parameter | Default | 사용법 | +|---|---:|---| +| `hue_low` | 90 | OpenCV HSV 기준 파란색 hue 하한입니다. 범위는 `0-179`. 청록 계열 선이 빠지면 낮춥니다. | +| `hue_high` | 145 | 파란색 hue 상한입니다. 보라빛 파란 선이 빠지면 올립니다. | +| `saturation_min` | 28 | 색의 진함 최소값입니다. 배경 잡음이 잡히면 올리고, 흐린 파란 연필선이 빠지면 낮춥니다. | +| `value_min` | 20 | 밝기 최소값입니다. 어두운 파란 선이 빠지면 낮추고, 그림자/노이즈가 잡히면 올립니다. | +| `include_dark_lines` | false | 검은색/어두운 선도 같이 포함합니다. 파란 선과 검은 선이 섞인 패널에 유용하지만 글자, 컷선, 그림자도 같이 잡힐 수 있습니다. | +| `despeckle_px` | 8 | 이 픽셀 면적보다 작은 점 노이즈를 제거합니다. 먼지 제거는 올리고, 작은 의도된 선이 사라지면 낮춥니다. | +| `close_px` | 1 | 작은 틈을 붙이는 morphology closing 반경입니다. 올리면 미세한 끊김은 줄지만 선이 두꺼워지거나 붙을 수 있습니다. | + +시작값: + +- 파란 러프만 있는 경우: 기본값. +- 파란 선이 너무 흐림: `saturation_min 15-25`, `value_min 10-20`. +- 배경이 너무 많이 잡힘: `saturation_min 45-70`, `despeckle_px 16-64`. +- 파란 선과 검은 선이 섞임: `include_dark_lines true`, overlay를 꼭 확인. + +## Line Gap Closer + +`Blue Sketch Cleaner` 뒤에 쓰는 노드입니다. line art를 skeleton으로 줄이고, +endpoint를 찾은 뒤 방향과 거리가 맞는 짧은 gap을 닫습니다. + +출력: + +- `closed_line`: gap closing 후 line art. +- `closure_overlay`: 원래 선은 검정, 새로 닫은 gap은 빨강. +- `segments_json`: 이미지별 닫은 segment 좌표와 skip 이유. + +파라미터: + +| Parameter | Default | 사용법 | +|---|---:|---| +| `threshold` | 180 | 이 값보다 어두운 픽셀을 선으로 봅니다. 검은 선만 엄격히 잡으려면 낮추고, 회색 선이 빠지면 올립니다. | +| `closing_distance` | 18 | endpoint끼리 연결할 최대 거리입니다. 큰 gap을 닫으려면 올리고, 엉뚱한 선끼리 붙으면 낮춥니다. | +| `spot_angle` | 75 | 방향 허용 각도입니다. 낮추면 엄격해지고, 높이면 더 많은 애매한 gap을 닫습니다. | +| `line_width` | 1 | 새로 그리는 closure stroke 두께입니다. line art에는 보통 `1-2`가 적당합니다. | +| `max_endpoints` | 600 | 안전 제한입니다. endpoint가 너무 많으면 무리하게 닫지 않고 skip합니다. 전체 페이지는 자주 이 제한을 넘습니다. | + +시작값: + +- 패널 crop: 기본값. +- 아주 작은 끊김만 닫기: `closing_distance 8-12`, `spot_angle 45-60`. +- 러프한 큰 gap도 닫기: `closing_distance 20-32`, `spot_angle 75-100`. +- 전체 페이지: 기본적으로 피하세요. 실험용으로만 overlay를 보면서 `max_endpoints`를 올립니다. + +## Color Region Finder + +gap closing 뒤에 쓰는 노드입니다. 검은 line art로 둘러싸인 흰 영역을 찾아 +채색 가능한 region preview를 만듭니다. + +출력: + +- `region_preview`: 검출 region을 색으로 표시하고 line art는 검정으로 표시. +- `regions_json`: 각 region의 bbox, area, centroid, style id. + +파라미터: + +| Parameter | Default | 사용법 | +|---|---:|---| +| `threshold` | 180 | 이 값보다 어두운 픽셀을 region 경계선으로 봅니다. Line Gap Closer와 맞춰 쓰는 것이 좋습니다. | +| `min_area` | 32 | 이 픽셀 면적보다 작은 region을 무시합니다. 노이즈가 많으면 올리고, 눈/장식 같은 작은 영역이 빠지면 낮춥니다. | +| `max_regions` | 128 | 이미지당 반환할 최대 region 수입니다. 복잡한 패널은 올릴 수 있지만, 항상 cap에 걸리면 입력이 너무 큽니다. | +| `ignore_border_regions` | true | 이미지 경계에 닿은 열린 region을 무시합니다. 패널 crop에는 true 권장, 페이지/레이아웃 디버깅에는 false도 가능. | + +시작값: + +- 패널 crop: 기본값. +- 작은 색 조각이 너무 많음: `min_area 128-512`. +- 눈/소품/장식이 빠짐: `min_area 8-24`. +- 전체 페이지 디버그: `max_regions 512+`, 대신 매우 noisy할 수 있습니다. + +## 빠른 판정법 + +- `Blue Sketch Cleaner` overlay가 맞으면 hue/saturation 설정은 대체로 맞습니다. +- `Line Gap Closer`가 `endpoint_count_exceeded`를 내면 더 작게 crop한 뒤 쓰세요. +- `Color Region Finder`가 항상 `max_regions`와 같은 region 수를 내면 이미지가 너무 복잡하거나 열린 선이 많다는 뜻입니다. diff --git a/docs/parameter_guide.md b/docs/parameter_guide.md new file mode 100644 index 0000000..1561957 --- /dev/null +++ b/docs/parameter_guide.md @@ -0,0 +1,112 @@ +# Node and Parameter Guide + +This guide uses the friendly ComfyUI display names. The internal node IDs stay +unchanged for workflow compatibility: + +- `OTBlueLineCleanup` -> `Blue Sketch Cleaner` +- `OTLineAutoClose` -> `Line Gap Closer` +- `OTRegionPaletteMap` -> `Color Region Finder` + +Recommended pipeline: + +```text +panel crop + -> Blue Sketch Cleaner + -> Line Gap Closer + -> Color Region Finder + -> colorization / correction +``` + +For full pages, run panel detection and cropping first. Full MC/MS pages are too +complex for gap closing and region mapping as a default. + +## Blue Sketch Cleaner + +Use this first. It detects blue rough pencil strokes and turns them into black +line art on a white background. + +Outputs: + +- `clean_line`: black line art on white background. +- `line_overlay`: original image with detected blue strokes marked red. +- `transparent_line_preview`: line-only preview on white. +- `settings_json`: parameters plus per-image line statistics. + +Parameters: + +| Parameter | Default | How to use it | +|---|---:|---| +| `hue_low` | 90 | Lower bound of blue hue in OpenCV HSV, range `0-179`. Lower it if cyan strokes are missed. | +| `hue_high` | 145 | Upper bound of blue hue. Raise it if purple-blue strokes are missed. | +| `saturation_min` | 28 | Minimum color saturation. Raise it to ignore pale paper/background noise. Lower it for very faint blue pencil. | +| `value_min` | 20 | Minimum brightness. Lower it if dark blue strokes disappear. Raise it if shadows/noise are selected. | +| `include_dark_lines` | false | Also include black/dark line art. Useful for mixed blue+black panels, but can catch text, borders, and shadows. | +| `despeckle_px` | 8 | Removes tiny connected specks below this pixel area. Raise it to remove dust; lower it if small intentional marks vanish. | +| `close_px` | 1 | Small morphological closing radius. Raise it to connect tiny cracks; too high will thicken or merge lines. | + +Starting recipes: + +- Blue rough only: defaults. +- Very faint blue: `saturation_min 15-25`, `value_min 10-20`. +- Too much background detected: `saturation_min 45-70`, `despeckle_px 16-64`. +- Mixed blue and black line art: `include_dark_lines true`, then check the overlay carefully. + +## Line Gap Closer + +Use this after `Blue Sketch Cleaner`. It skeletonizes line art, finds endpoints, +and draws short closure strokes between compatible endpoints. + +Outputs: + +- `closed_line`: line art after attempted gap closing. +- `closure_overlay`: original lines in black and newly closed gaps in red. +- `segments_json`: per-image closed segment coordinates and skip reason. + +Parameters: + +| Parameter | Default | How to use it | +|---|---:|---| +| `threshold` | 180 | Pixels darker than this are treated as line. Lower it for strict black-only lines; raise it if gray lines are missed. | +| `closing_distance` | 18 | Maximum pixel distance between endpoints. Raise for bigger gaps; lower if unrelated lines get connected. | +| `spot_angle` | 75 | Direction tolerance in degrees. Lower values are stricter; higher values close more ambiguous gaps. | +| `line_width` | 1 | Width of newly drawn closure strokes. Use `1-2` for line art; higher values can muddy sketches. | +| `max_endpoints` | 600 | Safety cap. If exceeded, the node skips instead of making chaotic closures. Full pages often exceed this. | + +Starting recipes: + +- Panel crop: defaults. +- Tiny broken strokes only: `closing_distance 8-12`, `spot_angle 45-60`. +- Larger sketch gaps: `closing_distance 20-32`, `spot_angle 75-100`. +- Full pages: avoid, or raise `max_endpoints` only for experiments after checking overlays. + +## Color Region Finder + +Use this after gap closing. It finds connected white regions separated by black +line art and makes a colored preview of fillable areas. + +Outputs: + +- `region_preview`: colored labels for detected regions, with line art in black. +- `regions_json`: bbox, area, centroid, and style id per detected region. + +Parameters: + +| Parameter | Default | How to use it | +|---|---:|---| +| `threshold` | 180 | Pixels darker than this are treated as line boundaries. Match this with Line Gap Closer. | +| `min_area` | 32 | Ignore fill regions smaller than this pixel area. Raise it to reduce noise; lower it to keep small details. | +| `max_regions` | 128 | Maximum regions returned per image. Raise for dense panels; if every image hits the cap, the input is too broad. | +| `ignore_border_regions` | true | Ignore open regions touching image borders. Keep true for panel crops; false can be useful for page/layout debugging. | + +Starting recipes: + +- Panel crop: defaults. +- Too many tiny colored fragments: `min_area 128-512`. +- Missing small eyes/details/accessories: `min_area 8-24`. +- Full page debug only: `max_regions 512+`, but expect noisy maps. + +## Quick Interpretation + +- If `Blue Sketch Cleaner` overlay looks right, the hue/saturation settings are good. +- If `Line Gap Closer` returns `endpoint_count_exceeded`, crop smaller before using it. +- If `Color Region Finder` always returns exactly `max_regions`, the image is too complex or too open. diff --git a/opentoonz_line_tools/nodes.py b/opentoonz_line_tools/nodes.py index 801cdd6..070e161 100644 --- a/opentoonz_line_tools/nodes.py +++ b/opentoonz_line_tools/nodes.py @@ -68,6 +68,7 @@ class OTBlueLineCleanup: RETURN_NAMES = ("clean_line", "line_overlay", "transparent_line_preview", "settings_json") FUNCTION = "cleanup" CATEGORY = "manga/opentoonz-line-tools" + DESCRIPTION = "Extract blue rough sketch strokes and convert them into clean black line art for later inking, gap closing, or colorization." def cleanup( self, @@ -127,6 +128,7 @@ class OTLineAutoClose: RETURN_NAMES = ("closed_line", "closure_overlay", "segments_json") FUNCTION = "autoclose" CATEGORY = "manga/opentoonz-line-tools" + DESCRIPTION = "Find nearby line endpoints and close small gaps before region filling. Best used on panel crops, not full pages." def autoclose( self, @@ -183,6 +185,7 @@ class OTRegionPaletteMap: RETURN_NAMES = ("region_preview", "regions_json") FUNCTION = "regions" CATEGORY = "manga/opentoonz-line-tools" + DESCRIPTION = "Detect fillable color regions enclosed by line art and return a colored preview plus region metadata JSON." def regions(self, image, threshold: int, min_area: int, max_regions: int, ignore_border_regions: bool): settings = RegionSettings(min_area=min_area, max_regions=max_regions, ignore_border_regions=ignore_border_regions) @@ -210,7 +213,7 @@ NODE_CLASS_MAPPINGS = { } NODE_DISPLAY_NAME_MAPPINGS = { - "OTBlueLineCleanup": "OT Blue Line Cleanup", - "OTLineAutoClose": "OT Line AutoClose", - "OTRegionPaletteMap": "OT Region Palette Map", + "OTBlueLineCleanup": "Blue Sketch Cleaner", + "OTLineAutoClose": "Line Gap Closer", + "OTRegionPaletteMap": "Color Region Finder", }