ComfyUISDXL/Illustrious/Pony/Flux inpaint 追加/削除8番出口型 異変探しR18

AI画像「追加/削除」ComfyUI実装ワークフロー — 8番出口型 異変探しCG集の決定版

対象: R18同人「8番出口型 異変探し×エロ」CG集の制作者(Windows / ComfyUI portable / SDXL・Illustrious・Pony・Flux / ローカルGPU) 狙い: 「1枚のベース画像をマスターとし、その一部だけをAIで追加/削除/置換」して、廊下・タイル・ライト・小物の位置を完全一致させたまま"異変(差分)"を入れる。間違い探しが成立する唯一の作り方。 作成: 2026-06-13 / 検証方針: 一次未確認の数値・ライセンス可否・ノード挙動は本文中に (要確認) と明示。捏造はしない。

0. なぜ「ベース1枚→局所差し替え」が唯一解か(設計思想)

マスター結線図(コピペで組む型)

[Load Image]  ベース画像(正常版・1枚に確定させる)
     │
     ├──────────────► (異変対象を指定してマスク化)
     │                 A: GroundingDinoSAMSegment("sign"/"vase"/"poster"…)
     │                 B: Impact SEGS Detector → MASK to SEGS
     │                 C: MaskEditor 手描き
     │                         │  MASK
     │                         ▼
     │                 [Expand Mask] +4〜8px ─► [Gaussian Blur Mask] σ=1〜3   ← 継ぎ目を溶かす前処理
     │                         │  (グラデMASK)
     ▼                         ▼
[Inpaint Crop] ◄── image+mask  ─────────────────────────────┐   ← マスク周辺だけ切出し・背景温存
     │ cropped_image, cropped_mask                            │
     ▼                                                        │
[InpaintModelConditioning]  (vae, pixels, mask, pos, neg)     │
     │ positive/negative/latent                               │
     ▼                                                        │
[Load Checkpoint] ─► [DifferentialDiffusion] ─► model ─► [KSampler] (denoise 0.6〜0.9)
                                                        │ LATENT
[ControlNet: Tile/Lineart/Depth(元画像から条件抽出)] ─────┘   ← 背景の輪郭・遠近を拘束
     │                                                  ▼
     │                                            [VAE Decode]
     │                                                  │ IMAGE
     └──────────────────────────────────────────► [Inpaint Stitch] ◄── 元画像へ完全合成・マスク外は不変
                                                        │
                                                        ▼
                                              [Color Match (Masked)] ← 色/明度ズレ補正
                                                        ▼
                                              [Save Image]  異変版(完成)

ポイント: KSamplerは「Crop で切り出した小領域」だけを処理する。全画面をVAE encode/decodeしないので、(1)背景が1bitも変わらない (2)高速 (3)継ぎ目はBlur+Color Matchで消える。文字・数字は AIに描かせず、最後にPILで合成するのが文字化け再発を防ぐ定石(要確認だが実務の鉄則)。

1. 結論(3行)+ 異変探しCG集の決定版パイプライン1つ(ノード列を1行で)

1枚のベース画像をマスターとし、Inpaint Crop and Stitchでマスク外を完全凍結しながら差分を入れる方式が最も背景同一性を保てる。Differential DiffusionまたはInpaintModelConditioningを併用すると継ぎ目が安定しやすい。Crop&Stitch経由が最も推奨。

Load Image → GroundingDinoSAMSegmentまたはImpact SEGM Detector → Inpaint Crop → VAEEncodeForInpaint/InpaintModelConditioning → KSampler(DifferentialDiffusion適用可) → VAEDecode → Inpaint Stitch

2. 全体設計図(Load Image→自動マスク→局所inpaint→縫合→継ぎ目消し のブロック図/各ブロックの役割)

Load Image ──► Mask生成(自動/手動) ──► Inpaint Crop
                                            │
                                            ▼
                                    VAEEncode + Conditioning
                                            │
                                            ▼
                                    KSampler(+DifferentialDiffusion)
                                            │
                                            ▼
                                    VAEDecode ──► Inpaint Stitch ──► 完成画像

3. 自動マスク生成の3系統(A:Grounding-DINO+SAM テキスト指定 / B:Impact Pack SEGS検出器 / C:手描き・色選択)

A: GroundingDinoModelLoader → SAMModelLoader → GroundingDinoSAMSegment
入力:IMAGE、テキスト("sign","poster","vase"など)
出力:IMAGE、MASK
threshold(0.0-1.0)で検出感度調整。文字や小物指定に強い。

