palettes {pliman} | R Documentation |
Create image palettes
Description
image_palette()
creates image palettes by applying the k-means algorithm
to the RGB values.
Usage
image_palette(
img,
pattern = NULL,
npal = 5,
proportional = TRUE,
colorspace = c("rgb", "hsb"),
remove_bg = FALSE,
index = "B",
plot = TRUE,
save_image = FALSE,
prefix = "proc_",
dir_original = NULL,
dir_processed = NULL,
return_pal = FALSE,
parallel = FALSE,
workers = NULL,
verbose = TRUE
)
Arguments
img |
An image object. |
pattern |
A pattern of file name used to identify images to be imported.
For example, if |
npal |
The number of color palettes. |
proportional |
Creates a joint palette with proportional size equal to
the number of pixels in the image? Defaults to |
colorspace |
The color space to produce the clusters. Defaults to |
remove_bg |
Remove background from the color palette? Defaults to
|
index |
An image index used to remove the background, passed to
|
plot |
Plot the generated palette? Defaults to |
save_image |
Save the image after processing? The image is saved in the
current working directory named as |
prefix |
The prefix to be included in the processed images. Defaults to
|
dir_original , dir_processed |
The directory containing the original and
processed images. Defaults to |
return_pal |
Return the color palette image? Defaults to |
parallel |
If TRUE processes the images asynchronously (in parallel) in separate R sessions running in the background on the same machine. |
workers |
A positive numeric scalar or a function specifying the number of parallel processes that can be active at the same time. By default, the number of sections is set up to 30% of available cores. |
verbose |
If |
Value
image_palette()
returns a list with two elements:
-
palette_list
A list withnpal
color palettes of classImage
. -
joint
An object of classImage
with the color palettes -
proportions
The proportion of the entire image corresponding to each color in the palette -
rgbs
The average RGB value for each palette
Examples
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
img <- image_pliman("sev_leaf.jpg")
pal <- image_palette(img, npal = 5)
}