Skip to contents

bilateralFilter applies the bilateral filter to an image. This filter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is very slow compared to most filters.

Usage

bilateralFilter(
  image,
  d = 5,
  sigma_color = 25,
  sigma_space = 25,
  target = "new"
)

Arguments

image

An Image object.

d

The diameter in pixels of the filter neighborhood (default: 5).

sigma_color

The filter standard deviation in the color space (see Note; default: 25).

sigma_space

The filter standard deviation in the coordinate space (see Note; default: 25).

target

The location where the results should be stored. It can take 3 values:

"new":

a new Image object is created and the results are stored inside (the default).

An Image object:

the results are stored in another existing Image object. This is fast and will not replace the content of image but will replace that of target. Note that if target does not have the same dimensions, number of channels, and bit depth as image, an error may be thrown.

Value

If target="new", the function returns an Image object. If target is an Image object, the function returns nothing and modifies that Image object in place.

Note

A larger value of sigma_color means that farther colors within the pixel neighborhood will be mixed together, resulting in larger areas of semi-equal color.

A larger value of sigma_space means that farther pixels will influence each other as long as their colors are close enough. When d > 0, it specifies the neighborhood size regardless of sigma_space. Otherwise, d is proportional to sigma_space.

See also

Author

Simon Garnier, garnier@njit.edu

Examples

balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
rnd <- image(array(sample(0:30, nrow(balloon) * ncol(balloon), replace = TRUE),
                   dim = c(nrow(balloon), ncol(balloon), 3)))
changeBitDepth(rnd, "8U", target = "self")
#> NULL
balloon_noisy <- balloon + rnd
balloon_bilateral <- bilateralFilter(balloon_noisy, 25)