B: UltralyticsDetectorProviderまたはBBOX Detector(combined) → SAMDetector(combined)またはMASK to SEGS
出力:SEGS → Detailer(SEGS)で局所処理後、SEGSPasteで合成。検出器依存で物体単位のマスク向き。

C: 手描きマスクはLoad Image(マスク用)またはMaskEditor相当(要確認)で作成。色選択はToBinaryMaskで二値化。

4. 局所差し替えの結線(主役)

4-1 SDXL/Illustrious inpaint(InpaintModelConditioning 経由・通常checkpointで継ぎ目を消す結線)

Load Image → InpaintModelConditioning(positive/negative/vae/pixels/mask)
出力latentをKSamplerへ。noise_maskトグルはUIバージョンにより異なる(要確認)。

4-2 Differential Diffusion(Gaussian Blur Mask→ソフト境界・KSampler手前のmodelパッチ位置)

Load Checkpoint → DifferentialDiffusion → KSampler(model入力)
マスクはGaussian BlurでぼかしてからInpaintModelConditioningまたはVAEEncodeForInpaintへ渡す。

4-3 Crop&Stitch でマスク外を完全凍結(KSamplerを挟む結線・背景同一性の担保)

Image+Mask → Inpaint Crop → VAEEncode → KSampler → VAEDecode → Inpaint Stitch
mask_blend_pixelsとcontext_from_mask_extend_factorで継ぎ目を調整(要確認)。

4-4 Fooocus inpaint patch(Acly・VAE Encode & Inpaint Conditioning の2出力結線)

Load Fooocus Inpaint → "VAE Encode & Inpaint Conditioning"
latent_inpaintとlatent_samplesの2系統を出力し、Apply Fooocus InpaintとKSamplerへ分岐。

5. 異変操作別レシピ(A:物を消す=LaMa/MAT "Inpaint (using Model)" / B:物を足す / C:看板の数字を変える / D:服・ポーズを変える)

A: Load Inpaint Model(LaMa/MAT) → "Inpaint (using Model)"(プロンプト不要)
B: Inpaint Crop&Stitch + 追加プロンプトで物体生成
C: GroundingDinoSAMSegment("sign")でマスク → InpaintModelConditioningで数字再生成
D: Differential Diffusion(ぼかしたマスク) + ControlNet(Tile/Depth)で姿勢変更

6. 背景を固定するControlNet結線(Tile/Lineart/Depthで元画像から条件抽出→ControlNet Apply→マスク外逸脱防止)

元画像 → プリプロセッサ(Tile/Lineart/Canny/Depth) → ControlNet Apply
Apply出力をKSamplerに接続。Segment制御も併用可。xinsir controlnet-union-sdxl-1.0使用(Apache 2.0)。

7. ワークフローJSONの組み方(ノードIDとlinks配列の考え方・最小JSONの骨子・API保存のコツ・要点だけ)

ノードIDは0から連番。linksは[出力元ID,出力スロット,入力先ID,入力スロット,型]の配列で記述。
最小骨子はLoad Image(1)→Mask生成(2)→Inpaint Crop(3)→KSampler(4)→Inpaint Stitch(5)のlinksを明記。
API保存時はextra_pnginfoを削除し、node connectionsのみ残すと再利用性が高い。

8. Illustrious/Pony系R18チェックポイント特有の注意点

inpaint専用版が無い場合はFooocusパッチまたはDifferential Diffusionを代替。score_9, score_8_up等のタグはconditioningに追加。NSFW領域の継ぎ目はColor Match (Masked)で補正後、モザイク処理は最終段に配置。

9. 落とし穴TOP10(継ぎ目/色ズレ/ライト不一致/文字化け再発/grow_mask_by過大/VRAM/ライセンス/Flux非商用/ControlNet強すぎ等)


詳細A. 自動マスク生成3系統の完全ノード列

A系 (Grounding-DINO+SAM)

GroundingDinoModelLoader ──► model
SAMModelLoader ──► sam_model
GroundingDinoSAMSegment(image=Load Image, text_prompt="sign|poster|number|vase", threshold=0.3(要確認), sam_model, grounding_dino_model) ──► mask
Expand Mask(mask, expand=4-8px(要確認)) ──► Gaussian Blur Mask(sigma=1-3(要確認))

出力MASKをInpaint Cropへ。テキスト指定の看板・小物変更に最適。

B系 (Impact SEGS)

UltralyticsDetectorProvider(model_name="bbox/handy.pt"(要確認)) ──► BBOX_DETECTOR / SEGM_DETECTOR
BBOX Detector(combined) or SEGM Detector(combined)(image, detector) ──► SEGS
SAMDetector(combined)(SEGS) ──► SEGS
MASK to SEGS(mask) ──► SEGS
SEGS Filter(label="person", size_range) ──► Detailer(SEGS) ──► SEGSPaste

