News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Linear to NonLinear Adaptations Question

Started by guga, January 26, 2019, 03:59:11 AM

Previous topic - Next topic

guga

Hi Guys

I´m a bit confused with the Linear to NonLinear adaptations of Bradford Transformations. Accordlying to http://www.marcelpatek.com/color.html the equation to create a linear or non linear Bradford transformation can be given by this pseudo-code In matlab :( ) :

% bradford.m
% calculates Bradford matrix from source to destination illuminant

Mcat = [0.8951 0.2664 -0.1614;
        -0.7502 1.7135 0.0367;
        0.0389 -0.0685 1.0296];

% destination white (here D50)   
D50 = [96.4220  100.0000   82.5210];

% enter tristimulus of the source white (e.g., monitor)
DXX = [95.105 100.000 108.548];



sxx = Mcat * DXX';  % source cone responses
d = Mcat * D50';    % destination cone responses
tau = (sxx(3)/d(3))^0.0834; % S-cone non-linear correction


diag = [d(1)/sxx(1) 0 0;  % diagonal linear matrix
        0 d(2)/sxx(2) 0;
        0 0 d(3)/sxx(3)];
   
diag_nl = [d(1)/sxx(1) 0 0;
             0 d(2)/sxx(2) 0;
             0 0 (d(3)/sxx(3)^tau)*sxx(3)^(tau-1)]; % non linear coeff in S
   
Mbfd = inv(Mcat) * diag * Mcat;       % "linear" Bradford CAT matrix
Mbfd_nl = inv(Mcat) * diag_nl * Mcat; % "non-linear" Bradford CAT matrix

disp ('Bradford Matrix:'                )
disp (Mbfd)
disp ('Bradford Matrix nonlinear:'                )
disp (Mbfd_nl)


I already suceeded to create a function to do the linear transformation, but i´m a bit confused about the nonlinear. From what i understdood, The only different part on both equations are in the 9th position of a matrix.

From linear we do a simple:
ratio = d(3)/sxx(3)];

replacing d(3) with x and sxx(3) with y, this fraction is simple:
ratio = x/y


But for non linear it is something like this for the same 9th position:
tau = (sxx(3)/d(3))^0.0834
ratio = (d(3)/sxx(3)^tau)*sxx(3)^(tau-1)

Replacing the same to x and y we have
tau = (y/x)^0.0834
ratio = (x/(y^tau)) * y^(tau-1)

Solving the equation on "ratio" we have a simple result as: x/y ????

So...if for nonlinear we use, at the end x/y and for linear we also use the same equation x/y what is the difference between both ??????
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

daydreamer

I see formula uses ^ in the second one(compare x^2 its not linear,its exponential curve)=its curved,the first one is a line(ar),only uses * and /,+,-
it says something about horseshoe shape
very long time I used MATLAB,but doesnt it have some graph drawing capabilities to help you understand it better?
I guess all this research is the reason my windows display settings also offers a nighttime mode,warmer colors make you sleep better it says




my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

guga

#2
Hi DayyDreamer. Oh..now i understood if you post here or in rosAsm subforum.

You can post it here.  :bgrin: :bgrin:

Yes, the non linear uses exponential. But the problem is that, both (non linear and linear) seems to produce the very same result. (Also, the nonlinear example used, will later do a non linear transformation)...But....i did not found the difference on the matlab code. I´m not used to matlab. I had to install it to test some of those monsters :icon_mrgreen: :icon_mrgreen: :icon_mrgreen: But still hard to understand.

From what i saw on the code, the only difference between "diag" and "diag_nl" are in the 3rd line.

diag = (....)
        0 0 d(3)/sxx(3)];



diag_nl = (...)
             0 0 (d(3)/sxx(3)^tau)*sxx(3)^(tau-1)]; % non linear coeff in S


With tau = (sxx(3)/d(3))^0.0834

But if you do the maths for diag_nl you will see that :

