skinoptics.utils module

SkinOptics
Copyright (C) 2024 Victor Lima
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Victor Lima
victorporto@ifsc.usp.br
victor.lima@ufscar.br
Release Date:
October 2024
Last Modification:
October 2024
References:
[WSS13] Wyman, Sloan & Shirley 2013.
Simple Analytic Approximations to the CIE XYZ Color Matching Functions
skinoptics.utils.biexp_decay(x, a, b, c, d, e)

The biexponential decay function.

\(f(x) = a\mbox{ exp}(-|b|x) + c \mbox{ exp}(-|d|x) + e\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

  • d (float) – function constant

  • e (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated biexponential decay function

skinoptics.utils.circle(r, xc, yc, theta_i=0.0, theta_f=360.0, n_points=1000)

The points that compose a circle.

\(\left \{ \begin{matrix} x = r \cos \theta + x_c\\ y = r \sin \theta + y_c \end{matrix} \right.\)

Parameters:
  • r (float) – radius

  • xc (float) – center x-coordinate

  • yc (float) – center y-coordinate

  • theta_i (float) – initial angle [degrees] (default to 0.)

  • theta_f (float) – final angle [degrees] (default to 360.)

  • n_points (int) – number of points (default to 1000)

Returns:

  • x (np.ndarray) – x-coordinantes of a circle

  • y (np.ndarray) – y-coordinantes of a circle

skinoptics.utils.cubic(x, a, b, c, d)

The cubic function.

\(f(x) = ax^3 + bx^2 + cx + d\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

  • d (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated cubic function

skinoptics.utils.dict_from_arrays(array_keys, array_values)

Construct a dictionary from two arrays.

Parameters:
  • array_keys (np.ndarray) – array with the dictionary keys

  • array_values (np.ndarray) – array with the dictionary values

Returns:

  • dict (dictionary) – dictionary constructed with the two arrays

skinoptics.utils.exp_decay(x, a, b, c)

The exponential decay function.

\(f(x) = a \mbox{ exp}(-|b|x) + c\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated exponential decay function

skinoptics.utils.exp_decay_inc_form(x, a, b, c)

The increasing form of the exponential decay function.

\(f(x) = a \mbox{ [}1 - \mbox{exp}(-|b|x)] + c\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated exponential decay (increasing form) function

skinoptics.utils.gaussian(x, a, b, c)

The Gaussian function.

\(f(x) = a \mbox{ exp}\left[-\frac{1}{2}\frac{(x - b)^2}{c^2}\right]\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated Gaussian function

skinoptics.utils.heaviside(x)

The Heaviside step function.

\(H(x) = \left \{ \begin{matrix} 0, & \mbox{if } g < 0 \\ \frac{1}{2}, & \mbox{if } g = 0 \\ 1, & \mbox{if } g > 0 \\ \end{matrix} \right.\)

Parameters:

x (float or np.ndarray) – function variable

Returns:

  • H (float or np.ndarray) – evaluated Heaviside step function

skinoptics.utils.hyperbolic_cossine(x, a, b, c, d)

The hyperbolic cossine function (with four parameters).

\(f(x) = a \mbox{ cosh}\left[\frac{(x - b)}{c}\right] + d\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

  • d (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated hyperbolic cossine function

skinoptics.utils.linear(x, a, b)

The linear function.

\(f(x) = ax + b\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – slope

  • b (float) – y-intercept

Returns:

  • f (float or np.ndarray) – evaluated linear function

skinoptics.utils.mod_gaussian_Wyman(x, a, b, c, d)
The modified Gaussian function needed to calculate some analytical functions
from Wyman, Sloan & Shirley 2013 [WSS13] (see function skinoptics.colors.cmfs()).

\(f(x) = a \mbox{ exp}\left\{-d \mbox{ } \left[\mbox{ ln}\left(\frac{x - b}{c}\right)\right]^2\right\}\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

  • d (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated function

skinoptics.utils.natural_log(x, a, b, c)

The natural logarithm function.

\(f(x) = a \mbox{ ln}(x + b) + c\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated natural logarithm function

skinoptics.utils.piecewise_gaussian_Wyman(x, a, b, c, d)
The piecewise Gaussian function needed to calculate some analytical functions
from Wyman, Sloan & Shirley 2013 [WSS13] (see function skinoptics.colors.cmfs()).

\(f(x) = a \mbox{ exp}\left\{-\frac{1}{2}[(x - b)\mbox{ }S(x - b \mbox{, }c \mbox{, }d)]^2\right\}\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

  • d (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated function

skinoptics.utils.quadratic(x, a, b, c)

The quadratic function.

\(f(x) = ax^2 + bx + c\)

Parameters:
  • x (float or np.ndarray) – function variable

  • a (float) – function constant

  • b (float) – function constant

  • c (float) – function constant

Returns:

  • f (float or np.ndarray) – evaluated quadratic function

skinoptics.utils.selector_function_Wyman(x, y, z)
The selector function needed to calculate some analytical functions
from Wyman, Sloan & Shirley 2013 [WSS13] (see function skinoptics.colors.cmfs()).

\(S(x,y,z) = y \mbox{ } (1 - H(x)) + z \mbox{ } H(x)\)

in which \(H(x)\) is the Heaviside step function skinoptics.utils.heaviside().

Parameters:
  • x (float or np.ndarray) – function variable

  • y (float or np.ndarray) – function variable

  • z (float or np.ndarray) – function variable

Returns:

  • S (float or np.ndarray) – evaluated selector function