Add files via upload

This commit is contained in:
viviiii
2026-03-04 15:59:01 +08:00
committed by GitHub
parent 6e7d6a734c
commit 6f7b0bcbcd
5 changed files with 167 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2026 viviiii
Copyright (c) 2025 ComfyUI-DepthNormalizer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+94 -1
View File
@@ -1,2 +1,95 @@
# ComfyUI-DepthNormalizer
ComfyUI custom node to normalize depth maps into stable 0–190 8-bit range.
A ComfyUI custom node for normalizing depth maps to a specific range (0–190 by default).
## 简介
ComfyUI-DepthNormalizer 提供了一个自定义节点,用于将深度图按 0–255 灰阶域进行归一化和拉伸,使输出稳定在 0–190(可配置)。
**核心功能:**
- 在 8-bit 域(0-255)中手动设置最小/最大值进行重映射
- 支持将输出最大值映射到目标值(默认 190)
- 可选减去最小值,强制黑色为 0
- 自动处理 ComfyUI IMAGE 格式(0-1 float)与 8-bit 域的转换
## 安装方式
### 方式一:通过 ComfyUI Manager 安装(推荐)
1. 打开 ComfyUI,点击 **Manager** 按钮
2. 选择 **Install Custom Nodes**
3. 搜索 "DepthNormalizer" 或输入仓库地址
4. 点击安装并重启 ComfyUI
### 方式二:手动安装
```bash
# 进入 ComfyUI 的 custom_nodes 目录
cd /path/to/ComfyUI/custom_nodes
# 克隆仓库
git clone https://github.com/your-username/ComfyUI-DepthNormalizer.git
# 重启 ComfyUI
```
## 节点说明
### Depth Range → 0–190 (Manual)
将深度图按指定的 8-bit 范围进行归一化,输出到目标范围。
#### 输入参数
| 参数名 | 类型 | 默认值 | 范围 | 说明 |
|--------|------|--------|------|------|
| `image` | IMAGE | - | - | 输入深度图(ComfyUI IMAGE 格式,0-1 float) |
| `min_8bit` | INT | 0 | 0-255 | 输入深度图在 8-bit 域的最小值 |
| `max_8bit` | INT | 190 | 0-255 | 输入深度图在 8-bit 域的最大值 |
| `target_max_8bit` | INT | 190 | 1-255 | 输出深度图在 8-bit 域的目标最大值 |
| `subtract_min` | BOOLEAN | True | - | 是否先减去最小值,使黑色强制为 0 |
| `clamp_to_target` | BOOLEAN | True | - | 是否将输出限制在目标范围内 |
#### 输出
| 输出名 | 类型 | 说明 |
|--------|------|------|
| `image` | IMAGE | 归一化后的深度图(ComfyUI IMAGE 格式,0-1 float) |
#### 处理逻辑
1. 将输入从 0-1 float 转换为 0-255 域:`x255 = image * 255.0`
2. 根据 `subtract_min` 参数选择重映射方式:
- 如果为 True:`y255 = (x255 - min) * (target / (max - min))`
- 如果为 False:`y255 = x255 * (target / max)`
3. 根据 `clamp_to_target` 进行裁剪:
- 如果为 True:限制在 `[0, target]`
- 如果为 False:限制在 `[0, 255]`
4. 转换回 0-1 float:`output = y255 / 255.0`
## 使用示例
### 示例:将深度范围 1-117 拉伸到 0-190
假设你有一个深度图,其有效深度值在 8-bit 域的范围是 1 到 117,你希望将其拉伸到 0-190 范围:
| 参数 | 值 |
|------|-----|
| `min_8bit` | 1 |
| `max_8bit` | 117 |
| `target_max_8bit` | 190 |
| `subtract_min` | ✅ True |
| `clamp_to_target` | ✅ True |
**效果:**
- 输入值 1 将映射到 0
- 输入值 117 将映射到 190
- 中间值线性插值
## 分类
在 ComfyUI 节点树中位于:**Depth/Normalize**
## 许可证
MIT License
+16
View File
@@ -0,0 +1,16 @@
"""
ComfyUI-DepthNormalizer
A ComfyUI custom node for normalizing depth maps to a specific range.
"""
from .nodes.depth_range_manual import DepthRangeTo190Manual
NODE_CLASS_MAPPINGS = {
"DepthRangeTo190Manual": DepthRangeTo190Manual,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DepthRangeTo190Manual": "Depth Range → 0–190 (Manual)",
}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
+3
View File
@@ -0,0 +1,3 @@
from .depth_range_manual import DepthRangeTo190Manual
__all__ = ["DepthRangeTo190Manual"]
+53
View File
@@ -0,0 +1,53 @@
import torch
class DepthRangeTo190Manual:
"""
Manual min/max remap in 8-bit domain (0..255) for depth maps.
Output will be scaled so that max maps to target_max_8bit (default 190).
Optionally subtract min first to force black = 0.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"min_8bit": ("INT", {"default": 0, "min": 0, "max": 255, "step": 1}),
"max_8bit": ("INT", {"default": 190, "min": 0, "max": 255, "step": 1}),
"target_max_8bit": ("INT", {"default": 190, "min": 1, "max": 255, "step": 1}),
"subtract_min": ("BOOLEAN", {"default": True}),
"clamp_to_target": ("BOOLEAN", {"default": True}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "run"
CATEGORY = "Depth/Normalize"
def run(self, image, min_8bit, max_8bit, target_max_8bit, subtract_min, clamp_to_target):
x = image # ComfyUI IMAGE is typically float32 in 0..1
# Convert 0..1 float image to 0..255 domain
x255 = x * 255.0
minv = float(min_8bit)
maxv = float(max_8bit)
target = float(target_max_8bit)
if subtract_min:
denom = max(maxv - minv, 1e-6)
y255 = (x255 - minv) * (target / denom)
else:
denom = max(maxv, 1e-6)
y255 = x255 * (target / denom)
if clamp_to_target:
y255 = torch.clamp(y255, 0.0, target)
else:
y255 = torch.clamp(y255, 0.0, 255.0)
# Back to 0..1 float for ComfyUI
y = y255 / 255.0
return (y,)