Skip to content
Plugins (183)

diffusion

stable

Image processing primitives for diffusion model pipelines, including noise generation, blending, masking, denoising steps, and noise schedulers.

use plugin diffusion::{generate_noise_rgba, generate_noise_grayscale, blend_images, …}
13 functions AI & ML
Runs with the native Zolo host

Plugin snippets can be edited in the Playground, but native capabilities are executed locally with the Zolo CLI.

/ filter jk navigate Esc clear
Functions (13)
  1. generate_noise_rgba Generates RGBA noise bytes from a seed
  2. generate_noise_grayscale Generates grayscale noise bytes from a seed
  3. blend_images Alpha-blends two byte images
  4. lerp_images Linearly interpolates two byte images
  5. apply_mask Applies a grayscale mask to an RGBA image
  6. add_noise Adds noise to an image at a given strength
  7. denoise_step Performs one DDPM denoising step
  8. scheduler_linear Generates a linear beta noise schedule
  9. scheduler_cosine Generates a cosine beta noise schedule
  10. scheduler_quadratic Generates a quadratic beta noise schedule
  11. image_stats Computes mean, min, max, std_dev of image bytes
  12. threshold Binarizes image bytes at a threshold
  13. invert Inverts all bytes in an image

From import to result

  1. 01Import only what you use
  2. 02Copy the smallest example
  3. 03Run it with the Zolo CLI

Overview

The diffusion plugin provides the byte-level image primitives that underpin a diffusion model pipeline: deterministic noise generation, image blending and interpolation, masking, single-step denoising, and the beta schedulers (linear, cosine, quadratic) that control how much noise is added or removed at each step. Images are represented as raw byte buffers (bytes) — typically RGBA where each pixel is four bytes, or grayscale where each pixel is one byte — and every operation works directly on those buffers, so no external image library is required. Noise is produced by a seeded xorshift64 PRNG, which means the same seed always yields the same buffer; reach for this plugin when you want to prototype or run a forward/reverse diffusion loop end to end in Zolo.

Common patterns

Build a forward (noising) step: start from a latent, generate matching noise, and mix it in at a chosen strength.

use plugin diffusion::{generate_noise_rgba, add_noise, image_stats}

let latent = generate_noise_rgba(64, 64, 1)
let noise = generate_noise_rgba(64, 64, 2)
let noisy = add_noise(latent, noise, 0.4)

let stats = image_stats(noisy)
print("mean: {stats["mean"]}, std_dev: {stats["std_dev"]}")

Run a reverse (denoising) loop driven by a scheduler: walk the beta schedule and apply one denoise_step per entry.

use plugin diffusion::{generate_noise_rgba, scheduler_linear, denoise_step}

let betas = scheduler_linear(20, 0.0001, 0.02)
let predicted = generate_noise_rgba(64, 64, 99)
let mut sample = generate_noise_rgba(64, 64, 7)

for beta in betas {
  sample = denoise_step(sample, predicted, beta)
}
print("denoised {sample.len} bytes")

Turn a grayscale buffer into a binary mask and apply it to an RGBA image.

use plugin diffusion::{generate_noise_rgba, generate_noise_grayscale, threshold, apply_mask}

let img = generate_noise_rgba(32, 32, 4)
let gray = generate_noise_grayscale(32, 32, 5)
let mask = threshold(gray, 128)
let masked = apply_mask(img, mask, 32, 32)
print("masked {masked.len} bytes")

Generates RGBA noise bytes from a seed

Generates a buffer of random RGBA noise (width * height * 4 bytes) using a deterministic xorshift64 PRNG seeded with seed. Use as the starting latent for a diffusion pipeline.

use plugin diffusion::{generate_noise_rgba}

let noise = generate_noise_rgba(64, 64, 12345)
print("bytes: {noise.len}")  // 16384

Because the PRNG is fully deterministic, the same seed reproduces the exact same buffer — useful for reproducible runs and tests.

use plugin diffusion::{generate_noise_rgba, image_stats}

let a = generate_noise_rgba(16, 16, 777)
let b = generate_noise_rgba(16, 16, 777)
print("identical: {image_stats(a)["mean"] == image_stats(b)["mean"]}")

Generates grayscale noise bytes from a seed

Generates a grayscale noise buffer (width * height bytes) with the same deterministic PRNG. Useful as a mask or single-channel latent.

use plugin diffusion::{generate_noise_grayscale}

let mask = generate_noise_grayscale(64, 64, 42)

Alpha-blends two byte images

Alpha-blends two RGBA byte buffers of the same size. alpha (0.0–1.0) controls the weight of img2: 0.0 returns img1, 1.0 returns img2.

use plugin diffusion::{generate_noise_rgba, blend_images}

let a = generate_noise_rgba(32, 32, 1)
let b = generate_noise_rgba(32, 32, 2)
let blended = blend_images(a, b, 32, 32, 0.5)

Pass alpha = 0.0 to recover img1 unchanged, or 1.0 to get img2; values in between cross-fade the two buffers.

use plugin diffusion::{generate_noise_rgba, blend_images, image_stats}

