模拟PhotoShop的“颜色范围”算法 [英] Emulate PhotoShop's "Color Range" algorithm

查看:165
本文介绍了模拟PhotoShop的“颜色范围”算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用在服务器上完成的自动化过程替换PhotoShop中完成的手动过程。目前在PhotoShop中,颜色范围工具用于根据过程的一部分使用模糊性因子从黑色或白色开始选择一系列颜色。



我的初始方法包括在L * a * b颜色空间中使用发光的阈值,以及候选颜色和黑/白之间的DE94。在这两种情况下,我选择的颜色不应该选择和/或没有选择应该的颜色。



我的预感是,我应该使用锥体而不是球体



任何人都可以深入了解PhotoShop在做什么,以及如果我走向正确的方向?此外,如果有一个库,那里做的这将是真棒我目前写在C。

解决方案

从我在Photoshop中看到的,算法可能类似于下面的:


  1. 定义一个函数来计算两种颜色:例如,在颜色空间中使用欧几里得距离 - 即,使用调整每个像素的强度,例如 http://en.wikipedia.org/wiki/Gaussian_function =nofollow>高斯函数。你可能需要调整
    一些参数。为了说明:你计算RGB空间中两个
    像素的距离(而不是2D像素坐标中的距离),然后将
    输入到falloff函数中,这将提供结果
    在0.0和1.0。将当前
    像素的所有颜色分量与其falloff函数的结果相乘。

  2. 如果要添加效果的范围参数,只需对每个像素使用
    相同的falloff函数,但是这次馈送它
    在像素的2D空间(图像上的像素
    坐标之间的距离)处的所选像素和当前
    像素之间的欧几里得距离。

如果只想选择某些像素,那么不要直接在图像中的像素上应用效果,可以将衰减值存储在矩阵中 double 的范围从0.0到1.0。



例如,如果坐标(x,y)处的像素的步长为2,则产生0.8并且步骤3.产生0.5,则具有坐标x和y的矩阵元素的值应当 0.8 * 0.5 = 0.4 。如果您选择的选择阈值低于0.4,则应选择像素(x,y),否则不会。


I'm trying to replace a manual process done in PhotoShop with an automated process done on the server. Currently in PhotoShop the "Color Range" tool is used to select a range of colors using the "Fuzziness" factor and starting with either Black or White depending on the part of the process.

My initial approaches included both using thresholds for Luminescence in the L*a*b color space as well is DE94 between the candidate color and Black/White. In both cases I selected colors that shouldn't be selected and/or didn't select colors that should.

My hunch is that I should be using cones instead of spheres for my selection.

Can anyone give any insight into what PhotoShop is doing and if I'm heading the right direction? Also, if there is a library out there to do this that would be awesome I'm currently writing this in C.

解决方案

From what I have seen in Photoshop, the algorithm could probably be similar to the following:

  1. Define a function that calculates the closeness of two colors: for example, use a Euclidian distance in the colorspace - that is, calculate the distance between the colors of the two pixels in the RGB space using the Euclidean distance formula.
  2. Next, adjust the intensity of each pixel by using a fallof function, such as the Gaussian function. You will probably need to tweak some parameters. To clarify: you calculate the distance of two pixels in RGB space (not the distance in 2D pixel coordinates), and then feed that into the falloff function which will provide a result between 0.0 and 1.0. Multiply all color components of the current pixel with the result of the falloff function for it. Do this for each pixel of the image.
  3. If you want to add the range parameter of the effect, simply use the same falloff function for each pixel again, but this time feed it the Euclidean distance between the selected pixel and the current pixel in the 2D space of pixels (the distance between pixel coordinates on the image).

If you only want to select certain pixels, then instead of applying the effect directly at the pixels in the image you could store the falloff values in a matrix of doubles in range from 0.0 to 1.0. Then, choose a threshold value above which you will select the given pixel.

For example, if the step 2. for pixel at the coordinate (x, y) yielded 0.8 and the step 3. yielded 0.5, then the value of the matrix element with coordinates x and y should be 0.8*0.5=0.4. If you picked a selection threshold below 0.4, you would select pixel (x, y), otherwise, you would not.

这篇关于模拟PhotoShop的“颜色范围”算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