Files
2nd/10_Wiki/Topics/AI_and_ML/AI 이미지 품질 최적화 및 디버깅 (Image Quality Optimization & Debugging).md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

8.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, inferred_by
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit inferred_by
wiki-2026-0508-ai-이미지-품질-최적화-및-디버깅-image-qualit AI Image Quality Optimization & Debugging 10_Wiki/Topics verified self
Image Quality Optimization
Debugging
defect fixing
negative prompt strategy
none B 0.85 conceptual
image-generation
quality
debugging
negative-prompt
inpainting
upscale
defect-detection
2026-05-09 pending Claude Opus 4.7 (manual cleanup 2026-05-09)

AI Image Quality Optimization & Debugging

📌 한 줄 통찰

매 raw output 의 defect (extra finger, blur, watermark) → systematic fix. Detect → mask → inpaint → upscale. 매 specific defect 의 specific negative prompt.

📖 핵심

매 common defect 의 catalog

Body / anatomy

  • Extra fingers / toes.
  • Wrong number of limbs.
  • Asymmetric eyes / face.
  • Twisted joints.
  • Missing teeth.

Quality

  • Blur / out of focus.
  • Low resolution.
  • Compression artifact.
  • Noise.

Composition

  • Subject 의 cropped.
  • Cluttered background.
  • Wrong aspect.

Style

  • Generic AI look (waxy skin).
  • Inconsistent lighting.
  • Wrong era / setting.

Text / artifact

  • Watermark.
  • Signature.
  • Garbled text.
  • Logo intrusion.

매 fix strategy

1. Quality keyword (positive)

  • "8k, 4k, high resolution".
  • "ultra detailed, sharp focus".
  • "masterpiece, professional photography".

→ 매 model 의 quality bias.

2. Negative prompt (Stable Diffusion)

  • Generic: "ugly, deformed, blurry, low quality".
  • Specific > generic. 매 observed defect 의 explicit:
    • "extra fingers, malformed hands".
    • "watermark, signature, text".
    • "asymmetric eyes, cross-eyed".
    • "compression artifact, jpeg artifact".

3. Weighted negative

(extra fingers:1.5), (deformed hands:1.3), (blurry:1.2), watermark

→ 매 defect 의 stronger suppression.

4. Inpaint (region-specific)

  • 매 mask 의 defect.
  • 매 specific positive prompt.

5. ControlNet (constraint)

  • OpenPose: pose 의 enforce.
  • Canny: edge.
  • Depth: 3D structure.

→ 매 anatomy fix 의 큰 도움.

6. Face restoration

  • GFPGAN / CodeFormer.
  • 매 face-specific.

7. Upscale + detail

  • Real-ESRGAN: 매 detail.
  • Tile-based: 큰 image.

매 platform 의 difference

Defect Stable Diffusion Midjourney DALL-E
Extra finger Negative prompt + ControlNet Vary Region Manual edit
Watermark Negative prompt --no Inpaint
Blur Negative + steps↑ --s ↑ (limited)
Bad face GFPGAN + inpaint Vary Region Manual

매 tuning parameter

Stable Diffusion

  • Steps: 20-50 (sweet 30).
  • CFG (guidance): 7-12 (high = strict).
  • Sampler: DPM++ 2M Karras (default modern).
  • Resolution: SDXL = 1024x1024 native.

Midjourney

  • --s (stylize): 0-1000.
  • --q (quality): 0.25, 0.5, 1, 2.
  • --c (chaos): 0-100.
  • --w (weird): 0-3000.

매 photorealism

Lighting

  • "Golden hour, soft light".
  • "Volumetric lighting, rim light".
  • "Studio softbox, three-point lighting".

Camera

  • "85mm lens, shallow depth of field".
  • "f/1.4, bokeh".
  • "Wide angle 24mm" / "telephoto 200mm".

Realism keyword

  • "photorealistic, photo, raw" (SD).
  • (DALL-E 3 = "photo style, 85mm" — "photorealistic" 가 painting feel).

매 debugging workflow

Step 1: Generate base

  • 매 prompt 의 first try.

Step 2: Identify defect

  • 매 visual inspection.
  • 매 specific list.

