本文介绍了色彩混合的插值方法好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题特别解决了在油漆,颜料等颜色混合的情况下曲线拟合的问题.

This question addresses in particular the question of curve fitting in the context of color mixing of paints, pigments, etc.

我试图猜测两种涂料的比例,比如说棕色"(B)和白色"(W),以达到给定的亮度值L.

I am trying to guess the required proportions of two paints, let's say "Brown" (B) and "white" (W) to get to a given lightness value L.

我以一种将比尔-兰伯特定律"应用到化学中的方式制作了校准曲线".但是,曲线不是线性的,所以我不能使用比尔-朗伯定律.

I have made a "calibration curve" in the same fashion as one does so for applying the Beer-lambert law in chemistry. However, the curve is not linear so I cannot use the Beer-Lambert law.

这就是我所做的:

(1)

  • 我已经测量了这些比例的混合物的油漆样品的光谱,标记为a,b,c,d,...等.

  • I have measured the spectrum of paint samples for these proportions of mixture, labeled a, b, c, d, ... etc.

a >>> W = 1,B = 0(纯白色)

a >>> W = 1, B = 0 (pure white)

b >>> W = 63/64,B = 1/64

b >>> W = 63/64, B = 1/64

c >>> W = 31/32,B = 1/32

c >>> W = 31/32, B = 1/32

d >>> W = 15/16,B = 1/16

d >>> W = 15/16, B = 1/16

e >>> W = 7/8,B = 1/8

e >>> W = 7/8, B = 1/8

f >>> W = 3/4,B = 1/4

f >>> W = 3/4, B = 1/4

g >>> W = 1/2,B = 1/2

g >>> W = 1/2, B = 1/2

h >>> W = 0,B = 1(纯棕色)

h >>> W = 0, B = 1 (pure brown)

这些是我得到的光谱反射率曲线:

And these are the spectral reflectance curves that I got :

如果我在给定波长(例如,波长)下获得一个反射率值, 500 nm,我得到了一条漂亮的曲线,其中x轴代表混合物中白色涂料的比例,y轴代表500 nm处的反射光:

If I pick-up one reflectance value at a given wavelength, e.g. 500 nm, I get this nice curve, where the x axis represents the proportion of white paint in the mix, and the y axis the reflected light at 500 nm :

我想通过内插法猜测达到一定数量的反射光需要多少白色.

I'd like to guess by interpolation how much white I need to arrive at a certain amount of reflected light.

(2)

我尝试使用scipy.optimize.curve_fit将指数曲线拟合到数据,但拟合度很差:

I have tried to fit an exponential curve to the data with scipy.optimize.curve_fit but the fit is pretty poor:

什么样的功能可以使数据紧密匹配?

What kind of function would fit the data closely?

推荐答案

由于没有人回答,我将扩展我的评论.

I'll expand my comment since nobody has answered.

根据我在图中看到的,有一个模式.最好的方法是拟合一条适合该图案整体的曲线.您可以使用Eureqa进行任何数学运算(免费试用就足够了): http://www .nu​​tonian.com/products/eureqa/

From what I see in the figure, there is a pattern. The best way would be to fit a curve that fits that pattern as a whole. You can do this without any math using Eureqa (the free trial should be enough): http://www.nutonian.com/products/eureqa/

如果要保留在python中并适合指数分布,可以执行以下操作:如何做指数和对数曲线拟合在Python?我发现只有多项式拟合

If you want to remain in python and fit an exponential distribution, you can do the following:How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting

因此,假设您对于500nm波长具有以下值:

So imagine you have for the wavelength 500nm the following values:

y = [10,20,30,30,50,60,70,80,90,100]
x = [0.,0.3,0.5,0.6,0.72,0.77,0.84,0.9,0.95,1]

然后,拟合指数曲线的代码将是:

Then the code to fit the exponential curve would be:

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def func(x, a, b, c):
    return a * np.exp(-b * x) + c

popt, pcov = curve_fit(func, x, y)

在这种情况下,我们得出a,b和c为:

In this case we get that a,b, and c are:

popt = array([ 7.1907744 , -2.62804994,  2.45029842])

因此,要获取特定x处的反射光值(例如0.2),可以执行以下操作:

So to get the value of reflected light at a certain x (for instance 0.2), you can do:

func(0.2, 7.1907744 , -2.62804994,  2.45029842)

哪个是14.61

但是您说这很不合适,如果不需要模型,可以执行以下操作:如果您不太在意模型,则可以使用以下方法: https://docs.scipy.org/doc/scipy/reference/Generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d

But you say it's a bad fit, if you don't need a model, you can do the following: If you don't really care about having a model you can use this: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d

from scipy import interpolate
f = interpolate.interp1d(x, y, kind="quadratic") #you can try different kinds of interpolation

然后找到一个值(例如x = 0.2):

And then to find a value (for instance x=0.2):

ynew = f(0.2)

哪个是6.549

或者具有许多值,以便您可以绘制它们: ynew = f(np.linspace(0,1,1000)

Or to have many values so you can plot them: ynew = f(np.linspace(0,1,1000)

这篇关于色彩混合的插值方法好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 11:47