物体検出が安定する人物・大型オブジェクトの置換に最適。

C系 (手描き/色選択)

Load Image ──► MaskEditor(右クリック→Open in MaskEditor(要確認)) ──► mask
ToBinaryMask(mask, threshold=128(要確認)) ──► 二値MASK

精密な服変更・ポーズ調整に最適。自動検出が難しい領域で使用。

詳細B. 局所差し替えの主役4結線

B-1 InpaintModelConditioning経由

Load Checkpoint ──► model
CLIPTextEncode(pos/neg) ──► conditioning
InpaintModelConditioning(vae=VAE, pixels=ベース画像, mask) ──► positive/negative/latent
KSampler(model, positive, negative, latent_image, denoise=0.65-0.80(要確認), cfg=5-7(要確認), sampler_name=euler_a or dpmpp_2m(要確認), steps=20-30) ──► VAEDecode

B-2 Differential Diffusion

Gaussian Blur Mask(kernel_size=ブラシ径, sigma=2-4(要確認)) ──► グラデーションMASK
DifferentialDiffusion(model) ──► model
KSampler(model, denoise=0.75-0.95(要確認))

境界溶けが強く、継ぎ目が最も安定。

B-3 Crop&Stitch完全凍結

Inpaint Crop(mask, mask_blend_pixels=8(要確認), context_from_mask_extend_factor=1.2(要確認), output_resize_to_target_size=512-768(要確認)) ──► cropped_image
VAEEncode ──► KSampler ──► VAEDecode ──► Inpaint Stitch(original=ベース画像)

マスク外画素を一切触らないため背景同一性最高。

B-4 Fooocus patch

Load Fooocus Inpaint ──► Apply Fooocus Inpaint(model)
"VAE Encode & Inpaint Conditioning"(pixels, mask) ──► latent_inpaint
Apply Fooocus Inpaint(latent_inpaint) ──► latent_samples
KSampler(latent_samples, denoise=0.5-1.0)

詳細C. 異変操作別の完全レシピ

A 消す

GroundingDinoSAMSegment("対象") ──► Expand Mask ──► Load Inpaint Model(LaMa big-lama.pt(要確認)) ──► "Inpaint (using Model)"(プロンプト不要) ──► Color Match(Masked)

物体除去に最適。

B 足す

手描きマスク or テキストマスク ──► Inpaint Crop ──► InpaintModelConditioning(pos="赤い消火器", denoise=1.0) ──► KSampler ──► Inpaint Stitch ──► Color Match
ControlNet Depth(ベース画像)併用で床・壁の整合。

C 看板の数字/文字

GroundingDinoSAMSegment("number|sign")で領域限定 ──► Inpaint Crop ──► InpaintModelConditioning(denoise=0.7) ──► KSampler
→ PIL ImageCompositeで数字レイヤー後乗せ(要確認)

AI単独は文字化け再発しやすい。

D 服/ポーズ

Differential Diffusion(model) + ControlNet(OpenPose/Lineart) ──► KSampler(denoise=0.65-0.85)

骨格固定しつつ服のみ変更。

詳細D. 背景固定ControlNet結線

Load Image ──► AIO Aux Preprocessor(preprocessor=Tile/Lineart/Depth) ──► controlnet_image
Load ControlNet(model=xinsir controlnet-union-sdxl-1.0(要確認)) ──► Apply ControlNet(strength=0.45-0.65(要確認), end_percent=0.6(要確認)) ──► KSampler.positive

強すぎると異変が入らず、弱すぎると背景がズレるトレードオフ。

詳細E. ワークフローJSON骨子

{
  "nodes": [
    {"id":1,"type":"LoadImage","widgets_values":["base.png"]},
    {"id":2,"type":"GroundingDinoSAMSegment","inputs":{"image":["1",0],"text_prompt":"sign"}},
    {"id":3,"type":"InpaintModelConditioning"},
    {"id":4,"type":"KSampler"},
    {"id":5,"type":"VAEDecode"},
    {"id":6,"type":"SaveImage"}
  ],
  "links": [[1,1,0,2,0,"IMAGE"],[2,2,1,3,2,"MASK"],...]
}

Save(API Format)でprompt形式に変換すると量産向き(要確認)。

詳細F. Illustrious/Pony系R18特有の注意

詳細G. 落とし穴TOP10

関連DR一覧(D:\市場調査資料\ 既存・本DRの周辺)

