--- id: wiki-2026-0508-ai-이미지-품질-최적화-및-디버깅-image-qualit title: AI Image Quality Optimization & Debugging category: 10_Wiki/Topics status: verified canonical_id: self aliases: [Image Quality Optimization, Debugging, defect fixing, negative prompt strategy] duplicate_of: none source_trust_level: B confidence_score: 0.85 verification_status: conceptual tags: [image-generation, quality, debugging, negative-prompt, inpainting, upscale, defect-detection] raw_sources: [] last_reinforced: 2026-05-09 github_commit: pending inferred_by: 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) ```python 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) ```python 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) ```python 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) ```python 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 ```python 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) ```python 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) ```python 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 - 부모: [[AI Image Generation]] - 변형: [[Negative Prompt]] · [[Inpainting]] - 응용: [[ControlNet]] - Adjacent: [[AI 모델 사후 편집 도구 (Post-editing Tools)|Post-editing-Tools]] ## 🤖 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. ## 🧪 검증 / 중복 - Verified. - 신뢰도 B. - Overlap with [[AI 모델 사후 편집 도구 (Post-editing Tools)|Post-editing-Tools]] / [[AI Image Generation]]. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-09 | Manual cleanup — defect catalog + negative strategy + ControlNet + code |