Learn R Programming

recolorize (version 0.2.0)

blurImage: Blur an image

Description

Blurs an image using the one of five blur functions in imager. Useful for decreasing image noise.

Usage

blurImage(
  img,
  blur_function = c("medianblur", "isoblur", "blur_anisotropic", "boxblur", "boxblur_xy"),
  ...,
  plotting = TRUE
)

Value

An image array of the blurred image.

Arguments

img

An image array, as read in by png::readPNG or readImage.

blur_function

A string matching the name of an imager blur function. One of c("isoblur", "medianblur", "blur_anisotropic", "boxblur", "boxblur_xy").

...

Parameters passed to whichever blur_function is called.

plotting

Logical. Plot the blurred image next to the input for comparison?

Details

The parameters passed with the ... argument are specific to each of the five blur functions; see their documentation for what to specify: imager::isoblur, imager::medianblur, imager::boxblur, imager::blur_anisotropic, imager::boxblur_xy. The medianblur and blur_anisotropic functions are best for preserving edges.

Examples

Run this code

# \donttest{
img_path <- system.file("extdata/fulgidissima.png", package = "recolorize")
img <- readImage(img_path)
median_img <- blurImage(img, "medianblur", n = 5, threshold = 0.5)
anisotropic_img <- blurImage(img, "blur_anisotropic",
                             amplitude = 5, sharpness = 0.1)

# save current graphical parameters:
current_par <- graphics::par(no.readonly = TRUE)
graphics::layout(matrix(1:3, nrow = 1))

plotImageArray(img, "original")
plotImageArray(median_img, "median")
plotImageArray(anisotropic_img, "anisotropic")

# and reset:
graphics::par(current_par)
# }

Run the code above in your browser using DataLab