脚注 — 全ソースURL(実在のみ)

  1. comfyui-inpaint-nodes (Acly) 公式リポジトリ — Fooocus patch / LaMa・MAT / Expand・Shrink・Stabilize Mask / Fill Masked / Color Match (Masked) / Denoise to Compositing Mask / "Inpaint (using Model)" の全ノード仕様: https://github.com/Acly/comfyui-inpaint-nodes
  2. Acly Fooocus inpaint モデル配置(lllyasviel/fooocus_inpaint): https://huggingface.co/lllyasviel/fooocus_inpaint/tree/main
  3. comfyui_segment_anything (storyicon) — GroundingDinoModelLoader / SAMModelLoader / GroundingDinoSAMSegment、GroundingDINO・SAMモデルファイル: https://github.com/storyicon/comfyui_segment_anything
  4. GroundingDinoSAMSegment ノードI/O(IMAGE/MASK・threshold 0.0-1.0): https://www.runcomfy.com/comfyui-nodes/ComfyUI-SAM2/GroundingDinoSAMSegment--segment-anything-
  5. ComfyUI-Impact-Pack (ltdrdata) — SAMLoader/SAMDetector/BBOX・SEGM Detector/MASK to SEGS/Detailer(SEGS)/SEGSPaste/ToBinaryMask: https://github.com/ltdrdata/ComfyUI-Impact-Pack
  6. ComfyUI-Inpaint-CropAndStitch (lquesada) — Inpaint Crop / Inpaint Stitch・マスク外はVAEを通さず温存: https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch
  7. InpaintModelConditioning ノードI/O(positive/negative/vae/pixels/mask → positive/negative/latent): https://comfyui-wiki.com/en/comfyui-nodes/conditioning/inpaint/inpaint-model-conditioning
  8. VAE Encode (for Inpainting) — pixels/vae/mask/grow_mask_by(既定6): https://comfyui-wiki.com/en/comfyui-nodes/latent/inpaint/vae-encode-for-inpaint
  9. VAE Encode (for Inpainting) ノード解説(runcomfy): https://www.runcomfy.com/comfyui-nodes/ComfyUI/VAEEncodeForInpaint
  10. DifferentialDiffusion 公式ビルトインノード(ComfyUI Docs): https://docs.comfy.org/built-in-nodes/DifferentialDiffusion
  11. Differential Diffusion ノード(runcomfy): https://www.runcomfy.com/comfyui-nodes/ComfyUI/DifferentialDiffusion
  12. Differential Diffusion 解説(グラデマスク=画素ごとdenoise強度・Gaussian Blur Mask前処理): https://promptingpixels.com/soft-inpainting-in-comfyui/
  13. Flux.1 Fill dev 公式チュートリアル(必要ファイル・FLUX.1[dev]非商用ライセンス): https://docs.comfy.org/tutorials/flux/flux-1-fill-dev
  14. Flux Fill ワークフロー(InpaintModelConditioning+DifferentialDiffusion を使用): https://comfyui-wiki.com/en/tutorial/advanced/image/flux/flux-1-dev-fill
  15. alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Beta(Flux系ControlNet inpaint): https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Beta
  16. xinsir controlnet-union-sdxl-1.0 / ProMax(12 control + 5 advanced editing・inpaint/tile・Apache 2.0): https://huggingface.co/xinsir/controlnet-union-sdxl-1.0
  17. Automated Inpainting with Dino(GroundingDINO自動マスク+inpaint 実ワークフロー・Civitai): https://civitai.com/models/269302/tutorial-resources-automated-inpainting-with-dino
  18. SDXL Inpainting 実ワークフロー(VAEEncodeForInpaint+InpaintModelConditioning 結線例・OpenArt): https://openart.ai/workflows/rat_dismal_40/comfyui-sdxl-inpainting/0ErhhSzJ1O7RLIvt7KGT

検証メモ: 上記は2026-06-13時点で実在を確認したURL。ノード名・入出力スロット・grow_mask_by既定6・SDXL inpaint 9ch・Flux非商用・xinsir Apache2.0 は一次/準一次で確認済。denoise/cfg/strength/thresholdの具体数値、MaskEditor手順、Ultralyticsモデルファイル名、PIL後乗せの最適手順は環境差があり「(要確認)」。FLUX.1[dev]のR18商用販売可否はライセンス上の重大リスク=必ず原文と法務で確認すること。

DR_AI画像編集_ComfyUI実装ワークフロー — 生成: grok-4.3 (grok_router.py 経由・コストログ自動記録) + 一次ソース18本で裏取り・編集。
一次未確認の数値/ライセンス可否は本文に (要確認) 明示。FLUX.1[dev] のR18商用可否は重大リスク=必ず原文・法務確認。