let a = generate_noise_rgba(32, 32, 1)
let b = generate_noise_rgba(32, 32, 2)
let quarter = blend_images(a, b, 32, 32, 0.25)
print("mean: {image_stats(quarter)["mean"]}")

Linearly interpolates two byte images

Linearly interpolates between two byte images. Equivalent to blend_images but named to reflect its use in latent-space interpolation where t is the interpolation parameter.

use plugin diffusion::{generate_noise_rgba, lerp_images}

let start = generate_noise_rgba(32, 32, 10)
let end = generate_noise_rgba(32, 32, 20)
let mid = lerp_images(start, end, 32, 32, 0.5)

Applies a grayscale mask to an RGBA image

Multiplies each pixel's RGB channels by the corresponding mask value (0–255 normalized to 0.0–1.0). The alpha channel is unchanged. mask can be grayscale (w*h bytes) or RGBA (w*h*4 bytes, using the R channel).

use plugin diffusion::{generate_noise_rgba, generate_noise_grayscale, apply_mask}

let img = generate_noise_rgba(32, 32, 1)
let mask = generate_noise_grayscale(32, 32, 99)
let masked = apply_mask(img, mask, 32, 32)

Adds noise to an image at a given strength

Blends noise into an image at the given strength (0.0–1.0). Used to add controlled noise during the forward diffusion process.

use plugin diffusion::{generate_noise_rgba, add_noise}

let img = generate_noise_rgba(32, 32, 0)
let noise = generate_noise_rgba(32, 32, 7)
let noisy = add_noise(img, noise, 0.3)

Performs one DDPM denoising step

Performs one step of DDPM-style denoising: subtracts the predicted noise scaled by beta and normalizes by sqrt(1 - beta). Use this iteratively with a noise scheduler.

use plugin diffusion::{generate_noise_rgba, denoise_step, scheduler_linear}

let noisy = generate_noise_rgba(32, 32, 1)
let predicted = generate_noise_rgba(32, 32, 2)
let betas = scheduler_linear(10, 0.0001, 0.02)
let step0 = denoise_step(noisy, predicted, betas[1])

Apply it repeatedly to walk down a full schedule, feeding each result back in.

use plugin diffusion::{generate_noise_rgba, scheduler_cosine, denoise_step}

let betas = scheduler_cosine(8)
let predicted = generate_noise_rgba(32, 32, 5)
let mut sample = generate_noise_rgba(32, 32, 6)
for beta in betas {
  sample = denoise_step(sample, predicted, beta)
}
print("done: {sample.len} bytes")

Generates a linear beta noise schedule

Returns a table of num_steps beta values evenly spaced between beta_start and beta_end. This is the standard linear DDPM schedule.

use plugin diffusion::{scheduler_linear}

let betas = scheduler_linear(1000, 0.0001, 0.02)
print(betas[1])     // ~0.0001
print(betas[1000])  // ~0.02

Use a small step count when prototyping a loop, then scale up for the real run.

use plugin diffusion::{scheduler_linear}

let betas = scheduler_linear(5, 0.0001, 0.02)
for beta in betas {
  print("beta: {beta}")
}

Generates a cosine beta noise schedule

Returns a table of num_steps beta values following the cosine schedule (Nichol & Dhariwal 2021), which produces smoother noise levels than the linear schedule.

use plugin diffusion::{scheduler_cosine}

let betas = scheduler_cosine(1000)
print(betas[1])

Generates a quadratic beta noise schedule

Returns a table of num_steps beta values following a quadratic schedule (interpolated in sqrt-space), giving more steps at low noise levels.

use plugin diffusion::{scheduler_quadratic}

let betas = scheduler_quadratic(1000, 0.0001, 0.02)

Computes mean, min, max, std_dev of image bytes

Computes statistics over all bytes in an image buffer. Returns a table with mean, min, max, std_dev, and byte_count.

use plugin diffusion::{generate_noise_rgba, image_stats}

let img = generate_noise_rgba(64, 64, 1)
let stats = image_stats(img)
print("mean: {stats["mean"]}")
print("std_dev: {stats["std_dev"]}")

Inspect the full range of a buffer, including the byte count, to sanity-check a pipeline stage.

use plugin diffusion::{generate_noise_grayscale, image_stats}

let gray = generate_noise_grayscale(48, 48, 11)
let stats = image_stats(gray)
print("min: {stats["min"]}, max: {stats["max"]}, count: {stats["byte_count"]}")

Binarizes image bytes at a threshold

Binarizes every byte in the image: bytes >= threshold become 255, bytes below become 0. Useful for creating binary masks from grayscale images.

use plugin diffusion::{generate_noise_grayscale, threshold}

let gray = generate_noise_grayscale(32, 32, 5)
let binary = threshold(gray, 128)

Inverts all bytes in an image

Inverts all bytes in the image buffer (255 - x for each byte). Works on RGBA, grayscale, or any raw byte buffer.

use plugin diffusion::{generate_noise_rgba, invert}

let img = generate_noise_rgba(32, 32, 3)
let inv = invert(img)

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

en