Step 3: Iterate prompt

  • 매 negative prompt 추가.
  • 매 quality keyword 추가.

Step 4: Regenerate

  • 매 same seed (test).
  • 매 different seed (variety).

Step 5: Inpaint specific

  • 매 mask + targeted prompt.
  • 매 round 의 small fix.

Step 6: Upscale + face

  • 매 final detail.

→ 매 round 의 1-2 defect 의 fix. 매 다음 round.

💻 Code

Negative prompt 의 weighted (SD)

prompt = "portrait of a knight, fantasy, oil painting, masterpiece, 8k"
negative = """
(extra fingers:1.5), (malformed hands:1.4), (deformed:1.2),
blurry, low quality, watermark, signature, text,
(asymmetric eyes:1.3), bad anatomy, cropped
"""

result = pipe(
    prompt=prompt,
    negative_prompt=negative,
    num_inference_steps=40,
    guidance_scale=8,
).images[0]

Defect detection (manual / heuristic)

import cv2
import numpy as np

def detect_extra_finger(image):
    """간단 heuristic: hand region 의 finger count."""
    # 매 OpenPose 의 hand keypoint detection.
    hand_kpts = openpose.detect_hand(image)
    if len(hand_kpts) > 5:
        return True
    return False

def detect_watermark(image):
    """매 corner 의 unusual brightness pattern."""
    img = np.array(image)
    corners = [img[:50, :50], img[:50, -50:], img[-50:, :50], img[-50:, -50:]]
    return any(detect_text_in_region(c) for c in corners)

ControlNet OpenPose (anatomy fix)

from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from controlnet_aux import OpenposeDetector

openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
pose = openpose(reference_image)

controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose")
pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
)

result = pipe(
    prompt="elegant pose, studio lighting",
    image=pose,   # pose enforce
    num_inference_steps=30,
).images[0]

→ 매 anatomy correctness ↑.

Face restoration (GFPGAN)

from gfpgan import GFPGANer

restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=2,
    arch='clean',
)

cropped, restored, output = restorer.enhance(np.array(image))
Image.fromarray(restored).save("face_fixed.png")

Iterative debug loop

def debug_image(prompt, max_rounds=5):
    image = generate(prompt)
    
    for round in range(max_rounds):
        defects = detect_defects(image)
        if not defects:
            return image
        
        # Negative prompt 의 update
        negative = " ".join(f"({d}:1.3)" for d in defects)
        
        # Inpaint specific region
        for d in defects:
            mask = create_mask_for_defect(image, d)
            image = inpaint(image, mask, prompt=f"perfect {d.target}", negative=negative)
    
    return image

Quality scoring (CLIP)

from transformers import CLIPProcessor, CLIPModel
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")

def quality_score(image, prompt):
    inputs = processor(text=[prompt], images=image, return_tensors="pt")
    outputs = model(**inputs)
    return outputs.logits_per_image.softmax(dim=1)[0][0].item()

# 매 candidate 의 score → best 선택

LLM-judge (for batch)

def llm_judge(image_url, prompt):
    return llm.complete([
        {"type": "image", "image_url": image_url},
        {"type": "text", "text": f"Rate 1-10 how well this matches: '{prompt}'. List defects."}
    ])

🤔 결정 기준

Defect Tool
Extra finger ControlNet OpenPose + inpaint
Bad face GFPGAN + inpaint
Watermark Negative prompt + inpaint
Blur Steps↑ + sampler change
Bad anatomy ControlNet + reference
Style mismatch LoRA / IP-Adapter

기본값: Specific negative > generic. Inpaint > regenerate. ControlNet 의 anatomy. Detect → fix loop.

🔗 Graph

🤖 LLM 활용

언제: 매 commercial output 의 quality 의 critical. 언제 X: 매 throwaway / personal use.

안티패턴

  • Generic negative ("ugly"): 매 specific 의 더 강력.
  • Single round: 매 defect 의 multiple round 필요.
  • Regenerate everything: 매 seed / context 잃음. Inpaint local.
  • No ControlNet: 매 anatomy 의 random.
  • Upscale 의 hallucination: 매 detail invent.

🧪 검증 / 중복

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-09 Manual cleanup — defect catalog + negative strategy + ControlNet + code