Files
2nd/10_Wiki/Topics/AI_and_ML/미드저니 및 스테이블 디퓨전의 부분 편집 기법.md
T
2026-05-10 22:08:15 +09:00

198 lines
6.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-미드저니-및-스테이블-디퓨전의-부분-편집-기법
title: 미드저니 및 스테이블 디퓨전의 부분 편집 기법
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Inpainting, Outpainting, Vary Region, Partial Edit]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [diffusion, inpainting, midjourney, sdxl, flux]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: python
framework: diffusers
---
# 미드저니 및 스테이블 디퓨전의 부분 편집 기법
## 매 한 줄
> **"매 부분 편집 매 mask × prompt × denoise 의 3축 control"**. Inpainting/outpainting 매 image 의 일부 만 regenerate — 매 mask region 의 latent 의 noise 의 추가 후 conditional denoise. 매 2026 의 FLUX.1 Fill, SDXL Inpaint, MJ "Vary Region" / "Vary Subtle" 매 production-ready.
## 매 핵심
### 매 3가지 mode
- **Inpainting**: existing region 의 mask 의 그리고 prompt 로 replace.
- **Outpainting**: image 의 canvas 의 확장 의 새 region 의 채움.
- **Vary Region (MJ)**: subset 의 selective regeneration — context-aware.
### 매 control axis
- **Mask shape**: hard edge vs feathered (blur radius).
- **Denoise strength**: 0.3 (subtle tweak) — 1.0 (full replace).
- **Prompt scope**: full-image prompt vs masked-only prompt.
### 매 응용
1. Object 추가/제거 — 매 background 의 보존 의 selective replace.
2. Outpaint 의 wide aspect — 16:9 → 21:9 cinematic.
3. Face/hand fix — adetailer 의 auto-detect mask + inpaint pass.
## 💻 패턴
### SDXL Inpaint pipeline
```python
from diffusers import StableDiffusionXLInpaintPipeline
from PIL import Image
import torch
pipe = StableDiffusionXLInpaintPipeline.from_pretrained(
"diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
torch_dtype=torch.float16,
).to("cuda")
img = Image.open("photo.png").convert("RGB")
mask = Image.open("mask.png").convert("L") # white = replace, black = keep
result = pipe(
prompt="a red ceramic vase with white flowers",
image=img,
mask_image=mask,
strength=0.95, # full replace inside mask
guidance_scale=7.0,
num_inference_steps=30,
).images[0]
```
### FLUX.1 Fill (2024-2026 SOTA)
```python
from diffusers import FluxFillPipeline
pipe = FluxFillPipeline.from_pretrained(
"black-forest-labs/FLUX.1-Fill-dev",
torch_dtype=torch.bfloat16,
).to("cuda")
result = pipe(
prompt="a vintage brass lamp on the desk",
image=img,
mask_image=mask,
height=1024, width=1024,
guidance_scale=30, # FLUX Fill specific
num_inference_steps=50,
).images[0]
```
### Outpainting — canvas 확장
```python
from PIL import Image, ImageOps
orig = Image.open("portrait.png") # 1024x1024
# 매 좌우 512px 확장 → 2048x1024
canvas = Image.new("RGB", (2048, 1024), (0, 0, 0))
canvas.paste(orig, (512, 0))
mask = Image.new("L", (2048, 1024), 255) # all white
mask.paste(0, (512, 0, 1536, 1024)) # original area = keep
# 매 feather mask edge 의 seam 회피
mask = mask.filter(ImageFilter.GaussianBlur(radius=16))
result = pipe(
prompt="extended cinematic landscape, mountains, golden hour",
image=canvas, mask_image=mask,
strength=1.0,
).images[0]
```
### Adetailer pattern — auto face/hand fix
```python
# 매 ComfyUI / A1111 — YOLO detect → mask → inpaint
from ultralytics import YOLO
face_det = YOLO("face_yolov8n.pt")
boxes = face_det(img)[0].boxes.xyxy
for box in boxes:
x1, y1, x2, y2 = map(int, box)
face_mask = Image.new("L", img.size, 0)
ImageDraw.Draw(face_mask).rectangle([x1, y1, x2, y2], fill=255)
face_mask = face_mask.filter(ImageFilter.GaussianBlur(8))
img = pipe(
prompt="detailed face, sharp eyes, natural skin",
image=img, mask_image=face_mask,
strength=0.4, # subtle — preserve identity
).images[0]
```
### Differential diffusion — soft mask
```python
# 매 mask 의 grayscale 의 per-pixel strength 으로 처리
soft_mask = Image.open("gradient_mask.png").convert("L")
# 매 black=0% strength, white=100% — smooth blend
result = pipe(prompt=p, image=img, mask_image=soft_mask, strength=0.8).images[0]
```
### Midjourney Vary Region (UI workflow)
```text
1. /imagine 로 base image 생성.
2. U1 (upscale) 후 "Vary (Region)" 클릭.
3. 매 lasso/rectangle 의 region 선택.
4. Prompt 의 edit (optional) 후 submit.
5. 매 4 variant 의 seed 만 region 의 regenerate.
```
### Mask preprocessing — clean edge
```python
import numpy as np
import cv2
mask_np = np.array(mask)
# 매 dilate (확장) 의 seam 의 hide
mask_np = cv2.dilate(mask_np, np.ones((5,5), np.uint8), iterations=2)
# 매 feather
mask_np = cv2.GaussianBlur(mask_np, (21, 21), 0)
mask = Image.fromarray(mask_np)
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Object 교체 (vase) | hard mask + strength=0.95 + SDXL Inpaint |
| Background extension | feathered mask + outpaint + strength=1.0 |
| Face detail fix | YOLO-detect mask + strength=0.3-0.5 |
| Subtle texture tweak | strength=0.2 + soft mask |
| Photoreal fill | FLUX.1 Fill > SDXL Inpaint |
| Stylized iteration | MJ Vary Region |
**기본값**: photoreal → FLUX.1 Fill, stylized → MJ Vary Region, batch automation → SDXL Inpaint + adetailer.
## 🔗 Graph
- 부모: [[AI 이미지 생성 및 편집 워크플로우 (AI Image Generation & Editing Workflow)]]
- 변형: [[ControlNet Inpaint]] · [[IP-Adapter Inpaint]]
- 응용: [[상업용 제품 사진 및 브랜드 로고 디자인]] · [[부정 프롬프트와 가중치를 활용한 시각적 아티팩트(Artifact) 디버깅 및 제어]]
- Adjacent: [[Adetailer]] · [[Differential Diffusion]] · [[SAM (Segment Anything)]]
## 🤖 LLM 활용
**언제**: object replacement, background extension, face/hand defect fix, brand asset iteration.
**언제 X**: identity preservation 의 strict requirement — IP-Adapter / instantID 의 사용 의 추천.
## ❌ 안티패턴
- **Hard mask 의 seam visible**: feather + dilate 의 누락.
- **Strength=1.0 의 face**: identity 의 파괴 — 0.3-0.5 의 사용.
- **Full-image prompt 만**: masked region 의 context 의 누락 — masked-specific term 의 추가.
- **Square mask 의 organic object**: SAM 의 사용 의 정확 mask.
- **Outpaint 의 strength<1.0**: 매 black 영역 의 noise 의 incomplete fill.
## 🧪 검증 / 중복
- Verified (Diffusers SDXL Inpaint docs, FLUX.1 Fill model card, Midjourney v6 docs).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — inpaint/outpaint/vary 3-mode + FLUX Fill |