image_palette()
creates image palettes by applying the k-means algorithm
to the RGB values.
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
)
image_palette()
returns a list with two elements:
palette_list
A list with npal
color palettes of class Image
.
joint
An object of class Image
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
An image object.
A pattern of file name used to identify images to be imported.
For example, if pattern = "im"
all images in the current working directory
that the name matches the pattern (e.g., img1.-, image1.-, im2.-) will be
imported as a list. Providing any number as pattern (e.g., pattern = "1"
)
will select images that are named as 1.-, 2.-, and so on. An error will be
returned if the pattern matches any file that is not supported (e.g.,
img1.pdf).
The number of color palettes.
Creates a joint palette with proportional size equal to
the number of pixels in the image? Defaults to TRUE
.
The color space to produce the clusters. Defaults to rgb
.
If hsb
, the color space is first converted from RGB > HSB before k-means
algorithm be applied.
Remove background from the color palette? Defaults to
FALSE
.
An image index used to remove the background, passed to
image_binary()
.
Plot the generated palette? Defaults to TRUE
.
Save the image after processing? The image is saved in the
current working directory named as proc_*
where *
is the image name
given in img
.
The prefix to be included in the processed images. Defaults to
"proc_"
.
The directory containing the original and
processed images. Defaults to NULL
. In this case, the function will search
for the image img
in the current working directory. After processing, when
save_image = TRUE
, the processed image will be also saved in such a
directory. It can be either a full path, e.g., "C:/Desktop/imgs"
, or a
subfolder within the current working directory, e.g., "/imgs"
.
Return the color palette image? Defaults to FALSE
.
If TRUE processes the images asynchronously (in parallel) in separate R sessions running in the background on the same machine.
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.
If TRUE
(default) a summary is shown in the console.
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
img <- image_pliman("sev_leaf.jpg")
pal <- image_palette(img, npal = 5)
}
Run the code above in your browser using DataLab