ComfyUI FLUX.1 Kontext 完整使用指南:AI图像编辑与提示词教程
FLUX.1 Kontext 是一个专为文本和图像驱动编辑设计的生成式模型套件。与传统的文本到图像(T2I)模型不同,Kontext 支持基于上下文的图像处理,能够同时理解图像和文本内容,实现更精确的图像编辑功能。
目前 Black Forest Labs 仅发布了 API 版本,开源版本尚未发布,我们会在开源版本发布后在此文章中更新相关教程,目前在 ComfyUI 中已经可以通过 API 节点使用 FLUX.1 Kontext。
FLUX.1 Kontext 模型特点
- 同图像连续编辑:在多个编辑步骤中保持同一图像的一致性
- 精确对象修改:准确修改图像中的特定对象
- 角色一致性编辑:在多步编辑过程中保持角色特征不变
- 风格保持与转换:既能保持原有风格,也能进行风格迁移
- 图像文字编辑:直接编辑图像中的文本内容
- 构图控制:精确控制画面构图、相机角度和姿态
- 快速推理:高效的图像生成和编辑速度
通过 API 在 ComfyUI 中使用 FLUX.1 Kontext
FLUX.1 Kontext 目前以 API 节点 的形式在 ComfyUI 中提供服务。后续开源版本发布后我们也会继续更新此教程,请访问 ComfyUI Wiki 在 ComfyUI 官方文档撰写的相关文章说明。
- 请更新你的 ComfyUI Portable 或者 Desktop 到最新版本。
- 在菜单栏中选择 工作流 -> 浏览模板 -> Image API 分类,找到 FLUX.1 Kontext 相关模板。
使用 API 节点需要你登录,并保证在账户中有充足的余额,请参考 ComfyUI API 节点概览 了解积分系统。
由于对应节点使用非常简单,基本上就是在 API Node 中找到 Flux.1 Kontext [pro] Image
或者 Flux.1 Kontext [pro] Image
节点使用 Load Image
以及 Save Image
节点即可。
- 在
Load Image
节点中加载需要编辑的图像 - 在
Flux.1 Kontext Pro Image
或者Flux.1 Kontext Max Image
节点中修改必要的参数:prompt
输入你想要编辑的图像的提示词aspect_ratio
设置原图的高宽比,比例必须在 1:4 到 4:1 之间prompt_upsampling
设置是否使用提示词上采样,如果开启,会自动修改提示词以获得更丰富的结果,但结果是不可重复的
- 点击
Run
按钮,或者使用快捷键Ctrl(cmd) + Enter(回车)
来执行图像的编辑。 - 等待 API 返回结果后,你可在
Save Image
节点中查看编辑后的图像,对应的图像也会被保存至ComfyUI/output/
目录下。
ComfyUI Flux.1 Kontext 原生工作流
[待更新]
FLUX.1 Kontext 提示词完全使用指南
FLUX.1 Kontext 提示词基础知识
重要提示:FLUX.1 Kontext 的最大提示词限制为 512 个 token,请合理安排提示词长度。
请使用英文书写对应提示词 Kontext 的核心优势在于理解图像上下文,您只需指定想要改变的内容,无需详细描述整个场景。这使得图像编辑变得更加简单直观。
FLUX.1 Kontext 基本对象修改
Kontext 在直接对象修改方面表现出色,例如改变颜色、替换物体等。
基础修改示例:
修改类型 | 提示词示例 | 效果说明 |
---|---|---|
颜色修改 | ”Change the car color to red” | 仅改变汽车颜色,保持其他不变 |
物体替换 | ”Change the flowers to yellow” | 改变花朵颜色 |
简单添加 | ”Add an apple on the table” | 在现有场景中添加新物体 |
提示词精确度等级对比
不同详细程度的提示词会产生不同的编辑效果。以下是三个精确度等级的对比:
等级对比表
精确度等级 | 特点 | 优势 | 劣势 | 适用场景 |
---|---|---|---|---|
简单编辑 | 简洁直接 | 快速便捷 | 可能改变原图风格 | 快速测试想法 |
受控编辑 | 添加保持指令 | 风格更稳定 | 提示词稍长 | 需要保持原图特征 |
复杂变换 | 详细描述所有要求 | 精确控制结果 | 提示词较长 | 多重修改需求 |
具体示例对比
场景:将夜景改为白天
精确度等级 | 提示词 | 预期效果 |
---|---|---|
简单编辑 | ”Change to daytime” | 时间改变,但可能风格也会改变 |
受控编辑 | ”Change to daytime while maintaining the same style of the painting” | 时间改变,风格基本保持 |
复杂变换 | ”Change the setting to a day time, add a lot of people walking the sidewalk while maintaining the same style of the painting” | 多重修改,精确控制 |
风格转换完整指南
风格转换原则表
原则 | 说明 | 好的示例 | 避免的示例 |
---|---|---|---|
明确指定风格 | 使用具体风格名称 | ”Transform to Bauhaus art style" | "Make it artistic” |
引用知名流派 | 提及具体艺术运动 | ”1960s pop art poster style" | "Modern art style” |
描述关键特征 | 详细描述视觉元素 | ”Visible brushstrokes, thick paint texture" | "Make it look better” |
保留重要元素 | 明确保持的内容 | ”While maintaining the original composition and object placement” | 不指定保留内容 |
风格转换提示词对比
将照片转换为绘画风格
效果类型 | 提示词 | 结果质量 |
---|---|---|
❌ 基础(可能失去细节) | “Make it a sketch” | 风格改变但细节丢失 |
✅ 改进(保持结构) | “Convert to pencil sketch with natural graphite lines, cross-hatching, and visible paper texture” | 风格转换且保留场景细节 |
✅ 最佳(全面控制) | “Convert to pencil sketch with natural graphite lines, cross-hatching, and visible paper texture while maintaining all background details and character features” | 完美平衡风格与细节 |
常用风格转换提示词模板
风格类型 | 推荐提示词模板 |
---|---|
油画风格 | ”Transform to oil painting with visible brushstrokes, thick paint texture, and rich color depth” |
水彩画风格 | ”Convert to watercolor painting with transparent colors, paper texture, and natural paint flow effects” |
铅笔素描 | ”Convert to pencil sketch with natural graphite lines, cross-hatching, and visible paper texture” |
动漫风格 | ”Transform to anime style with clear lines, vibrant colors, and typical anime character features” |
黏土动画 | ”Restyle to Claymation style with 3D sculpted texture and soft lighting effects” |
FLUX.1 Kontext 角色一致性编辑框架
角色一致性三步法
步骤 | 作用 | 示例 | 重要性 |
---|---|---|---|
1. 建立参考 | 明确角色身份 | ”The woman with short black hair” | ⭐⭐⭐⭐⭐ |
2. 指定变换 | 说明改变内容 | ”Now in a tropical beach setting” | ⭐⭐⭐⭐ |
3. 保留标记 | 明确保持特征 | ”While maintaining the same facial features and expression” | ⭐⭐⭐⭐⭐ |
角色描述用词对比
描述方式 | 效果 | 示例 | 推荐度 |
---|---|---|---|
❌ 代词引用 | 容易混淆身份 | ”She”, “He”, “This person” | 不推荐 |
✅ 具体描述 | 身份明确 | ”The woman with short black hair” | 强烈推荐 |
✅ 特征标记 | 精确识别 | ”The man with glasses”, “The girl in red coat” | 推荐 |
连续编辑示例序列
角色:年轻女性
编辑步骤 | 提示词 | 目标 |
---|---|---|
步骤 1 | ”She’s now taking a selfie in a street in Freiburg, it’s a lovely day out” | 改变环境和活动 |
步骤 2 | ”Remove the thing from her face” | 移除特定物品 |
步骤 3 | ”It’s now snowing, everything is covered in snow” | 改变天气环境 |
文字编辑专项技巧
文字编辑语法规则
编辑类型 | 语法格式 | 示例 |
---|---|---|
替换文字 | ”Replace ‘[original text]’ with ‘[new text]‘" | "Replace ‘joy’ with ‘BFL‘“ |
修改样式 | ”Replace ‘[original text]’ with ‘[new text]’ while maintaining [style requirements]" | "Replace ‘SALE’ with ‘OPEN’ while maintaining the same font style and color” |
添加文字 | ”Add text ‘[content]’ at [position]" | "Add text ‘WELCOME’ on the sign” |
文字编辑最佳实践对比
做法 | 效果 | 示例 |
---|---|---|
✅ 使用引号包围 | 精确识别目标文字 | ”Replace ‘OPEN’ with ‘CLOSED’” |
❌ 不使用引号 | 可能识别错误 | ”Change OPEN to CLOSED” |
✅ 指定保持样式 | 保持原有视觉效果 | ”While maintaining the same font style and color” |
❌ 不指定保持 | 可能改变整体设计 | 仅指定文字内容 |
FLUX.1 Kontext 问题排除对照表
常见问题及解决方案
问题类型 | 问题表现 | 错误示例 | 正确解决方案 |
---|---|---|---|
角色身份改变 | 人物面部特征变化过大 | ”Transform the person into a Viking" | "Transform the man into a viking warrior while preserving his exact facial features, eye color, and facial expression” |
构图位置偏移 | 主体位置或比例改变 | ”Put him on a beach" | "Change the background to a beach while keeping the person in the exact same position, scale, and pose” |
风格细节丢失 | 转换风格时丢失重要细节 | ”Make it a sketch" | "Convert to pencil sketch with natural graphite lines, cross-hatching, and visible paper texture while preserving all scene details” |
意外元素改变 | 不想改变的部分被修改 | ”Change to daytime" | "Change to daytime while everything else should stay black and white and maintain the original style” |
动词选择对效果的影响
动词类型 | 含义强度 | 适用场景 | 示例 |
---|---|---|---|
”Transform” | 完全改变 | 风格完全改变时 | ”Transform to oil painting style" |
"Change” | 部分修改 | 修改特定元素时 | ”Change the clothing color" |
"Replace” | 直接置换 | 物体或文字替换时 | ”Replace the background with forest" |
"Add” | 增加元素 | 在现有基础上增加时 | ”Add a small bird" |
"Remove” | 删除元素 | 去除不需要的内容时 | ”Remove the cars from background” |
FLUX.1 Kontext 高级提示词组合技巧
多重编辑提示词结构
模板格式:
[主要修改] + [保持要求] + [细节说明]
实际示例:
编辑需求 | 按模板组织的提示词 |
---|---|
改变背景+保持人物 | ”Change the background to a forest scene while keeping the person in exactly the same position and pose, maintaining the original lighting” |
风格转换+保持构图 | ”Transform to watercolor painting style while maintaining the original composition and all object positions, using soft color transitions” |
多对象修改 | ”Change the car to red and the sky to sunset colors while keeping the road and buildings in their original appearance” |
提示词优先级指南
优先级 | 内容类型 | 示例 |
---|---|---|
最高 | 保持人物身份 | ”While maintaining the exact same facial features” |
高 | 主要修改目标 | ”Change the background to beach” |
中 | 风格和质感 | ”Using watercolor painting style” |
低 | 细节补充 | ”Add soft lighting effects” |
FLUX.1 Kontext 实用提示词检查清单
在使用提示词前,请检查以下要点:
基础检查项
- 是否明确指定了要修改的内容?
- 是否说明了需要保持不变的元素?
- 提示词长度是否在512 token限制内?
- 是否使用了具体而非模糊的描述?
高级检查项
- 角色编辑时是否用具体描述而非代词?
- 风格转换时是否描述了具体特征?
- 文字编辑时是否使用了引号?
- 是否选择了合适的动词(transform/change/replace)?
通过这个全面的提示词指南,您可以更好地掌握 FLUX.1 Kontext 的使用技巧,实现更精确的图像编辑效果。
FLUX.1 Kontext 提示词最佳实践总结
- 具体明确:精确的语言能带来更好的结果。使用准确的颜色名称、详细描述和清晰的动作动词,避免模糊术语。
- 从简单开始:在增加复杂性之前先进行核心更改。首先测试基本编辑,然后在成功结果的基础上构建。
- 有意保留:明确说明应保持不变的内容。使用”同时保持相同的[面部特征/构图/光照]“等短语来保护重要元素。
- 必要时迭代:复杂的变换通常需要多个步骤。将剧烈变化分解为连续编辑以获得更好的控制。
- 直接命名主体:使用”这位黑色短发的女性”或”红色汽车”,而不是”她”、“它”或”这个”等代词。
- 文字使用引号:引用您想要更改的确切文字:“将 ‘joy’ 替换为 ‘BFL‘“比一般的文字描述效果更好。
- 明确控制构图:更改背景或设置时,指定”保持准确的相机角度、位置和构图”以防止不必要的重新定位。
- 谨慎选择动词:“转换”可能暗示完全改变,而”更改服装”或”替换背景”能让您更好地控制实际改变的内容。
记住:如果每次编辑的指令数量不太复杂,让内容更明确总是有益的。