Z-Image Face Detailer Portrait Enhancement and Face Refinement Workflow

5월 27, 2026

Z-Image Face Detailer Portrait Enhancement and Face Refinement Workflow

Keywords: z-image face detailer portrait enhancement


Table of Contents


Introduction

Face Detailer is a specialized workflow for automatic face detection and enhancement in images. Unlike ZI-037 (general upscaler + detailer), this article focuses specifically on facial feature optimization, including face detection, face mask generation, face resolution enhancement, and facial artifact repair.

Diffusion models frequently face the following challenges when generating faces:

  • Facial asymmetry or distortion
  • Inconsistent eyes (direction, size)
  • Deformed teeth
  • Rough or blurry facial textures
  • Individual face quality issues in group scenes

The Face Detailer workflow addresses these common problems through automated detection and repair.

Face Detection and Masking Techniques

Face Detectors

Currently mainstream face detectors include:

Detector Pros Cons
MediaPipe Face Detection Fast, lightweight Medium accuracy, general occlusion handling
RetinaFace High accuracy, supports multiple poses Slower speed
YOLO-Face Fast, suitable for real-time detection Lower accuracy for small faces
BlazeFace Extremely fast, mobile-friendly Lowest accuracy
Face Detection v2 (ComfyUI) Optimized for ComfyUI Requires additional installation

Face Detection Implementation

import cv2
import mediapipe as mp

# MediaPipe face detection
mp_face_detection = mp.solutions.face_detection.FaceDetection(
    model_selection=0,  # 0 = short range, 1 = full range
    min_detection_confidence=0.5
)

def detect_faces(image_path):
    image = cv2.imread(image_path)
    rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    results = mp_face_detection.process(rgb_image)

    faces = []
    if results.detections:
        for detection in results.detections:
            bbox = detection.location_data.relative_bounding_box
            h, w = image.shape[:2]
            x = int(bbox.xmin * w)
            y = int(bbox.ymin * h)
            width = int(bbox.width * w)
            height = int(bbox.height * h)
            faces.append({"x": x, "y": y, "width": width, "height": height})

    return faces

# Usage
faces = detect_faces("group_photo.jpg")
for i, face in enumerate(faces):
    print(f"Face {i+1}: ({face['x']}, {face['y']}), {face['width']}x{face['height']}")

Face Mask Generation

Two main methods for generating face masks:

Method 1: Rectangular Mask (Simple and Fast)

import numpy as np
from PIL import Image

def create_rect_mask(face_bbox, image_size, padding=50):
    """Create rectangular face mask with padding"""
    mask = np.zeros(image_size, dtype=np.uint8)
    x = max(0, face_bbox["x"] - padding)
    y = max(0, face_bbox["y"] - padding)
    w = min(image_size[0] - x, face_bbox["width"] + 2 * padding)
    h = min(image_size[1] - y, face_bbox["height"] + 2 * padding)

    # Add feathering effect
    cv2.rectangle(mask, (x, y), (x + w, y + h), 255, -1)
    mask = cv2.GaussianBlur(mask, (21, 21), 11)

    return Image.fromarray(mask)

Method 2: Semantic Segmentation Mask (More Precise)

from transformers import pipeline

# Use semantic segmentation model for precise face mask
segmentor = pipeline("image-segmentation", model="facebook/detr-resnet-50-panoptic")

def create_semantic_mask(image, face_bbox):
    """Create precise face mask using semantic segmentation"""
    results = segmentor(image)
    mask = np.zeros(image.size[::-1], dtype=np.uint8)

    for result in results:
        if result["label"] in ["person", "face"]:
            segmentation = np.array(result["mask"])
            mask[segmentation > 0.5] = 255

    # Crop to face area
    mask = mask[
        face_bbox["y"]:face_bbox["y"] + face_bbox["height"],
        face_bbox["x"]:face_bbox["x"] + face_bbox["width"]
    ]

    return Image.fromarray(mask)

