OpenCV randn_0
Fill an image with Gaussian noise, OpenCV-style
- dst
- mean
- stddev
- nparray
randn fills an image with Gaussian (normal-distribution) noise. You give it a target array and a mean and standard deviation, and it overwrites every pixel with a sample from that bell curve. In a ComfyUI context that's useful for one main thing: stress-testing denoisers and inpainting. Feed a noisy image into a sampler at low denoise and you're basically benchmarking how well it cleans up; or add controlled noise as a texture source. It's also a classic tool in camera-simulation and augmentation pipelines, though honestly, most image-gen users will touch this rarely - ComfyUI has its own noise path (noise_seed) that does the job with less fuss.
The mechanism is trivial on the OpenCV side: cv2.randn(dst, mean, stddev) writes normally-distributed values into dst in place. The shape and dtype of your dst input define the output - randn doesn't create an array, it fills one you already have.
The awkward part
That in-place design is exactly where this node fights ComfyUI. The three inputs are:
dst- anNPARRAYthat acts as the template: its size and dtype decide the output shape. Pass anything, it gets clobbered with noise.mean- anNPARRAYholding a single scalar (the mean of the distribution).stddev- anNPARRAYholding a single scalar (the standard deviation).
Those scalar arrays are the friction. There's no "scalar" widget here - mean and stddev must be numpy arrays, so you have to source a one-element NPARRAY from somewhere else in the graph (a node that outputs a 1×1 array, say). That's the README's "expect dragons" in action: raw OpenCV semantics, no hand-holding. The output nparray is your noisy image, BGR, ready for Nparrays2Image.
For a quick experiment, wire any image in as dst, use an array-valued mean around (128,) and stddev (30,), and you'll get a visible grain overlay. randn_1 next to it is an identical duplicate - the auto-generator produced two nodes from two indistinguishable overload stubs, so either one works.
Install
Standard for this pack - no models, OpenCV is the only real dependency:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Or search "OpenCV" in ComfyUI Manager, restart, look under image/OpenCV. batch_size==1 only, per the README, and if you hit Cannot import name 'guidedFilter' from 'cv2.ximgproc' you've got conflicting OpenCV packages - known issue, documented fix in the README.
If you just wanted random noise without the nparray scaffolding, consider whether the built-in noise_seed/RandomNoise nodes serve you better. This one is for when you specifically want Gaussian-distributed noise over a fixed canvas, and don't mind wiring a couple of scalars as arrays to get it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| dst | NPARRAY | — | |
| mean | NPARRAY | — | |
| stddev | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |