Extensions/comfyui-image-block-glitch
ComfyUI Extension

comfyui-image-block-glitch

A ComfyUI extension with 1 custom node.

By YudachiL·Created about a month ago·Updated about a month ago· 4
YudachiL/comfyui-image-block-glitch
Nodes1
On cloudLocal install
Categoryimage/effects
Stars4
Updatedabout a month ago
Readme
<div align="center">

Image Block Glitch for ComfyUI

「让像素一点点崩壞」

一个轻量、无需模型的 ComfyUI 图像后处理节点。
适合为二次元插画、角色立绘、海报和封面添加可控的数字故障效果。

ComfyUI Version Python License

效果展示 · 安装 · 工作流 · 参数

<br/> <img src="assets/Preview.gif" alt="Image Block Glitch animated preview" width="900"/> </div>

效果展示

节点会从选区中复制横向矩形图块并进行随机水平错位。可以控制图块尺寸、数量、出现概率、重叠、透明度以及色相偏移。

| Input | Output | |:---:|:---:| | <img src="assets/input.png" alt="Input image" width="460"/> | <img src="assets/output.png" alt="Glitched output" width="460"/> |


功能特点

  • 规整的横向矩形图块:每个故障块保持完整的轴对齐矩形。
  • 任意形状蒙版:蒙版不需要是矩形,节点会在有效区域中寻找能够完整放下图块的位置。
  • 坐标选区:也可以直接使用 x / y / width / height 指定矩形区域。
  • 自然重叠:通过开关允许或禁止图块重叠;开启后由随机布局自然产生重叠。
  • 概率控制:分别控制图块出现概率和色相偏移概率。
  • 色相偏移:每个图块可以在指定角度范围内随机变色。
  • 固定随机结果:相同输入、参数和 seed 会得到相同结果。
  • 批量处理:支持标准 ComfyUI IMAGE 批次。
  • 影响区域输出:额外输出 affected_mask,方便后续合成或继续添加效果。
  • 无需模型:不需要下载权重,节点本体只依赖 ComfyUI 已有的 PyTorch。

节点名称:Image Block Glitch / 图像块错位故障
节点分类:image/effects


安装

ComfyUI/custom_nodes 目录中运行:

git clone https://github.com/YudachiL/comfyui-image-block-glitch.git comfyui-image-block-glitch

也可以下载仓库 ZIP,并解压到:

ComfyUI/custom_nodes/comfyui-image-block-glitch

完成后重启 ComfyUI,搜索 Image Block Glitch


示例工作流

仓库内提供了一份可以直接使用的工作流:

workflows/image_block_glitch_hue_mask.json

可以将 JSON 直接拖入 ComfyUI,或复制到 ComfyUI/user/default/workflows

<div align="center"> <img src="assets/workflow.png" alt="Image Block Glitch ComfyUI workflow" width="960"/> </div>

蒙版模式使用方法

  1. Load Image 节点中上传图片。
  2. 右键该节点并打开蒙版编辑器。
  3. 涂出允许生成故障图块的区域。
  4. region_mode 设置为 mask,然后运行工作流。

蒙版可以是不规则形状。节点只会放置能够完整包含在白色区域内的矩形,因此不会沿蒙版边缘把图块裁成异形。


推荐设置

以下配置可以作为调参起点:

| 效果 | 推荐设置 | | --- | --- | | 轻微画面抖动 | 较少图块、较低高度、较短 shift、色相概率 0.2~0.4 | | 高饱和霓虹故障 | 图块 30~60、允许重叠、色相概率 0.7+、范围 -120~120 | | 横向数据断层 | 关闭色相偏移、使用较宽图块、高 opacity、限定局部蒙版 |

经典横向 glitch 建议保持 vertical_jitter = 0。如果希望图块分布更松散,可以增加少量纵向偏移。


参数说明

| 参数 | 作用 | | --- | --- | | region_mode | coordinates 使用坐标矩形;mask 使用任意形状蒙版 | | region_x / y / width / height | 坐标模式下的处理区域 | | block_count | 尝试生成的图块数量 | | block_probability | 每个候选图块实际出现的概率 | | block_width_min / max | 图块宽度范围,单位 px | | block_height_min / max | 图块高度范围,单位 px | | shift_min / max | 水平错位距离范围,单位 px | | vertical_jitter | 纵向随机偏移;设为 0 时为纯横向 | | allow_overlap | 是否允许故障图块互相覆盖 | | hue_shift_enabled | 是否启用色相偏移 | | hue_shift_probability | 每个已生成图块发生色相偏移的概率 | | hue_shift_min / max | 色相偏移角度范围,支持负数 | | opacity | 图块覆盖强度 | | edge_mode | 坐标模式使用 clip 裁切或 wrap 区域内环绕 | | seed | 随机种子,用于复现结果 |

输出

  • image:处理后的图像。
  • affected_mask:实际生成故障图块的位置遮罩。

使用提示

  • 如果蒙版较窄或形状很碎,请调小 block_width_minblock_height_min
  • block_count 是尝试生成的数量;当概率较低或蒙版空间不足时,实际图块数量可能更少。
  • 蒙版模式会优先保证矩形完整,因此放不下的图块会被跳过。
  • wrap 主要用于坐标模式;蒙版模式始终受蒙版有效区域限制。

独立脚本

不启动 ComfyUI 也可以直接运行 standalone.py

python standalone.py assets/input.png out.png \
  --x 100 --y 200 --width 600 --height 350 \
  --blocks 30 --block-width 60 260 --block-height 4 22 \
  --shift 20 180 --hue-shift -30 30 \
  --hue-probability 0.65 --seed 123

使用 --mask mask.png 可以在任意形状蒙版内生成完整矩形图块。

<div align="center">

If this node is useful for your work, feel free to share your results, open an issue, or leave a Star.

MIT License

</div>