Face Detailer v2.0 Workflow Overview

Face Detailer v2.0 is the face refinement workflow in the ComfyUI ecosystem, with the following core process:

Original Image → Face Detection → Crop Face Area → Upscale → Model Redraw → Scale Back → Composite into Original

Core Components

  1. Face Detector: Locates all faces in the image
  2. Area Cropper: Crops rectangular areas containing faces (with padding)
  3. Upscale Module: Scales cropped areas to target resolution
  4. Diffusion Model Redraw: Uses Z-Image to redraw upscled faces
  5. Scale and Blend: Scales redrawn results back to original size and blends into original image

Difference from ZI-037

Feature ZI-037 (General Upscaler + Detailer) ZI-060 (Face Detailer)
Processing Target Entire image Face areas only
Detection Module None (processes full image) Face detection + mask generation
Redraw Scope Full image Face areas only
Use Case Overall resolution enhancement Face quality repair
Output Upscaled full image Original size with enhanced faces

Face Restoration vs Face Enhancement

Face Restoration

Goal: Repair damaged or deformed facial features

Use Cases:

  • Severely deformed faces (multiple eyes, twisted faces)
  • Hand or face anatomical errors
  • Completely messed up facial textures

Methods:

  • Use specialized restoration models (GFP-GAN, CodeFormer, RestoreFormer)
  • Or use diffusion models with high strength redraw (strength 0.7-0.9)
  • Prompts emphasize correct facial structure

Prompt Examples:

Restoration: "fix face, correct facial features, realistic face, proper anatomy"

Face Enhancement

Goal: Improve quality while maintaining original facial features

Use Cases:

  • Face is basically correct but not clear enough
  • Need to enhance details (skin texture, eye details)
  • Improve face resolution

Methods:

  • Low strength redraw (strength 0.3-0.6)
  • Use super-resolution models
  • Hybrid method combining restoration and enhancement

Prompt Examples:

Enhancement: "enhance face detail, sharp eyes, natural skin texture, high quality portrait"

Selection Guide

Face Issue Recommended Method Strength
Severe deformation Face Restoration 0.7-0.9
Slight asymmetry Face Restoration 0.5-0.7
Blurry/low resolution Face Enhancement 0.3-0.5
Need detail improvement Face Enhancement 0.3-0.6
Overall quality improvement Hybrid Method 0.5-0.7

ComfyUI Face Detailer Nodes and Configuration

Install Required Components

# Install in ComfyUI/custom_nodes/ directory
cd ComfyUI/custom_nodes

# Face Detailer nodes
git clone https://github.com/LucianTan/ComfyUI-FaceDetailer.git

# Or Ultimate SD Upscale + Face Detailer
git clone https://github.com/AIGODLIKE/AI-GODLIKE-ComfyUI-Workflow.git

# Install dependencies
pip install -r ComfyUI-FaceDetailer/requirements.txt

Basic Face Detailer Workflow

{
  "1": {
    "class_type": "LoadImage",
    "inputs": {
      "image": "generated_image.jpg"
    }
  },
  "2": {
    "class_type": "FaceDetailer",
    "inputs": {
      "image": ["1", 0],
      "model": ["model", 0],
      "clip": ["clip", 0],
      "vae": ["vae", 0],
      "detector": "retinaface",
      "face_size": 512,
      "upscale_model": "4x-UltraSharp",
      "upscale_by": 2.0,
      "denoise": 0.5,
      "cfg": 7.5,
      "steps": 28,
      "seed": 42
    }
  },
  "3": {
    "class_type": "SaveImage",
    "inputs": {
      "images": ["2", 0]
    }
  }
}

Node Parameter Details

