'How to build useful color ranges of a certain color without overlapping and missing color expressions in R?
I would like to build useful color ranges of brown color once for several images. But let's start with one image first. To check colors of the image I use the following code (unfortunately I couldn't read in the pic by url, please do it yourself, I've saved it on PC now):
https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg/640px-Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg
#load with url
#image_url <- "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg/640px-Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg"
#pic <- image_read(image_url)
#print(pic)
#load from PC
setwd("~/...")
getwd()
library(magick)
forest.jpg <- image_read("~/... .jpg")
show(forest.jpg)
#check pixel colors first
library(knitr)
image1 <- plotPixels("Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg", lower = NULL, upper = NULL, n = 20000)
#build clusters
kmeans.clusters <- getKMeanColors("Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg", n = 200, plotting = FALSE)
cl <- extractClusters(kmeans.clusters)
plotClusters(cl)
If you turn the quader around and have a birds view, you can see that brown color has an extra line beside green. I would like to set ranges for the whole brown color palette that I have every brown color included, but no overlapping and no missing color point in the image. So later I would like to check about the size of different color ranges in different pictures. For example: Pic no. 1 has more dark brown color than pic no. 2, according to the number of pixel in this range, which are indicated by kmeans.clusters$size.
Later I found out that the code
kmeans.clusters <- getKMeanColors("Hattingen-Blankenstein_Waldpfad_LSG3.2.9.jpg", n = 200, plotting = FALSE)
is only usable for one picture only. Does anyone has an idea how I can rewrite it for lots of pictures in this file? Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
