如何计算色彩滤镜的RGB值

节选自Duke在Coursera上的公开课:程序设计与Web入门。

How to make a filter in any color

The values in the table were determined by plotting a piecewise linear function for each of the R, G, and B values vs. the average value. To keep black pixels black and white pixels white, the desired functions are pinned at (0,0) and (255,255). The third point (where the function changes slope) is determined by plotting the R, G, or B value of the desired color vs. 127.5.

Consider any color any color with R value = Rc, G value = Gc, and B value = Bc. The filtered pixel has R value:

R = Rc/127.5*avg                      for avg < 128
R = (2 - Rc/127.5)*avg + 2*Rc - 255   for avg >=128
复制代码

Similarly for G and B, where you would substitute Gc or Bc for Rc in the above formula.

To apply this formula and create a colored filter of your choice, use a color picker tool to determine the RGB content of any color you would like to use, such as teal (17,170,153).

Since for teal, Rc = 17, Gc = 170, Bc = 153, so

R = 17/127.5*avg                          = 0.13*avg        for avg < 128
R = (2 - 17/127.5)*avg + 2*17 - 255	  = 1.87*avg - 221  for avg >=128

G = 170/127.5*avg                       = 1.33*avg        for avg < 128
G = (2 - 170/127.5)*avg + 2*170 - 255	= 0.67*avg + 85   for avg >=128

B = 153/127.5*avg                       = 1.2*avg         for avg < 128
B = (2 - 153/127.5)*avg + 2*153 - 255	= 0.8*avg + 51    for avg >=128
复制代码

Now you can use this formula to make a filter in any color!

转载于:https://juejin.im/post/5c89eb695188257ec355ec11

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值