Functions to adjust contrast, brightness, colors of the image. Details below.
image_modulate(image, brightness = 100, saturation = 100, hue = 100)
image_quantize(
image,
max = 256,
colorspace = "rgb",
dither = TRUE,
treedepth = NULL
)
image_map(image, map, dither = FALSE)
image_ordered_dither(image, threshold_map)
image_channel(image, channel = "lightness")
image_separate(image, channel = "default")
image_combine(image, colorspace = "sRGB", channel = "default")
image_transparent(image, color, fuzz = 0)
image_background(image, color, flatten = TRUE)
image_colorize(image, opacity, color)
image_contrast(image, sharpen = 1)
image_normalize(image)
image_enhance(image)
image_equalize(image)
image_median(image, radius = 1)
magick image object returned by image_read()
or image_graph()
modulation of brightness as percentage of the current value (100 for no change)
modulation of saturation as percentage of the current value (100 for no change)
modulation of hue is an absolute rotation of -180 degrees to +180 degrees from the current position corresponding to an argument range of 0 to 200 (100 for no change)
preferred number of colors in the image. The actual number of colors in the image may be less than your request, but never more.
string with a colorspace
from colorspace_types for example "gray"
, "rgb"
or "cmyk"
a boolean (defaults to TRUE
) specifying whether to apply Floyd/Steinberg error
diffusion to the image: averages intensities of several neighboring pixels
depth of the quantization color classification tree. Values of 0 or 1 allow selection of the optimal tree depth for the color reduction algorithm. Values between 2 and 8 may be used to manually adjust the tree depth.
reference image to map colors from
A string giving the dithering pattern to use. See the ImageMagick documentation for possible values
a string with a
channel from
channel_types for example "alpha"
or "hue"
or "cyan"
a valid color string such as
"navyblue"
or "#000080"
. Use "none"
for transparency.
relative color distance (value between 0 and 100) to be considered similar in the filling algorithm
should image be flattened before writing? This also replaces transparency with background color.
percentage of opacity used for coloring
enhance intensity differences in image
replace each pixel with the median color in a circular neighborhood
For details see Magick++ STL documentation. Short descriptions:
image_modulate adjusts brightness, saturation and hue of image relative to current.
image_quantize reduces number of unique colors in the image.
image_ordered_dither reduces number of unique colors using a dithering threshold map.
image_map replaces colors of image with the closest color from a reference image.
image_channel extracts a single channel from an image and returns as grayscale.
image_transparent sets pixels approximately matching given color to transparent.
image_background sets background color. When image is flattened, transparent pixels get background color.
image_colorize overlays a solid color frame using specified opacity.
image_contrast enhances intensity differences in image
image_normalize increases contrast by normalizing the pixel values to span the full range of colors
image_enhance tries to minimize noise
image_equalize equalizes using histogram equalization
image_median replaces each pixel with the median color in a circular neighborhood
Note that
colors are also determined by image properties
imagetype and
colorspace
which can be modified via image_convert()
.
# manually adjust colors
logo <- image_read("logo:")
image_modulate(logo, brightness = 200)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_modulate(logo, saturation = 150)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_modulate(logo, hue = 200)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
# Reduce image to 10 different colors using various spaces
image_quantize(logo, max = 10, colorspace = 'gray')
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 Gray FALSE 0 72x72
image_quantize(logo, max = 10, colorspace = 'rgb')
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 RGB FALSE 0 72x72
image_quantize(logo, max = 10, colorspace = 'cmyk')
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 CMYK FALSE 0 72x72
image_ordered_dither(logo, 'o8x8')
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
# Change background color
translogo <- image_transparent(logo, 'white')
image_background(translogo, "pink", flatten = TRUE)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB TRUE 0 72x72
# Compare to flood-fill method:
image_fill(logo, "pink", fuzz = 20)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
# Other color tweaks
image_colorize(logo, 50, "red")
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_contrast(logo)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_normalize(logo)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_enhance(logo)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_equalize(logo)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
image_median(logo)
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 sRGB FALSE 0 72x72
# Alternate way to convert into black-white
image_convert(logo, type = 'grayscale')
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 GIF 640 480 Gray FALSE 0 72x72