How to calculate RP-177 3×3 matrices in Matlab. Part 2. TRA. Rec709/P3 to Rec2020.

How to calculate RP-177 3×3 matrices in Matlab. Part 2. TRA. Rec709/P3 to Rec2020.

(work in progress)
Matlab code made by Tinna Lif Gunnarsdottir.

Part 1 is here

COLOR REC 2020

        R = [0.708 ; 0.292 ; 0.000];
        G = [0.170 ; 0.797 ; 0.0330];
        B = [0.131 ; 0.046 ; 0.8230];

P = [R G B];

White Point D65

        X = 0.3127;
        Y = 0.3290;
        Z = 0.3583;
        W = [X/Y ; 1 ; Z/Y];


CC = P \ W;

C = [CC(1,1) 0 0 ; 0 CC(2,1) 0 ; 0 0 CC(3,1)];
format long 
NPM = P * C 
NPM_inv = inv(NPM)

NPM =

0.636958048301291   0.144616903586208   0.168880975164172
0.262700212011267   0.677998071518871   0.059301716469862
0                   0.028072693049088   1.060985057710791

NPM_inv =

   1.716651187971268  -0.355670783776393  -0.253366281373660
  -0.666684351832489   1.616481236634939   0.015768545813911
   0.017639857445311  -0.042770613257809   0.942103121235474



From P3 to Rec-2020

% COLOR DCI P3 - D65
        R_P3 = [0.6800   ; 0.3200 ; 0.0000];
        G_P3 = [0.2650  ; 0.6900 ; 0.0450];
        B_P3 = [0.1500  ; 0.0600 ; 0.7900];
        P_P3 = [R_P3 G_P3 B_P3];
        X_P3 = 0.3127;
        Y_P3 = 0.3290;
        Z_P3 = 0.3583;
        W_P3 = [X_P3/Y_P3 ; 1 ; Z_P3/Y_P3];
        CC_P3 = P_P3 \ W_P3;
        C_P3 = [ CC_P3(1,1) 0 0 ;  0  CC_P3(2,1) 0 ;  0    0   CC_P3(3,1)];
        NPM_P3 = P_P3 * C_P3


% TRA
TRA_P3 =  NPM \ NPM_P3

NPM_P3 =

           0.486570948648216   0.265667693169093   0.198217285234362
           0.228974564069749   0.691738521836506   0.079286914093745
                           0   0.045113381858903   1.043944368900976

TRA_P3 =

           0.753833034361722   0.198597369052617   0.047569596585662
           0.045743848965358   0.941777219811693   0.012478931222948
          -0.001210340354518   0.017601717301090   0.983608623053428

COLOR REC 709

        R_7 = [0.640 ;  0.330 ; 0.030];
        G_7 = [0.300 ;  0.600 ; 0.100];
        B_7 = [0.150 ;  0.060 ; 0.790];
        P_7 = [R_7 G_7 B_7];
        % White Point  D65

X_7 = 0.3127;
Y_7 = 0.3290;
Z_7 = 0.3583;
        W_7 = [X_7/Y_7 ; 1 ; Z_7/Y_7];
        CC_7 = P_7 \ W_7;                                              % P inv

 

        C_7 = [ CC_7(1,1) 0 0 ;  0  CC_7(2,1) 0 ;  0    0   CC_7(3,1)];
        NPM_7 = P_7 * C_7
        TRA_7 =  NPM \ NPM_7 % Rec709 as source, NPM/2020 as dest, and inv

NPM_7 =

           0.412390799265959   0.357584339383878   0.180480788401834
           0.212639005871510   0.715168678767756   0.072192315360734
           0.019330818715592   0.119194779794626   0.950532152249661

TRA_7 =

           0.627403895934699   0.329283038377884   0.043313065687417
           0.069097289358232   0.919540395075459   0.011362315566309
           0.016391438875150   0.088013307877226   0.895595253247624

DCI white _ P3

        X_P3_W = 0.314;
        Y_P3_W = 0.351;
        Z_P3_W = 0.335;
        W_P3_W = [X_P3_W/Y_P3_W ; 1 ; Z_P3_W/Y_P3_W];
        CC_P3_W = P_P3 \ W_P3_W;
        C_P3_W = [ CC_P3_W(1,1) 0 0 ;  0  CC_P3_W(2,1) 0 ;  0    0
         CC_P3_W(3,1)];
        NPM_P3_W = P_P3 * C_P3_W
        TRA_P3_W =  NPM \ NPM_P3_W

NPM_P3_W =

           0.445169815564552   0.277134409206778   0.172282669815565
           0.209491677912731   0.721595254161044   0.068913067926226
                           0   0.047060560053981   0.907355394361973

TRA_P3_W =

   0.689691223459987   0.207169204075508   0.041345622770170

   0.041851616632057   0.982426091420886   0.010846196309229
  -0.001107355451221   0.018361440441151   0.854913936657422

Leave a Reply

Your email address will not be published. Required fields are marked *