본문 바로가기
AI2025년 10월 5일6분 읽기

AI 이미지 업스케일링 — ESRGAN과 Real-ESRGAN 활용

YS
김영삼
조회 154

AI 초해상도(Super-Resolution) 기술

AI 기반 이미지 업스케일링은 저해상도 이미지를 고해상도로 변환하는 기술입니다. 단순 보간법(bilinear, bicubic)과 달리 AI 모델은 디테일을 생성하여 사실적인 결과를 만들어냅니다.

주요 모델 비교

모델배율특징용도
ESRGAN4x높은 디테일, 선명사진, 일러스트
Real-ESRGAN2x/4x실제 열화 대응실사진 복원
SwinIR2x/4x트랜스포머 기반고품질 복원
Waifu2x2x애니메이션 특화일러스트, 만화

Real-ESRGAN 설치 및 사용

# 설치
pip install realesrgan
git clone https://github.com/xinntao/Real-ESRGAN.git
cd Real-ESRGAN
pip install -r requirements.txt
python setup.py develop

# CLI 사용
python inference_realesrgan.py \
  -n RealESRGAN_x4plus \
  -i inputs/ \
  -o results/ \
  --outscale 4 \
  --face_enhance

# 애니메이션 이미지용
python inference_realesrgan.py \
  -n RealESRGAN_x4plus_anime_6B \
  -i anime_inputs/ \
  -o anime_results/

Python 코드에서 사용

from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import cv2

model = RRDBNet(
    num_in_ch=3, num_out_ch=3,
    num_feat=64, num_block=23,
    num_grow_ch=32, scale=4
)

upsampler = RealESRGANer(
    scale=4,
    model_path='weights/RealESRGAN_x4plus.pth',
    model=model,
    tile=400,
    tile_pad=10,
    pre_pad=0,
    half=True,
    gpu_id=0,
)

img = cv2.imread('input.jpg', cv2.IMREAD_UNCHANGED)
output, _ = upsampler.enhance(img, outscale=4)
cv2.imwrite('output.jpg', output)

얼굴 보정 통합 (GFPGAN)

from gfpgan import GFPGANer

face_enhancer = GFPGANer(
    model_path='weights/GFPGANv1.4.pth',
    upscale=4,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=upsampler,
)

_, _, output = face_enhancer.enhance(
    img,
    has_aligned=False,
    only_center_face=False,
    paste_back=True,
)
cv2.imwrite('face_enhanced.jpg', output)

배치 처리 최적화

import glob
from pathlib import Path
from tqdm import tqdm

input_dir = Path('inputs')
output_dir = Path('outputs')
output_dir.mkdir(exist_ok=True)

images = list(input_dir.glob('*.jpg')) + list(input_dir.glob('*.png'))

for img_path in tqdm(images, desc='Upscaling'):
    img = cv2.imread(str(img_path), cv2.IMREAD_UNCHANGED)
    try:
        output, _ = upsampler.enhance(img, outscale=4)
        out_path = output_dir / f"{img_path.stem}_4x.png"
        cv2.imwrite(str(out_path), output)
    except RuntimeError as e:
        upsampler.tile = 200
        output, _ = upsampler.enhance(img, outscale=4)
        cv2.imwrite(str(output_dir / f"{img_path.stem}_4x.png"), output)
        upsampler.tile = 400
  • Real-ESRGAN은 실제 사진의 다양한 열화(압축, 노이즈, 블러)에 강합니다
  • VRAM이 부족하면 tile 파라미터를 줄이거나 half=True로 FP16을 사용합니다
  • 애니메이션/일러스트에는 전용 모델(anime_6B)이 더 좋은 결과를 줍니다
  • 과도한 업스케일링(8x 이상)은 아티팩트가 생기므로 4x를 2번 적용하는 것이 낫습니다

AI 업스케일링은 오래된 사진 복원, 웹 이미지 개선, 인쇄용 해상도 확보 등 다양한 실용적 활용이 가능합니다. 무료 오픈소스 모델만으로도 상용 수준의 결과를 얻을 수 있습니다.

댓글 0

아직 댓글이 없습니다.
Ctrl+Enter로 등록