module

CrImage::Util::Noise

Noise generation and addition for textures and effects.

Provides tools for adding various types of noise to images, useful for:

  • Creating film grain effects
  • Simulating analog photography
  • Adding texture to flat areas
  • Testing image processing algorithms
  • Generating procedural textures

Class methods

add_noise(src : Image, amount : Float64 = 0.1, noise_type : NoiseType = NoiseType::Gaussian, monochrome : Bool = false) : RGBA

Adds noise to an image for film grain or texture effects.

Applies random noise to each pixel based on the specified algorithm. The amount parameter controls intensity, and monochrome determines whether the same noise is applied to all channels or different noise per channel.

Parameters:

  • src : The source image
  • amount : Noise intensity (0.0 = none, 1.0 = maximum, default: 0.1)
  • noise_type : Type of noise algorithm (default: Gaussian)
  • monochrome : Use same noise for all channels (default: false)

Returns: A new RGBA image with noise applied

Raises: ArgumentError if amount is outside 0.0-1.0 range

Example:

img = CrImage.read("photo.jpg")
grainy = img.add_noise(0.1, NoiseType::Gaussian)
Source
generate_noise_texture(width : Int32, height : Int32, noise_type : NoiseType = NoiseType::Gaussian, scale : Float64 = 1.0) : RGBA

Generates a noise texture image.

Creates an image filled entirely with noise pattern. Useful for creating procedural textures, backgrounds, and overlay effects. The scale parameter affects Perlin noise frequency.

Parameters:

  • width : Width of generated image (must be positive)
  • height : Height of generated image (must be positive)
  • noise_type : Type of noise to generate (default: Gaussian)
  • scale : Scale factor for Perlin noise frequency (default: 1.0)

Returns: A new RGBA image filled with noise

Raises: ArgumentError if dimensions or scale are invalid

Example:

noise_texture = CrImage.generate_noise(800, 600, NoiseType::Perlin)
Source