Parameter Description Recommended Value
detector Face detector retinaface / mediapipe
face_size Target face area size 384 / 512 / 768
upscale_model Upscale model 4x-UltraSharp / RealESRGAN
upscale_by Upscale factor 1.5 - 4.0
denoise Denoise strength (redraw strength) Restoration: 0.5-0.8, Enhancement: 0.3-0.5
cfg Guidance scale 5.0 - 8.0
steps Inference steps 20 - 35
seed Random seed Fixed value for consistency

Advanced Face Detailer Workflow

{
  "1": {
    "class_type": "LoadImage",
    "inputs": {"image": "portrait.jpg"}
  },
  "2": {
    "class_type": "FaceDetectionAndMasking",
    "inputs": {
      "image": ["1", 0],
      "detector": "retinaface",
      "detection_threshold": 0.5,
      "bbox_expansion": 0.3
    }
  },
  "3": {
    "class_type": "CropAndUpscaleFaces",
    "inputs": {
      "image": ["1", 0],
      "masks": ["2", 1],
      "target_size": 512,
      "upscale_model": "4x-UltraSharp"
    }
  },
  "4": {
    "class_type": "CLIPTextEncode",
    "inputs": {
      "text": "beautiful face, sharp eyes, natural skin texture, high quality portrait, detailed",
      "clip": ["clip", 0]
    }
  },
  "5": {
    "class_type": "KSampler",
    "inputs": {
      "model": ["model", 0],
      "positive": ["4", 0],
      "negative": ["4_neg", 0],
      "latent_image": ["3", 0],
      "seed": 42,
      "steps": 28,
      "cfg": 7.0,
      "sampler_name": "euler",
      "scheduler": "normal",
      "denoise": 0.5
    }
  },
  "6": {
    "class_type": "ResizeAndCompositeFaces",
    "inputs": {
      "original_image": ["1", 0],
      "processed_faces": ["5", 0],
      "masks": ["2", 1]
    }
  },
  "7": {
    "class_type": "SaveImage",
    "inputs": {"images": ["6", 0]}
  }
}

Node Connection Guide

  1. LoadImage → Load the image needing face processing
  2. FaceDetectionAndMasking → Detect faces and generate masks
  3. CropAndUpscaleFaces → Crop and upscale face areas
  4. CLIPTextEncode → Encode face enhancement prompts
  5. KSampler → Use Z-Image to redraw faces
  6. ResizeAndCompositeFaces → Scale processed faces back and blend into original
  7. SaveImage → Save final result

Face Resolution Enhancement

Dedicated Face Upscale Models

Model Upscale Factor Features
4x-UltraSharp 4x General upscaling, good detail preservation
RealESRGAN-x4plus 4x Face-optimized, fast speed
GFPGAN 4x Dedicated face restoration
CodeFormer 4x Face restoration, good for low-quality input
RestoreFormer 4x Latest face restoration model

Face Upscale Workflow

Low-resolution Face → Upscale Model → Diffusion Model Fine-tuning → Enhanced Face
# Pseudo-code: face resolution enhancement process
def enhance_face_resolution(image, face_bbox, target_size=512):
    # 1. Crop face area
    face_crop = crop_image(image, face_bbox)

    # 2. Upscale
    face_upscaled = upscale(face_crop, target_size=target_size, model="4x-UltraSharp")

    # 3. Diffusion model fine-tuning (low strength)
    face_enhanced = diffusion_refine(
        face_upscaled,
        prompt="high quality face portrait, sharp details, realistic skin texture",
        strength=0.35,
        steps=20,
        cfg=6.0
    )

    # 4. Scale back to original position
    face_resized = resize_to_original(face_enhanced, face_bbox)

    # 5. Composite into original image
    result = composite(image, face_resized, face_bbox, feather_radius=15)

    return result

Face Artifact Removal

Common Face Artifact Types

Artifact Type Description Repair Method
Eye inconsistency Eyes have different directions or sizes High strength redraw + symmetry prompts
Deformed teeth Wrong tooth shape or arrangement Face restoration model + inpainting
Facial distortion Asymmetric face structure Restoration model (GFP-GAN/CodeFormer)
Abnormal skin texture Stripes or unnatural skin texture Low strength redraw + texture prompts
Extra facial features Extra eyes, mouths, etc. High strength redraw + correct anatomy prompts