(d(3)/sxx(3)^tau)*sxx(3)^(tau-1)]

is, in fact

d(3)/sxx(3)  ---- Which is teh same as in "diag"

This is why i´m confused.

If they produces the same result why make it different ?

I tried to run this code, but matlab is kinda greek for me. I didn´t suceeded to make this function runs to test. :redface: :redface:

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

FORTRANS

Hi,

   Since tau and (tau - 1) cannot be equal, the only way to factor
that out is when sxx(3) is zero or one.  If zero, the formula won't
work.  Is sxx(3) equal to one?

    d(3)
____________ * sxx(3)^(tau-1)
sxx(3)^tau


   As daydreamer says try to plot the function in MatLab or a
spreadsheet.

Regards,

Steve N.

guga

Hi fortrans, yes, but, tau = (sxx(3)/d(3))^0.0834

Tau = (sxx(3)/d(3))^0.0834

    d(3)
____________ * sxx(3)^(tau-1)
sxx(3)^tau

To make easier to understand, I calculated it in wolfram alpha like this

Renamed:

d(3) = x
sxx(3) = y

Which lead us to:


    x
____________ * y^(tau-1)
y^tau

Since, tau = (y/x)^ 0.0834, the equation becomes:
    x
____________________ * y^(((y/x)^ 0.0834)-1)
y^((y/x)^ 0.0834)

Putting that on wolfram alpha results in:

x
__
y

https://www.wolframalpha.com/input/?i=x+%2F+(y%5E((y%2Fx)%5E+0.0834))+*+(y%5E(((y%2Fx)%5E+0.0834)-1))


And..after renaming back from x and y result in:
d(3)/sxx(3)



I suceeded to make it work in matlab, but they produces the very same result. So, why make it different ffrom diag and diag_nl if they are the same ?




Either in Wolfram Alpha and MatLab the result is the same, proofing that both diag and diag_nl are the same thing. That´s why i´m confused...Why displaying diag and diag_nl as different equations if they produces the same result (And, in fact, are the same mathematical equation) ?



Since the exponential is used in the diag_nl matrix, it results in:

   
diag_nl = [d(1)/sxx(1) 0 0;
             0 d(2)/sxx(2) 0;
             0 0 d(3)/sxx(3)]; % non linear coeff in S

That is the same as the linear formula used on diag


diag = [d(1)/sxx(1) 0 0;  % diagonal linear matrix
        0 d(2)/sxx(2) 0;
        0 0 d(3)/sxx(3)];
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

FORTRANS

Hi,

   Yes, I can see it now, sort of.  The taus cancel each other.
X^n divided by X^n is one.  X^(n-1) divided by X^n is just
1 / X .  So you are right, it is the same and it is silly.  Sorry
for the confusion.  Apparently obfuscation is fun for someone.

Regards,

Steve

guga

Tks Steve :)

Don´t worry, the confusion was caused by the article at Marcel Patek site. :icon_mrgreen:  Indeed, some people really like to obfuscate simple things :greensml: :greensml: :greensml:

I was deeply confused about that, specially because i started another function to work with those "nonlinear" equations and stopped after finding that the result was the same. the good thing is that now i can use only one ssingle equation to hold all that stuff related to Color Conversion and Color Adaptation techniques.

I´m currently finishing one function to use on a new RGBtoCieLCH function that uses gamma, white references and also those sort of adaptations. If i suceed we could be able to use one single function to create something around 18000 different types of variations of colorspaces to use  :bgrin: :bgrin: :bgrin:

The main problem i´m facing is with the mathematical equations used to port those kind of things. The papers i´m reading are utterly complex and i have to push from memory those mathematical symbols used on them to understand what it is doing. I still have some issues regarding matrix equations (which are a bit confusing for me) but, i guess, i´m succeeding to create the necessary functions to use.

Eventually i plan to release a library for us at the forum. It may be usefull for someone who wants to create plugins for photoshop, adobe, sony vegas etc etc :)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com