magick (version 2.0)

thresholding: Image thresholding

Description

Thresholding an image can be used for simple and straightforward image segmentation. The function image_threshold() allows to do black and white thresholding whereas image_lat() performs local adaptive thresholding.

Usage

image_threshold(image, type = c("black", "white"), threshold = "50%",
  channel = NULL)

image_lat(image, geometry = "10x10+5%")

Arguments

image

magick image object returned by image_read() or image_graph()

type

type of thresholding, either one of lat, black or white (see details below)

threshold

pixel intensity threshold percentage for black or white thresholding

channel

a value of channel_types() specifying which channel(s) to set

geometry

pixel window plus offset for LAT algorithm

Details

  • image_threshold(type = "black"): Forces all pixels below the threshold into black while leaving all pixels at or above the threshold unchanged

  • image_threshold(type = "white"): Forces all pixels above the threshold into white while leaving all pixels at or below the threshold unchanged

  • image_lat(): Local Adaptive Thresholding. Looks in a box (width x height) around the pixel neighborhood if the pixel value is bigger than the average minus an offset.

Examples

Run this code
# NOT RUN {
test <- image_convert(logo, colorspace = "Gray")
image_threshold(test, type = "black", threshold = "50%")
image_threshold(test, type = "white", threshold = "50%")

# Turn image into BW
test %>%
  image_threshold(type = "white", threshold = "50%") %>%
  image_threshold(type = "black", threshold = "50%")

# adaptive thresholding
image_lat(test, geometry = '10x10+5%')
# }

Run the code above in your browser using DataCamp Workspace