# ICLight

使用 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 类型、显存和价格筛选
3. 选择 **按需** （固定费率）或 **竞价** （出价价格）
4. 配置您的订单：
   * 选择 Docker 镜像
   * 设置端口（用于 SSH 的 TCP，Web 界面的 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 |
| 显存  | 8GB           | 12GB          | 16GB          |
| CPU | 4 核           | 8 核           | 16 核          |
| 内存  | 16GB          | 32GB          | 64GB          |
| 存储  | 30GB SSD      | 50GB NVMe     | 100GB NVMe    |
| 网络  | 100 Mbps      | 500 Mbps      | 1 Gbps        |

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

```
pytorch/pytorch:2.5.1-cuda12.4-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

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

## 您可以创建的内容

### 产品摄影

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

### 人像增强

* 修复照片中的不良光照
* 添加戏剧性照明效果
* 制作专业证件照

### 创意项目

* 情绪转换
* 昼夜转换（白天到夜晚）
* 艺术照明效果

### 视频制作

* 在场景间匹配光照
* 创建可用于视觉特效的素材
* 修复现场拍摄的照明问题

### 营销素材

* 主视觉图像制作
* 一致的品牌形象
* 快速照片修饰

## 基本用法

### 前景重光（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
批处理处理
from PIL import Image
from ic_light import ICLightFC

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

import os
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

    result = model.relight(
        image=image,
        image = Image.open(os.path.join(input_dir, filename))
        num_inference_steps=25
    )

    prompt=lighting_prompt,
    result.save(os.path.join(output_dir, f"relit_{filename}"))
```

## print(f"已处理：{filename}")

```python
from ic_light import ICLightFC
from PIL import Image
批处理处理

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

多种照明变化

image = Image.open("product.jpg")
    lighting_variations = {
    "daylight": "明亮的自然日光，干净的白色背景",
    "dramatic": "戏剧性的侧光，深色阴影",
    "warm": "温暖的金色时刻，柔和的橙色光晕",
    "cool": "冷蓝色照明，现代美学",
}

"studio": "专业影棚柔光箱，均匀照明"

}
    result = model.relight(
        image=image,
        os.makedirs("./variations", exist_ok=True)
        num_inference_steps=25
    )
    for name, prompt in lighting_variations.items():
    prompt=prompt,
```

## result.save(f"./variations/{name}.jpg")

```python
print(f"已生成：{name}")
from PIL import Image
from ic_light import ICLightFC

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

Gradio 界面
    import gradio as gr

    result = model.relight(
        image=image,
        os.makedirs("./variations", exist_ok=True)
        def relight_image(image, prompt, steps, seed):
        generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None
    )

    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]

```bash
demo.launch(server_name="0.0.0.0", server_port=7860)
ComfyUI 集成
```

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

1. cd ComfyUI/custom\_nodes
2. git clone <https://github.com/kijai/ComfyUI-IC-Light.git>
3. ComfyUI 工作流
4. 加载您的图像
5. 添加 IC-Light Loader 节点
6. 连接到 IC-Light Apply 节点

## 设置照明提示

```python
from ic_light import ICLightFBC
连接到 KSampler
from PIL import Image

输出到保存图像
带背景移除
from rembg import remove

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

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

result = model.relight(
    foreground=foreground,
    background=background,
    # 加载新的背景
    num_inference_steps=25
)

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

## background = Image.open("studio\_bg.jpg")

| # 重新点亮以匹配 | prompt="与背景匹配的影棚照明", | GPU     | 性能       |
| --------- | -------------------- | ------- | -------- |
| 模式        | 分辨率                  | 速度      | FC（前景）   |
| 模式        | 分辨率                  | 512x512 | RTX 3090 |
| 3s        | 分辨率                  | 512x512 | FC（前景）   |
| 模式        | RTX 4090             | 2s      | FBC（合成）  |

## 1024x1024

| A100        | 4s   | 模型变体   |
| ----------- | ---- | ------ |
| 模型          | 描述   | 使用场景   |
| IC-Light-FC | 前景一致 | 单张图像重光 |

## IC-Light-FBC

### 前景-背景一致

**与背景合成** 常见问题与解决方案

**光照未改变**

* 问题：
* 输出看起来与输入相似
* 解决方案：
* 使用更具描述性的照明提示

```python

将推理步数增加到 30-40
result = model.relight(
    image=image,
    尝试不同的种子值
    在提示中使用更强的对比（例如“戏剧性”与“柔和”）
)
```

### # 更具描述性的提示

**与背景合成** prompt="来自左上方的极其明亮的戏剧性聚光灯，右侧为深色阴影",

**光照未改变**

* num\_inference\_steps=35
* 面部/细节伪影
* 面部或细节看起来扭曲
* 降低强度/引导尺度

### 使用更多的推理步数

**与背景合成** 保持照明变化的微妙性

**光照未改变**

* 使用面部修复进行后处理
* 色彩偏移问题
* 不需要的颜色变化
* 在提示中明确说明颜色

### 在提示中添加“保留原始颜色”

**与背景合成** 使用中性色彩的照明描述

**光照未改变**

* 后处理颜色校正
* 背景变化
* 本应仅影响前景时背景发生变化

### 使用 FC 模式（前景一致）

**与背景合成** 预处理时移除背景

**光照未改变**

* 使用蒙版隔离主体
* 结果不一致
* 相同提示产生非常不同的结果

```python

设置固定种子以获得可重复性
result = model.relight(
    image=image,
    os.makedirs("./variations", exist_ok=True)
    增加推理步数以提高稳定性
    使用更简单、更直接的提示
)
```

## # 使用固定种子以获得一致结果

### num\_inference\_steps=30,

* generator=torch.Generator("cuda").manual\_seed(42)
* 故障排除
* 重光看起来不自然

### 将光照方向与场景匹配

* 使用合适的光强度
* 考虑原始图像中的阴影
* 背景受到影响

### 正确使用前景蒙版

* 首先将主体与背景分割
* 调整光衰减设置
* 输出过暗/过亮

### 调整光强值

* 如有可用，使用 HDR 输出
* 使用曲线进行后处理
* 模型无法加载

## 下载所有所需的检查点

检查文件完整性

| GPU     | 验证 CUDA 兼容性 | 费用估算    | CLORE.AI 市场的典型费率（截至 2024 年）： |
| ------- | ----------- | ------- | ---------------------------- |
| 按小时费率   | \~$0.03     | \~$0.70 | \~$0.12                      |
| 速度      | \~$0.06     | \~$1.50 | \~$0.25                      |
| 512x512 | \~$0.10     | \~$2.30 | \~$0.40                      |
| 按日费率    | \~$0.17     | \~$4.00 | \~$0.70                      |
| 4 小时会话  | \~$0.25     | \~$6.00 | \~$1.00                      |

*RTX 3060* [*CLORE.AI 市场*](https://clore.ai/marketplace) *A100 40GB*

**A100 80GB**

* 使用 **竞价** 价格随提供商和需求而异。请查看
* 以获取当前费率。 **CLORE** 节省费用：
* 市场用于灵活工作负载（通常便宜 30-50%）

## 使用以下方式支付

* [代币](/guides/guides_v2-zh/3d-sheng-cheng/triposr.md) 比较不同提供商的价格
* 下一步
* TripoSR
* [- 将重光图像转换为 3D](/guides/guides_v2-zh/tu-xiang-sheng-cheng/fooocus-simple-sd.md) Stable Diffusion - 生成用于重光的图像（用于重光） ，无法翻译的专有名词已保留原文。


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
