Nodes/ComfyDL/Image Grayscale
ComfyUI Node

Image Grayscale

Grayscale that keeps all three channels — the sneaky part

By Cynthia-lxx·Created 2 months ago·Updated 2 days ago· 6
Image Grayscale
  • image
  • image

CdlImageGrayscale turns a color image gray, and the one thing to know about it is that the output is not a 1-channel image. It converts using rgb_to_grayscale with num_output_channels=3, so you get three channels that all carry the same luminance value. That sounds like a waste of space until you realize it's the feature, not the bug: the output stays a normal IMAGE with [B, H, W, 3] layout, so anything downstream that expects a standard color tensor keeps working without you adding reshape nodes or praying a node accepts a MASK where it wanted an IMAGE.

If you just need a monotone version of an image to feed a classifier or a style pipeline, this is the cleanest way to get it inside ComfyDL. The pack's own image-processing chain example wires this into resize and normalize steps, and it's a natural front-end for the LeNet or ResNet nodes if you want to do the classic Fashion-MNIST trick of feeding grayscale digits.

How it works

The node takes your [B, H, W, C] image, internally permutes it to channel-first, and calls torchvision's TF.rgb_to_grayscale with num_output_channels=3. That computes a standard luminance-weighted average of the RGB channels and copies the result into all three output channels. Because the three channels are identical, the image looks gray even though it's technically still "RGB" to anything inspecting the shape. If you ever feed this into a node that genuinely needs single-channel input, check whether that node wants a MASK (ComfyUI's native single-channel type) - but for the ComfyDL model nodes, 3-channel gray is what the demo workflows use, so you're fine here.

Inputs and output

This is the simplest node in the pack's Image Tools category:

  • image - the only input. Any IMAGE, batched or not.

The single output is image, same height, width, and batch as the input, with the same three channels but grayscale values. Wire it to a preview to confirm, then on to whatever consumes it. There's no brightness or method dropdown - it's deliberately opinionated and boring.

Installing ComfyDL

It's part of the ComfyDL pack, so installing the pack covers you for all of these nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ComfyDL/requirements.txt

Restart ComfyUI afterward. The only extra dependency is matplotlib; torch and torchvision ship with ComfyUI. If you use ComfyUI Manager, try searching "ComfyDL" - and if it's not in the built-in list yet (the pack hasn't published to the official registry, its pyproject.toml has a placeholder publisher ID), use Install via Git URL with https://github.com/Cynthia-lxx/ComfyDL.

Common issues

The main gotcha is expectations: if you were hoping for a true single-channel grayscale image, this node will look "wrong" to you because the tensor still says 3 channels. It isn't broken - that's the design. And since it's just a luminance map, you get the same gray regardless of how colorful the input was; there's no weighting knob to argue with. If your grayscale output looks slightly different from an image editor's, it's because torchvision uses specific (0.299, 0.587, 0.114) luminance weights, which is the standard Rec. 601 formula. Nothing to tune - plug it in and move on.

Categoryimage/color

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
imageIMAGE