classify | R Documentation |
Classify image pixels into discrete colour classes.
classify(
imgdat,
method = c("kMeans", "kMedoids"),
kcols = NULL,
refID = NULL,
interactive = FALSE,
plotnew = FALSE,
col = "red",
...
)
imgdat |
(required) image data. Either a single image, or a series of images
stored in a list. Preferably the result of |
method |
methods for image segmentation/classification.
|
kcols |
the number of discrete colour classes present in the input image(s).
Can be a single integer when only a single image is present, or if kcols is identical for all
images. When passing a list of images, |
refID |
either the numeric index or name of a 'reference' image, for use when passing a list of images. Other images will be k-means classified using centres identified in the single reference image, thus helping to ensure that homologous pattern elements will be reliably classified between images, if so desired. |
interactive |
interactively specify the colour-category 'centers', for k-means clustering.
When |
plotnew |
Should plots be opened in a new window when |
col |
the color of the marker points, when |
... |
additional graphical parameters when |
You can customise the type of parallel processing used by this function with
the future::plan()
function. This works on all operating systems, as well
as high performance computing (HPC) environment. Similarly, you can customise
the way progress is shown with the progressr::handlers()
functions
(progress bar, acoustic feedback, nothing, etc.)
A matrix, or list of matrices, of class rimg
containing the colour
class classifications ID at each pixel location. The RGB values corresponding to
cluster centres (i.e. colour classes) are stored as object attributes.
Since the kmeans
process draws on random numbers to find initial
cluster centres when interactive = FALSE
, use set.seed()
if reproducible
cluster ID's are desired between runs.
Thomas E. White thomas.white026@gmail.com
stats::kmeans
# Single image
papilio <- getimg(system.file("testdata/images/butterflies/papilio.png", package = "pavo"))
papilio_class <- classify(papilio, kcols = 4)
# Multiple images, with interactive classification and a reference image
snakes <- getimg(system.file("testdata/images/snakes", package = "pavo"))
if (interactive()) {
snakes_class <- classify(snakes, refID = "snake_01", interactive = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.