Artifact Repair Workflow

{
  "artifact_fix_workflow": {
    "steps": [
      "1. Detect face area",
      "2. Use restoration model for initial repair",
      "3. Use diffusion model for fine-tuning",
      "4. Check and fix specific areas (eyes, teeth)",
      "5. Composite into original image"
    ],
    "key_parameters": {
      "restoration_model": "CodeFormer",
      "restoration_weight": 0.7,
      "diffusion_strength": 0.4,
      "specific_fix_strength": 0.6
    }
  }
}

Batch Face Processing

Batch Processing Script

import os
import torch
from PIL import Image
from pathlib import Path

def batch_face_detailer(input_dir, output_dir, config):
    """Batch face processing"""
    os.makedirs(output_dir, exist_ok=True)

    for filename in os.listdir(input_dir):
        if not filename.lower().endswith(('.jpg', '.jpeg', '.png')):
            continue

        input_path = os.path.join(input_dir, filename)
        output_path = os.path.join(output_dir, filename)

        try:
            # Load image
            image = Image.open(input_path)

            # Detect faces
            faces = detect_faces(image)
            if not faces:
                print(f"No faces detected in {filename}")
                continue

            # Process each face
            result = image
            for face in faces:
                result = enhance_face(result, face, config)

            # Save result
            result.save(output_path)
            print(f"Processed: {filename} ({len(faces)} faces)")

        except Exception as e:
            print(f"Error processing {filename}: {e}")

    print(f"Batch processing complete: {output_dir}")

Batch Configuration

batch_config = {
    "detector": "retinaface",
    "face_size": 512,
    "upscale_model": "4x-UltraSharp",
    "upscale_by": 2.0,
    "denoise": 0.5,
    "cfg": 7.0,
    "steps": 28,
    "prompt": "beautiful face, sharp eyes, natural skin texture, high quality portrait"
}

# Run batch processing
batch_face_detailer(
    input_dir="./input_images",
    output_dir="./output_enhanced",
    config=batch_config
)

Integration with Inpainting Workflow

The Face Detailer can be integrated with the inpainting workflow (ZI-052) for even more precise face editing:

Face Detection → Inpainting Mask → Face Upscale → Diffusion Redraw → Composite

This allows you to combine face-specific enhancement with general inpainting techniques for maximum quality.

Practical Examples

Example 1: Portrait Photography Enhancement

Input: Portrait photo with slightly blurry face

Configuration:

  • Detector: RetinaFace
  • Face size: 512
  • Upscale: 4x-UltraSharp
  • Denoise: 0.35 (enhancement, not restoration)

Prompt:

high quality portrait, sharp eyes, natural skin texture, professional photography, detailed face

Example 2: Anime Character Face Fix

Input: Anime character with distorted facial features

Configuration:

  • Detector: MediaPipe
  • Face size: 384
  • Upscale: RealESRGAN
  • Denoise: 0.6 (moderate restoration)

Prompt:

anime character face, correct facial features, detailed eyes, anime style, high quality

Example 3: Group Photo Face Improvement

Input: Group photo with multiple faces at different qualities

Configuration:

  • Batch processing enabled
  • Detector: RetinaFace
  • Face size: 512
  • Denoise: 0.5 (balanced restoration/enhancement)

Prompt:

group of people, all faces clear and detailed, natural appearance, high quality photography

Example 4: ID Photo Generation

Input: Face needs to be centered and enhanced for ID photo format

Configuration:

  • Detector: RetinaFace
  • Face size: 512
  • Upscale: 4x-UltraSharp
  • Denoise: 0.45

Prompt:

ID photo, centered face, neutral expression, plain background, professional, high quality

References

Z-Image Team