Qwen-Image-Layered 能将图像分解为多个RGBA图层,让图像可编辑,允许用户独立地操纵每个图层,支持高保真度的基础编辑操作,如重新着色、替换内容、修改文本、删除、调整大小和自由移动图层对象,避免对其他内容的干扰。Qwen-Image-Layered 提供图层数量选择,支持递归分解,能实现无限层次的精细化处理。Qwen-Image-Layered 还提供实用的Web界面,方便用户进行图像分解、将图层导出为可编辑的PPTX文件,结合Qwen-Image-Edit进行透明图像编辑。
需要 transformers 的版本 ≥ 4.51.3(支持 Qwen2.5-VL),安装最新版本的 diffusers 和相关依赖。
pip install git+https://github.com/huggingface/diffusers
pip install python-pptx
pip install psd-tools
from diffusers import QwenImageLayeredPipeline
import torch
from PIL import Image
pipeline = QwenImageLayeredPipeline.from_pretrained("Qwen/Qwen-Image-Layered")
pipeline = pipeline.to("cuda", torch.bfloat16)
pipeline.set_progress_bar_config(disable=None)
image = Image.open("asserts/test_images/1.png").convert("RGBA")
inputs = {
"image": image,
"generator": torch.Generator(device='cuda').manual_seed(777),
"true_cfg_scale": 4.0,
"negative_prompt": " ",
"num_inference_steps": 50,
"num_images_per_prompt": 1,
"layers": 4,
"resolution": 640, # 可通过不同尺寸(640, 1024)确定分辨率,当前版本推荐 640
"cfg_normalize": True, # 是否启用 cfg 归一化
"use_en_prompt": True, # 用户未提供描述时,自动选择描述语言
}
with torch.inference_mode():
output = pipeline(**inputs)
output_image = output.images[0]
for i, image in enumerate(output_image):
image.save(f"{i}.png")
运行以下脚本,启动基于 Gradio 的网页界面,可分解图像并将图层导出为 pptx、zip 和 psd 文件,方便灵活编辑和移动图层:
python src/app.py
若需编辑分解后的特定图层,运行以下脚本启动 Gradio 网页界面,借助 Qwen-Image-Edit 编辑带透明度的图像:
python src/tool/edit_rgba_image.py
编辑完单个分解图层后,可通过以下脚本将其合并为新图像。注意按从底层到顶层的顺序上传图层:
python src/tool/combine_layers.py
输入一张图像后,Qwen-Image-Layered 能将其分解为多个独立可编辑的 RGBA 图层。编辑操作仅作用于目标图层,与其他内容物理隔离,保障编辑效果的一致性。
• 改色:对第一个图层进行改色,其他内容保持不变。
• 替换元素:将第二个图层中的人物从女孩替换为男孩(需配合 Qwen-Image-Edit 使用)。
• 文本修改:将图层中的文本修改为“Qwen-Image”(需配合 Qwen-Image-Edit 使用)。
• 删除元素:干净移除不需要的对象。
• 缩放:不扭曲图像的前提下调整对象尺寸。
• 重新定位:在画布内自由移动对象位置。
PowerPoint演示文稿智能生成工具 PowerPoint Slides Skill
金融 AI 新工具 FinClaw,免费提供1000+ 金融专属Skills
PPT Agent 演示文稿生成框架
端到端自主AI科研引擎 NanoResearch
CitationClaw 学术论文智能引用画像和分析报告
pi-autoresearch:pi自动化实验优化循环
OpenClaw Control Center:为OpenClaw用户(包括团队和个人)提供统一的监控和管理界面
OpenClaw Dashboard 仪表盘:让OpenClaw管理更简单
PaperBanana-CN 学术配图助手
996.ICU:工作 996, 生病 ICU