doufu8588 2009-08-05 05:44
浏览 381
已采纳

查找颜色范围

I want to find a range of colours from the value of one RGB value

If I was given rgb(0,100,200) for example it would give me everything between rgb(0,0,255) and rgb(0,255,255). However not rgb(255,0,255).

Similarly rgb(150,50,0). Return: rgb(255,0,0) and rgb(255,255,0). Not rgb(255,0,255).

Making sense?

Im using PHP

  • 写回答

2条回答 默认 最新

  • dongyun9120 2009-08-06 14:57
    关注

    The algorithm you explain is basically: "A color consists of two RGB components. Let the strongest RGB component be S and the other component O. Create 255 variations where you let S be (255) and O ranges from 0 to 255."

    E.g. all of the below example yield the same result:

    a) rgb(0,100,200) 
    b) rgb(0,199,200)
    c) rgb(0,254,255)
    d) rgb(0,1,2)
    
    Result: rgb(0,[0-255],255)
    

    This means you only have a 6 variations.

    1. Red is the largest component, Green next largest => rgb(255,[0-255],0)
    2. Red is the largest component, Blue next largest => rgb(255,0,[0-255])
    3. Green is the largest component, Red next largest => rgb([0-255],255,0)
    4. Green is the largest component, Blue next largest => rgb([0-255],0,255)
    5. Blue is the largest component, Red next largest => rgb([0-255],0,255)
    6. Blue is the largest component, Green next largest => rgb(0,[0-255],255)

    The intention of your algorithm is not clear, so I am guessing your use case is actually different from what you explain. It does not handle colors with either 1 or 3 components (most colors actually).

    If your goal is to find similar colors (e.g. a color in a certain distance) there are better approaches. For example you could convert your colors to a HSV color space (Hue, Saturation, Value) and then say that the color is similar if the either of the components H, S or V are +/- 10 steps from your original.

    E.g.:

    rgb(255,100,0) => hsv(24,100,100)

    Your range is then hsv([14-34],[90-110],[90-110])

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图