OpenCV applyColorMap_2
OpenCV applyColorMap_2
- src
- userColor
- dst
- nparray
Most of the applyColorMap family lets you pick from OpenCV's 23 built-in palettes with an integer. applyColorMap_2 is the third overload, and it's the one that says "no, bring your own." Instead of a colormap integer it takes userColor - an NPARRAY that is your own 256-entry lookup table. Every grayscale level from 0 to 255 maps to the color you put in that table, which means you can build an exact, custom palette and apply it to depth maps, masks, or any grayscale data.
That's genuinely powerful - a brand's colors, a specific scientific colormap, a desaturated film look for your depth preview - and also genuinely fiddly, because nothing in this pack constructs that LUT for you.
How it works
cv2.applyColorMap(src, userColor) treats userColor as the colormap itself: it must be a 256-row array, one entry per gray level, where each row is the BGR color (3 channels) that gray level should become. So the node maps every input pixel's brightness to the corresponding row of your table. Feed it a 256×3 uint8 array and you've replaced the entire built-in palette selection with your own.
The catch is the same "expect dragons" honesty the pack is built on: where does a 256×3 BGR array come from in ComfyUI? Not from Image2Nparray - that gives you a normal image. You'd need a small custom node or a Python-level helper to build the LUT, then hand it to this node. If you have that plumbing, the sky's the limit on palettes. If you don't, the built-in applyColorMap_0/_1 will get you 90% of the way with zero effort.
The inputs that matter
- src (NPARRAY) - the grayscale image to colorize.
- userColor (NPARRAY, required) - your 256-row custom palette, BGR,
uint8. - dst (NPARRAY, optional) - out-parameter; skip it.
Output: one nparray - the image mapped through your palette.
Wiring it up
IMAGE → Image2Nparray → cvtColor (code=6, BGR2GRAY) → applyColorMap_2 → Nparrays2Image, with your custom LUT wired into userColor. Grayscale in is still mandatory - colorizing an RGB image channel-by-channel looks wrong no matter whose palette you use.
Installing opencv-comfyui
ComfyUI Manager → search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Restart ComfyUI. Dependency: opencv-contrib-python.
Gotchas
- LUT must be 256 rows - a wrong-sized
userColorfails; OpenCV expects exactly one color per gray level. - Grayscale source - cvtColor (
code=6) first. - Building the LUT is on you - the pack generates no array-construction helper, so
userColoris the hard part of this node. - Batch_size == 1 - conversion nodes refuse batches; use
ImageFromBatch.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| userColor | NPARRAY | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |