Nodes/comfyui-kpu-utils/KPU Example (Grayscale)
ComfyUI Node

KPU Example (Grayscale)

The Grayscale Node That's Really a Tutorial in Disguise

By kpucha·Created 7 months ago·Updated 7 months ago· 0
KPU Example (Grayscale)
  • image
  • IMAGE

Honestly? The name tells you what this is. KPU Example (Grayscale) is the pack's sample node - the one the author ships to show you how a node is written, before the other five nodes (the prompt builders and the scene generator) do the actual work. But it does one real job too: it takes any image and converts it to grayscale, in a way that won't break the rest of your graph.

Here's the thing that makes it slightly cleverer than a "make it black and white" button: it converts to gray, then replicates the gray value into all three RGB channels instead of returning a single-channel image. That matters in ComfyUI, where a lot of downstream nodes quietly assume three channels. Feed this into a Save Image, an img2img encode, or an upscaler and nothing chokes.

How it works

Under the hood it applies the standard luminance formula - 0.299*R + 0.587*G + 0.114*B - the same weights your TV used. It handles the three image formats ComfyUI actually throws at you: PyTorch tensors (the usual case), numpy arrays, and PIL images. It also prints a couple of lines to the console on every run, like [KPUExampleNode] Input tensor shape: (1, 1024, 1024, 3), which is exactly the kind of logging you'd put in a teaching example.

The inputs and outputs are as minimal as it gets: one required image (type IMAGE), one output IMAGE. There are no settings to fiddle with, no weights to tune. You plug an image in, you get an image out.

When you'd actually use it

Two real uses, neither of them exciting:

  • Monochrome stylization - run a scene through it, save the result, and you've got a moody black-and-white version. Fine for manga-style lineart moods or film-noir vibes.
  • As a template - if you've ever thought about writing your own node, this is the cleanest skeleton in the pack. It's ~120 lines of readable Python that shows input types, return types, and the FUNCTION pattern every ComfyUI node follows.

It's not a power tool and it doesn't pretend to be. There are dozens of dedicated B&W or color-grade nodes with actual controls; this one is the "example" its display name promises.

Installing the pack

The pack is comfyui-kpu-utils by kpucha - a small, Spanish-authored, hobby-scale project with a single commit and basically zero community footprint, so treat it like any unfamiliar pack: glance at the code before you install (I did; it's benign string and image utilities). Two ways in:

cd ComfyUI/custom_nodes
git clone https://github.com/kpucha/comfyui-kpu-utils

Then restart ComfyUI and the node appears under the KPU Utils category. Or use ComfyUI Manager - search for "comfyui-kpu-utils" and hit install. One gotcha: requirements.txt lists a pip package called comfyui, which doesn't exist on PyPI, so an install step will show an error. Ignore it - numpy and Pillow already ship with ComfyUI, and there are no model files to download for this pack.

Gotchas

  • Silent failure. If the node hits an error it catches the exception, prints it to the console, and returns your input image unchanged. So a "broken" run looks like nothing happened - the tell is the [KPUExampleNode] error line in the terminal, not a missing image.
  • Console spam. Every execution logs input and output shapes. Harmless, but if you run a 50-image batch you'll see 100 log lines.
  • No preview mode. It just returns the image; wire it into a preview or Save Image node to actually see the result.

Where people get burned: expecting a true single-channel grayscale (e.g., for a mask or a luminance map) and getting a 3-channel image instead. If you need an actual single-channel mask, use the built-in ImageToMask node. If you just want black-and-white art, this does the job.

CategoryKPU Utils

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE