imnoise {SpatialPack}R Documentation

Add noise to image

Description

This function adds noise to an input image.

Usage

imnoise(img, type = "gaussian", mean = 0, sd = 0.01, epsilon = 0.05, var = 0.04,
       looks = 1)

Arguments

img

input grayscale image matrix.

type

character string, specifying the type of contamination: "gaussian" (Gaussian white/additive noise), "saltnpepper" (salt and pepper noise or on-off noise), "speckle" (uniform multiplicative noise) and "gamma" (gamma multiplicative noise).

mean

mean for the Gaussian noise, default value is mean = 0.

sd

standard deviation for the Gaussian noise, default value is sd = 0.01.

epsilon

contamination percentage for the salt and pepper noise with default noise density 0.05. This affects approximately epsilon% of pixels.

var

variance of uniform multiplicative noise using the equation noise = img + unif * img, with unif is uniformly distributed with mean 0 and variance var. Default value is var = 0.04.

looks

parameter of gamma multiplicative noise. The default value is looks = 1.

Value

Noisy image, returned as a numeric matrix. The imnoise function clips output pixel values to the range [0,1] after adding noise.

Examples

  data(texmos2)
  x <- imnoise(texmos2, type = "saltnpepper", epsilon = 0.10)
  plot(as.raster(x))

  y <- imnoise(texmos2, type = "speckle")
  plot(as.raster(y))

  z <- imnoise(texmos2, type = "gamma", looks = 4)
  plot(as.raster(z))

[Package SpatialPack version 0.4 Index]