如何重新创建Photoshop曲线背后的数学

如何重新创建Photoshop曲线背后的数学

本文介绍了如何重新创建Photoshop曲线背后的数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想要做的就是理解如何计算沿着曲线的值,如此处所示的photoshop曲线框中所示: https://i.stack.imgur.com/A4FbI.pngalt =Photoshop曲线>



因此,给定N个点,x在0和1之间而y在0和1之间 - 我们将创建一条穿过所有这些点的曲线。给定这条曲线,我希望能够计算任何给定X的曲线的所有值。换句话说,我想修改任何给定X的值。颜色就像曲线盒一样,但以编程方式。



我读过这些是catmull-rom样条线 - 但我看到的只是一个函数,它依赖于在参数T上 - 我希望能够查找x的值。如果可能的话,我想用C语言来做到这一点

使用 Catmull-Rom样条来解决方案

因为它是一种样条曲线,它表示一条曲线,您可以在其中添加控制点并改进曲线本身(这是您在Photoshop上单击以添加新点时所做的操作),具有使曲线每隔一段时间在任何情况下,你只需要一个函数获取一个值(float在0..1或int在0..255或任何色彩空间你有)将产生另一个。

  float fun(float x){
y = / * something * /
返回y;
}

当然可以使用任何类型的函数来完成。最基本的一个是默认的身份识别功能

  float fun(float x){
y = x ;
return y;

$ / code>

任何其他函数都可以用曲线计算出来,它会好的但是更复杂为了开发,我建议你从简单的例子开始,比如贝塞尔曲线。在任何情况下,都会使用 t 参数,因为它们是参数曲线,所以在深入研究开发之前,您需要了解一些曲线的数学背景,看一看。


Basically, what I want to do is understand how to calculate the values along a 'curve' as represented here in the photoshop curves box:

So, given N points with x between 0 and 1 and y between 0 and 1 - we'll create a curve that passes through all these points. Given this curve, I'd like to be able to calculate all values of the curve for any given X.

In other words, I'd like to modify values of color just like the curves box does, but programmatically.

I've read that these are "catmull-rom splines" -- but all I see is a function that relies upon a parametric T -- I want to be able to look up for values of x. I'd like to do this in C if possible

解决方案

A Catmull-Rom Spline is used because it's a kind of spline that represents a curve in which you can add control points and refine the curve itself (that is what you do on Photoshop when you click to add a new point), with the particularity to have the curve pass by every control point you specify.

In any case you just need a function that taken a value (float in 0..1 or int in 0..255 or whatever color space you have) will produce another one.

float fun(float x) {
  y = /* something */
  return y;
}

This can be done with whatever kind of function of course. The most basic one is the default one that is an identity function

float fun(float x) {
  y = x;
  return y;
}

Any other function can be calculated with curves and it will be ok but more complex to develop, I'd suggest you to start from simple examples like a Bezier curve. In any case the t parameter is used because these are parametric curves, you need to understand some of the mathematical background of curves before digging into development, take a look here.

这篇关于如何重新创建Photoshop曲线背后的数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:35