🚀 DiffusionLight:通过绘制铬球免费获取光照探针
DiffusionLight 提出了一种简单而有效的技术,用于估计单张输入图像中的光照情况。它利用扩散模型在数十亿标准图像上的训练成果,解决了现有技术在真实、无控制环境下的局限性,能在不同场景中产生令人信服的光照估计结果。
🚀 快速开始
我们推荐查看 GitHub 仓库,该仓库提供了从任何图像中估计光照的代码,包括生成铬球、从铬球中提取环境图,以及使用自定义曝光组合方法创建 HDR 环境图。
✨ 主要特性
- 创新光照估计技术:利用扩散模型在标准图像上的训练成果,解决了现有技术依赖 HDR 全景数据集的局限性。
- 高质量铬球生成:发现了铬球外观与初始扩散噪声图之间的关系,能够持续生成高质量的铬球。
- HDR 光照估计:通过 LoRA 微调 LDR 扩散模型(Stable Diffusion XL),使其能够进行曝光包围以进行 HDR 光照估计。
- 广泛适用性:在不同场景中都能产生令人信服的光照估计结果,对真实场景具有出色的泛化能力。
📦 安装指南
模型权重以 Safetensors 格式提供,可在 Files & versions 标签页 中下载。
💻 使用示例
基础用法
如果您想使用此 LoRA 仅生成铬球,可参考以下示例代码:
import torch
from diffusers.utils import load_image
from diffusers import StableDiffusionXLControlNetInpaintPipeline, ControlNetModel
from transformers import pipeline
from PIL import Image
import numpy as np
IS_UNDER_EXPOSURE = False
if IS_UNDER_EXPOSURE:
PROMPT = "a perfect black dark mirrored reflective chrome ball sphere"
else:
PROMPT = "a perfect mirrored reflective chrome ball sphere"
NEGATIVE_PROMPT = "matte, diffuse, flat, dull"
IMAGE_URL = "https://raw.githubusercontent.com/DiffusionLight/DiffusionLight/main/example/bed.png"
controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-depth-sdxl-1.0", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetInpaintPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
controlnet=controlnet,
torch_dtype=torch.float16,
).to("cuda")
pipe.load_lora_weights("DiffusionLight/DiffusionLight")
pipe.fuse_lora(lora_scale=0.75)
depth_estimator = pipeline(task="depth-estimation", model="Intel/dpt-large")
init_image = load_image(IMAGE_URL)
depth_image = depth_estimator(images=init_image)['depth']
def get_circle_mask(size=256):
x = torch.linspace(-1, 1, size)
y = torch.linspace(1, -1, size)
y, x = torch.meshgrid(y, x)
z = (1 - x**2 - y**2)
mask = z >= 0
return mask
mask = get_circle_mask().numpy()
depth = np.asarray(depth_image).copy()
depth[384:640, 384:640] = depth[384:640, 384:640] * (1 - mask) + (mask * 255)
depth_mask = Image.fromarray(depth)
mask_image = np.zeros_like(depth)
mask_image[384:640, 384:640] = mask * 255
mask_image = Image.fromarray(mask_image)
output = pipe(
prompt=PROMPT,
negative_prompt=NEGATIVE_PROMPT,
num_inference_steps=30,
image=init_image,
mask_image=mask_image,
control_image=depth_mask,
controlnet_conditioning_scale=0.5,
)
output["images"][0].save("output.png")
高级用法
我们采用了自定义管道来为铬球添加满足特定需求的功能,包括 抗锯齿 以平滑边缘、迭代修复 以增强光照方向的正确性,以及 嵌入插值 以在不同曝光下生成铬球。因此,强烈建议您访问 GitHub 仓库 以获取更多高级用法。
📚 详细文档
触发词
铬球状态 |
提示词 |
正常曝光 |
a perfect mirrored reflective chrome ball sphere |
欠曝光 |
a perfect black dark mirrored reflective chrome ball sphere |
铬球生成
我们使用自定义管道来为铬球添加满足特定需求的功能。这包括 抗锯齿 以平滑其边缘,迭代修复 以增强光照方向的正确性,以及 嵌入插值 以在不同曝光下生成铬球。因此,我们强烈建议您访问我们的 GitHub 仓库。
📄 许可证
本项目采用 MIT 许可证。
📖 引用
如果您使用了本项目的相关内容,请引用以下文献:
@inproceedings{Phongthawee2023DiffusionLight,
author = {Phongthawee, Pakkapon and Chinchuthakun, Worameth and Sinsunthithet, Nontaphat and Raj, Amit and Jampani, Varun and Khungurn, Pramook and Suwajanakorn, Supasorn},
title = {DiffusionLight: Light Probes for Free by Painting a Chrome Ball},
booktitle = {ArXiv},
year = {2023},
}
🏢 相关链接
访问我们 🦉
