The goal of ColorAR is to provide a set of functions to compute coloration metrics from images and perform comparative analyses.
You can install the development version of ColorAR like so:
devtools::install_github("agarciaEE/ColorAR")
This is a basic example which shows you some functions:
# load package
library(ColorAR)
# get data
data("imgTransList")
Compute color proportion of an image:
targetColor <- c(255, 165, 0) #orange RGB code
Orange_proportion <- extractColor(imgTransList[[1]], targetColor)
#> Target colour outside colour candidates
#> 3 color candidates...
#> Most proximal candidate colour is:
#> 255 246 255
print(Orange_proportion$P) # print proportion
#> [1] 0.2704314
plot(Orange_proportion$ras) # plot color distribution on the image
Classify image based on target colors:
# define a data frame with the target colors RGB codes.
targetColors = data.frame(red = c(255, 255, 0),
green = c(255, 165, 0),
blue = c(255, 0, 0),
row.names = c("white", "orange", "black"))
imgClass <- classifyColor(imgTransList[[1]], RGB = targetColors, allow.admixture = F, output = "both")
#> Computing colors' offsets...
#> Target colour within colour candidates
#> Target colour outside colour candidates
#> 3 color candidates...
#> Most proximal candidate colour is:
#> 255 246 255
#> Target colour within colour candidates
#> Selected offsets:
#> white orange black
#> 0.3231898 0.3234802 0.3537182
#> Classifying image...
#> Admixture of target colors present...
#> Done
par(mfrow = c(1,2))
plot(imgClass$class) # plot classified image
plotRGB(imgClass$RGB) # plot classified image in RGB format
Perform PCA on images:
## basic example code
imgPCA12 <- imagePCA(imgTransList, PCx = 1, PCy = 2, scale = F, plot.eigen = F, plot.PCA = F,interpolate = 5, plot.names = F, plot.images = F, plot.tree = NULL, type = "RGB" , as.RGB = F)
Plot image PCA along with a tree:
regcols <- setNames(rep(viridis::inferno(5))[as.factor(dataset$region)], dataset$sample)
imagePCA.plot(imgPCA12, tree = tree, plot.tree = "integrated", plot.images = F, colPCA = regcols, coltree = regcols)