Formula to determine brightness of RGB color

前端 未结 20 3140
猫巷女王i
猫巷女王i 2020-11-21 23:16

I\'m looking for some kind of formula or algorithm to determine the brightness of a color given the RGB values. I know it can\'t be as simple as adding the RGB values toget

20条回答
  •  眼角桃花
    2020-11-21 23:37

    To determine the brightness of a color with R, I convert the RGB system color in HSV system color.

    In my script, I use the HEX system code before for other reason, but you can start also with RGB system code with rgb2hsv {grDevices}. The documentation is here.

    Here is this part of my code:

     sample <- c("#010101", "#303030", "#A6A4A4", "#020202", "#010100")
     hsvc <-rgb2hsv(col2rgb(sample)) # convert HEX to HSV
     value <- as.data.frame(hsvc) # create data.frame
     value <- value[3,] # extract the information of brightness
     order(value) # ordrer the color by brightness
    

提交回复
热议问题