> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/tu-xiang-chu-li/iclight.md).

# ICLight

在 Clore.ai GPU 上使用 IC-Light 进行 AI 图像重打光

使用 AI 驱动的照明控制，为任意图像重新打光。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

{% hint style="info" %}
本指南中的所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace) 市场。
{% endhint %}

## 在 CLORE.AI 上租用

1. 访问 [CLORE.AI 市场](https://clore.ai/marketplace)
2. 按 GPU 类型、VRAM 和价格筛选
3. 选择 **按需** （固定费率）或 **竞价** （出价）
4. 配置你的订单：
   * 选择 Docker 镜像
   * 设置端口（SSH 用 TCP，Web UI 用 HTTP）
   * 如有需要，添加环境变量
   * 输入启动命令
5. 选择支付方式： **CLORE**, **BTC**，或 **USDT/USDC**
6. 创建订单并等待部署

### 访问你的服务器

* 在以下位置查找连接信息 **我的订单**
* Web 界面：使用 HTTP 端口 URL
* SSH： `ssh -p <port> root@<proxy-address>`

## 什么是 IC-Light？

lllyasviel 的 IC-Light 支持：

* 根据文本描述为图像重新打光
* 更改光照方向和颜色
* 添加或移除阴影
* 创建影棚灯光效果
* 前景/背景重打光

## 资源

* **GitHub：** [lllyasviel/IC-Light](https://github.com/lllyasviel/IC-Light)
* **HuggingFace：** [lllyasviel/IC-Light](https://huggingface.co/lllyasviel/IC-Light)
* **演示：** [HuggingFace Space](https://huggingface.co/spaces/lllyasviel/IC-Light)
* **论文：** 基于 ControlNet 架构

## 推荐硬件

| 组件   | 最低            | 推荐            | 最佳            |
| ---- | ------------- | ------------- | ------------- |
| GPU  | RTX 3060 12GB | RTX 4080 16GB | RTX 4090 24GB |
| VRAM | 8GB           | 12GB          | 16GB          |
| CPU  | 4 核           | 8 核           | 16 核          |
| RAM  | 16GB          | 32GB          | 64GB          |
| 存储   | 30GB SSD      | 50GB NVMe     | 100GB NVMe    |
| 网络   | 100 Mbps      | 500 Mbps      | 1 Gbps        |

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**端口：**

```
22/tcp
7860/http
```

**命令：**

```bash
cd /workspace && \
git clone https://github.com/lllyasviel/IC-Light.git && \
cd IC-Light && \
pip install -r requirements.txt && \
python gradio_demo.py
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 安装

```bash
git clone https://github.com/lllyasviel/IC-Light.git
cd IC-Light
pip install -r requirements.txt

# 模型会在首次运行时自动下载
```

## 你可以创建什么

### 产品摄影

* 为电商提供完美光照
* 一致的目录图片
* 无需影棚即可获得影棚级效果

### 人像增强

* 修正照片中的不良光照
* 添加戏剧性的光效
* 创建专业头像照

### 创意项目

* 氛围转换
* 日夜转换
* 艺术化光效

### 视频制作

* 跨场景匹配光照
* 创建适合 VFX 的素材
* 修正现场拍摄的光照问题

### 营销素材

* 主视觉图创建
* 一致的品牌视觉图像
* 快速照片修饰

## 基础用法

### 前景重打光（FC 模式）

在保持背景不变的情况下重新为主体打光：

```python
import torch
from PIL import Image
from diffusers import StableDiffusionPipeline
from ic_light import ICLightFC

# 加载模型
model = ICLightFC.from_pretrained("lllyasviel/IC-Light-FC")
model.to("cuda")

# 加载图像
image = Image.open("portrait.jpg")

# 使用文本提示重新打光
result = model.relight(
    image=image,
    prompt="左侧的金色日光",
    num_inference_steps=25
)

result.save("relit_portrait.jpg")
```

### 背景条件（FBC 模式）

让前景重新打光以匹配新背景：

```python
from ic_light import ICLightFBC
from PIL import Image

model = ICLightFBC.from_pretrained("lllyasviel/IC-Light-FBC")
model.to("cuda")

# 加载前景和新背景
foreground = Image.open("person.png")  # 带透明背景
background = Image.open("sunset_scene.jpg")

# 重新打光以匹配背景
result = model.relight(
    foreground=foreground,
    background=background,
    prompt="温暖的日落光照",
    num_inference_steps=25
)

result.save("composited.jpg")
```

## 光照提示词

### 基于方向的光照

```python
prompts = [
    "来自左侧的明亮光线",
    "来自上方的柔和光线",
    "来自后方的戏剧性背光",
    "来自右侧的轮廓光",
    "正面扩散光",
    "来自下方的低角度光线"
]
```

### 基于颜色的光照

```python
prompts = [
    "温暖的金色阳光",
    "清冷的蓝色黄昏",
    "霓虹粉色光",
    "绿色环境光",
    "橙色日落余晖",
    "白色影棚灯光"
]
```

### 基于环境的光照

```python
prompts = [
    "户外日光，强烈阳光",
    "室内窗光，柔和阴影",
    "夜晚城市灯光，霓虹反射",
    "烛光，温暖摇曳",
    "阴天，漫射光",
    "影棚柔光箱，专业"
]
```

## 批量处理

```python
import os
from PIL import Image
from ic_light import ICLightFC

model = ICLightFC.from_pretrained("lllyasviel/IC-Light-FC")
model.to("cuda")

input_dir = "./images"
output_dir = "./relit"
os.makedirs(output_dir, exist_ok=True)

lighting_prompt = "专业影棚灯光，柔和阴影"

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

    image = Image.open(os.path.join(input_dir, filename))

    result = model.relight(
        image=image,
        prompt=lighting_prompt,
        num_inference_steps=25
    )

    result.save(os.path.join(output_dir, f"relit_{filename}"))
    print(f"已处理：{filename}")
```

## 多种光照变化

```python
from ic_light import ICLightFC
from PIL import Image
import os

model = ICLightFC.from_pretrained("lllyasviel/IC-Light-FC")
model.to("cuda")

image = Image.open("product.jpg")

lighting_variations = {
    "daylight": "明亮的自然日光，干净的白色背景",
    "dramatic": "戏剧性的侧光，深色阴影",
    "warm": "温暖的黄金时刻，柔和的橙色光晕",
    "cool": "清冷的蓝色灯光，现代美感",
    "studio": "专业影棚柔光箱，均匀照明"
}

os.makedirs("./variations", exist_ok=True)

for name, prompt in lighting_variations.items():
    result = model.relight(
        image=image,
        prompt=prompt,
        num_inference_steps=25
    )
    result.save(f"./variations/{name}.jpg")
    print(f"已生成：{name}")
```

## Gradio 界面

```python
import gradio as gr
from PIL import Image
from ic_light import ICLightFC

model = ICLightFC.from_pretrained("lllyasviel/IC-Light-FC")
model.to("cuda")

def relight_image(image, prompt, steps, seed):
    generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None

    result = model.relight(
        image=image,
        prompt=prompt,
        num_inference_steps=steps,
        generator=generator
    )

    return result

demo = gr.Interface(
    fn=relight_image,
    inputs=[
        gr.Image(type="pil", label="输入图像"),
        gr.Textbox(
            label="光照提示词",
            value="专业影棚灯光",
            placeholder="描述你想要的光照..."
        ),
        gr.Slider(10, 50, value=25, step=5, label="步数"),
        gr.Number(value=-1, label="种子（-1 表示随机）")
    ],
    outputs=gr.Image(label="重打光图像"),
    title="IC-Light - AI 图像重打光",
    description="使用文本描述更改任意图像中的光照。在 CLORE.AI GPU 服务器上运行。",
    examples=[
        ["example.jpg", "左侧的金色日光", 25, -1],
        ["example.jpg", "戏剧性的轮廓光，深色背景", 25, -1],
        ["example.jpg", "柔和的窗光，轻柔阴影", 25, -1]
    ]
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## ComfyUI 集成

IC-Light 可作为 ComfyUI 节点使用：

```bash
cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-IC-Light.git
```

### ComfyUI 工作流

1. 加载你的图像
2. 添加 IC-Light Loader 节点
3. 连接到 IC-Light Apply 节点
4. 设置光照提示词
5. 连接到 KSampler
6. 输出到 Save Image

## 配合背景移除使用

```python
from ic_light import ICLightFBC
from rembg import remove
from PIL import Image

# 先移除背景
original = Image.open("photo.jpg")
foreground = remove(original)

# 加载新背景
background = Image.open("studio_bg.jpg")

# 重新打光以匹配
model = ICLightFBC.from_pretrained("lllyasviel/IC-Light-FBC")
model.to("cuda")

result = model.relight(
    foreground=foreground,
    background=background,
    prompt="与背景匹配的影棚灯光",
    num_inference_steps=25
)

result.save("composited.jpg")
```

## 性能

| 模式      | 分辨率       | GPU      | 速度  |
| ------- | --------- | -------- | --- |
| FC（前景）  | 512x512   | RTX 3090 | 3 秒 |
| FC（前景）  | 512x512   | RTX 4090 | 2 秒 |
| FBC（合成） | 512x512   | RTX 4090 | 3 秒 |
| FC（前景）  | 1024x1024 | A100     | 4 秒 |

## 模型变体

| 模型           | 描述      | 使用场景    |
| ------------ | ------- | ------- |
| IC-Light-FC  | 前景一致    | 单张图像重打光 |
| IC-Light-FBC | 前景-背景一致 | 与背景合成   |

## 常见问题与解决方案

### 光照没有变化

**问题：** 输出看起来与输入相似

**解决方案：**

* 使用更详细的光照提示词
* 将推理步数提高到 30-40
* 尝试不同的种子值
* 在提示词中使用更强的对比（例如，“戏剧性”对比“柔和”）

```python

# 更详细的提示词
result = model.relight(
    image=image,
    prompt="来自左上方的极亮戏剧性聚光灯，右侧深色阴影",
    num_inference_steps=35
)
```

### 脸部/细节出现伪影

**问题：** 脸部或细节看起来失真

**解决方案：**

* 降低强度/引导尺度
* 使用更多推理步数
* 保持光照变化微妙
* 使用人脸修复进行后处理

### 颜色偏移问题

**问题：** 不需要的颜色变化

**解决方案：**

* 在提示词中明确说明颜色
* 在提示词中添加“保留原始颜色”
* 使用中性色的光照描述
* 进行颜色校正后处理

### 背景变化

**问题：** 当只应改变前景时，背景却发生了变化

**解决方案：**

* 使用 FC 模式（前景一致）
* 通过去除背景进行预处理
* 使用蒙版分离主体

### 结果不一致

**问题：** 相同提示词会得到很不同的结果

**解决方案：**

* 设置固定种子以确保可复现
* 增加推理步数以提高稳定性
* 使用更简单、更直接的提示词

```python

# 使用固定种子获得一致结果
result = model.relight(
    image=image,
    prompt=prompt,
    num_inference_steps=30,
    generator=torch.Generator("cuda").manual_seed(42)
)
```

## 故障排查

### 重新打光看起来不自然

* 使光照方向与场景一致
* 使用合适的光照强度
* 考虑原图中的阴影

### 背景受到影响

* 正确使用前景蒙版
* 先将主体从背景中分割出来
* 调整光衰减设置

### 输出过暗/过亮

* 调整光照强度值
* 如可用，请使用 HDR 输出
* 使用曲线进行后处理

### 模型未加载

* 下载所有必需的检查点
* 检查文件完整性
* 验证 CUDA 兼容性

## 成本估算

CLORE.AI 市场的典型费率（截至 2024 年）：

| GPU       | 小时费率    | 日费率     | 4 小时会话  |
| --------- | ------- | ------- | ------- |
| RTX 3060  | \~$0.03 | \~$0.70 | \~$0.12 |
| RTX 3090  | \~$0.06 | \~$1.50 | \~$0.25 |
| RTX 4090  | \~$0.10 | \~$2.30 | \~$0.40 |
| A100 40GB | \~$0.17 | \~$4.00 | \~$0.70 |
| A100 80GB | \~$0.25 | \~$6.00 | \~$1.00 |

*价格因提供商和需求而异。请查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *以获取当前费率。*

**节省费用：**

* 使用 **竞价** 可中断工作市场——约三分之一的服务器将现货价格定得低于按需价格（中位数约优惠 13%），其余则与按需价格持平
* 使用 **CLORE** 代币支付
* 比较不同提供商的价格

## 下一步

* [TripoSR](/guides/guides_v2-zh/3d-sheng-cheng/triposr.md) - 将重新打光后的图像转换为 3D
* Stable Diffusion - 生成用于重新打光的图像
* ComfyUI - 高级工作流集成
* [Fooocus](/guides/guides_v2-zh/tu-xiang-sheng-cheng/fooocus-simple-sd.md) - 简单图像生成


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/tu-xiang-chu-li/iclight.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
