How to calculate RP-177 3×3 matrices in Matlab

How to calculate RP-177 3×3 matrices in Matlab.

Update: For part 2 with the RP-177 TRA matlab code see this post

The Matlab code is made by Tinna Lif Gunnarsdottir.

To make DCPs in DCI-P3 D6O, D61, D65 or Rec 709 D60, D61, D65 you can use SMPTE RP-177:1993 3×3 NPMs to transfer from RGB to XYZ.

NPM = normalized primary matrix

For more info on the math see SMPTE EG 432-1-10 and How to make 3D LUTs in Nuke (R´B´G´to X´Y´Z´)

update:

Here are some 3D LUTS made with these 3×3 matrices

Example: DCI-P3 D6O

Here is the matlab code to calculate the correct RP-177 RGB-XYZ matrices to go from DCI-P3 D6O to XYZ.

Matlab Code

% COLOR DCI P3
R = [0.68   ; 0.320 ; 0];
G = [0.265  ; 0.690 ; 0.045]; 
B = [0.150  ; 0.060 ; 0.79];
P = [R G B];

% White Point D60
X = 0.3217; Y = 0.3378; Z = 0.3405;

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)];

NPM = P * C
NPM =
0.504739646629896 0.264744009223770 0.182855006076470
0.237524539590539 0.689333457978873 0.073142002430588
0                 0.044956529868187 0.963036365336076

Pasted into a Nuke color matrix node:
0.48657095  0.26566769  0.19821729
0.22897457   0.69173852    0.07928691
0                           0.04511338    1.04394437

The middle row sums to 1
0.22897457+0.69173852+0.07928691 = 1

Other transforms


DCI-P3 D61

WHITE POINT
X = 0.3198;
Y = 0.3360;
Z = 0.3442;

NPM from matlab:
0.500852913533834 0.264968867481203  0.185963933270677
0.235695488721804 0.689918937969925  0.0743855733082713
0                                              0.044994713345865  0.979410048558897

Pasted into a Nuke color matrix node:
0.50085291 0.26496887 0.18596393
0.23569549 0.68991894 0.07438557
0                          0.04499471 0.97941005

Middle row sums to 1
0.23569549+0.68991894+0.07438557=1

DCI-P3 DCI-WHITE

WHITE POINT
X = 0.314;
Y = 0.351;
Z = 0.335;

NPM from matlab
0.445169815564552 0.277134409206778   0.172282669815565
0.209491677912731   0.721595254161044    0.068913067926226
0                                              0.047060560053981 0.907355394361973

Pasted into a Nuke color matrix node:
0.44516982 0.27713441     0.17228267
0.20949168 0.72159525    0.06891307
0                         0.04706056   0.90735539

Middle row sums to 1
0.20949168+0.72159525+0.06891307=1

REC 709
REC 709 D65, D60, D61 fits inside DCI-P3 and can be used in DCPs.

REC709 Primaries
R = [0.640 ; 0.330 ; 0.030];
G = [0.300 ; 0.600 ; 0.100];
B = [0.150 ; 0.060 ; 0.790];

REC 709 D65

D65 WHITE POINT
X = 0.3127;
Y = 0.3290;
Z = 0.3583;

NPM from matlab:
0.412390799265959 0.357584339383878 0.180480788401834
0.212639005871510   0.715168678767756   0.072192315360734
0.019330818715592   0.119194779794626   0.950532152249661

Pasted into a Nuke color matrix node:
0.4123908  0.3575843   0.18048079
0.21263901 0.71516867 0.07219232
0.01933082 0.1191948   0.95053215

The middle row should sum to 1 according to RP-177 so I changed 0.71516868 to 0.71516867.


REC 709 D60

D60 WHITE POINT
X = 0.3217;
Y = 0.3378;
Z = 0.3405;

NPM from matlab:
0.431575918832227 0.355727231008106 0.165035512089804
0.222531333147867 0.711454462016212   0.066014204835922
0.020230121195261 0.118575743669369  0.869187030339634

Pasted into a Nuke color matrix node:
0.43157592 0.35572723 0.16503551
0.22253133 0.71145447  0.0660142
0.02023012 0.11857574 0.86918703

Changed 0.71145446 to 0.71145447 so the middle row sums to 1
0.22253133+0.71145447+0.0660142= 1

REC 709 D61

D61 WHITE POINT

X = 0.3198;
Y = 0.3360;
Z = 0.3442;

NPM from matlab:
0.427462229871868 0.356162746222987 0.168160738190859
0.220410212277682  0.712325492445975 0.067264295276343
0.020037292025244 0.118720915407662 0.885646554471856

Pasted into a Nuke color matrix node:
0.42746223 0.35616275 0.16816074
0.22041021  0.71232549 0.0672643
0.02003729 0.11872092 0.88564655
Middle row sums to 1
0.22041021+0.71232549+0.0672643=1

 

Using soX to extract channels and add silence

Add silence
Sometimes audio files are too short and does not match the length of the video files
Instead of making another reel with a silent soundtrack you can add some silence to the audio files using Sox.

To make a 48 khz 24 bit 10 second silent wav file with sox:
sox -n -r 48000 -b24 silent10sec.wav trim 0.0 10.0

To add this to the end of another 48 khz 24 bit sound file with sox:
sox film.LFE.wav silent10sec.wav film2.LFE.wav

 

Extract Channels

Extract channels from interleaved 5.1 sound files
If the file is L, R, C, LFE, LS, RS
sox film51.wav left.wav remix 1
sox film51.wav right.wav remix 2
sox film51.wav center.wav remix 3
sox film51.wav lfe.wav remix 4
sox film51.wav ls.wav remix 5
sox film51.wav rs.wav remix 6

Note: I had trouble with one interleaved audio file when making a DCP in EasyDCP Creator so I started extracting the channels on all interleaved audio files when making DCPs.

Note: You can check the interleaved audio file in Adobe Audition to see if it is L,R,C,LFE,LS,RS

Installation
In Ubuntu Linux you install sox using sudo apt install sox

On Windows you can install sox using Bash on Ubuntu on Windows and install sox with apt install sox or get the binaries from the Sox homepage.

On a Mac you can install sox using homebrew and install sox with brew install sox or get the binaries from the Sox homepage.

Using Ubuntu linux inside Virtualbox on a Mac to format hard drives and do other DCP related stuff

You can run linux inside virtualbox on a mac (and windows).
You can also run Windows inside virtualbox on a mac.

Installing Ubuntu in virtualbox 
Download Ubuntu

Download virtualbox and extensions

Install virtualbox
Click new
Choose Linux, Ubuntu 64 and a name like Ubuntu.

Choose RAM size. I used 2048 MB because it is recommended for Ubuntu 16.04

Choose Hard Disk size. I chose 15 GB and “create virtual hard disk file.”

Choose Hard disk file type. I left it at VDI.

Choose Storage on physical hard disk. I used fixed size because it faster.

Choose Location and size. Ubuntu

Done

Choose Virtualbox – preferences – extensions and install the Virtualbox extensions you downloaded. The extensions enables USB 3.

I upgraded the settings on the Ubuntu virtual machine:

Ubuntu – settings:

ports – USB – USB 3

Video – Memory – 128 MB

System – Processor 2 CPUs (Ubuntu 16.04 minimum requirements)

Choose the ubuntu linux image when you boot it the first time or add is as a cd rom.

You can now start the virtual machine.

Choose install Ubuntu

I used the default settings.

When Ubuntu is installed you can install the linux Guest additions.

Use Virtualbox – Devices – Install Guest Additions. The Guest additions enables adjusting the screen size of the virtual box and other things.

Let the program run.

Choose shutdown

You can set up a Shared folder in virtualbox that will be mounted in linux
Devices – Shared folder – Shared folder settings

Start the virtual machine again

 

Updating Ubuntu

sudo apt update
sudo apt upgrade

You can copy files from EXT2 hard drives to Windows NTFS hard drives. NTFS hard drives can be read on macs.


Using Files/nautilus to access shared folders and copy files to EXT 2 hard drives.

You can start Files/nautilus as root to get read/write access.
in Terminal
sudo nautilus

Formatting a hard drive using Gparted

See this post for more info on gparted/parted/inode 128

run sudo apt install gparted to install gparted

Use Virtualbox – Devices – USB and enable the hard drive.

run gparted

sudo gparted

Click on “Device” – “Create a partition table”
Choose msdos.

Use add partition, add a label and format the drive as EXT2, NTFS, EXT4 or others.

Format the hard drive using mke2fs with inode 128
To format a hard drive as ext2 with 128 inode size, use this command in a terminal on the hard drive you want to format:
sudo mke2fs -t ext2 -I 128 -L DCP123 /dev/sdb1


Setting 755 permissions with chmod

in terminal
sudo chmod 755 -R /media/user/dcp/

Using asdcp tools

Download asdcplib
http://www.cinecert.com/asdcplib/download/

Extract it
Right click and choose extract here

Compile it
start a terminal in the asdcp folder
run these commands
sudo apt install libssl-dev
sudo ./configure
sudo make

Running asdcp-unwrap to extract the wav file from a mxf sound file
You can use asdcp-wrap to make MXFs

Open terminal in the folder where you want your wav file

Run asdcp-unwrap from the asdcp/src directory on the sound mxf file.

/home/user/Downloads/asdcp/src/asdcp-unwrap /media/user/dcp/sound.mxf

You can also drag the asdcp-unwrap file from the File manager to the terminal.
Space.
Then drag the mxf file to terminal.
Enter.

The wav file can be imported in Adobe Audition.

Using Amazon S3 Simple Storage
Install Crossftp Pro to upload to Amazon S3 simple storage

Install java
sudo apt-get install default-jre
sudo apt-get install default-jdk
download portable crossftp and follow the instructions.
or download and install the crossftp linux deb package

change to the Downloads directory in Terminal or right click the directory and choose open terminal here.
open terminal
cd Downloads
sudo dpkg -i ./crossftp_deb_package.deb

Finding base64 sha-1 hash values
(You can also run this command in a terminal on a mac)

in Terminal:
openssl sha1 -binary "FILE_NAME" | openssl base64
source: wikipedia

Running Subtitle Edit in ubuntu.

You can run portable Subtitle Edit in linux. There is a discussion on the sub talk forum on how to run it.

You can run a basic version with video support. To do more advanced work I recommend using Windows. You can run Windows in Virtualbox on a mac.
You need to install mono-complete and Mplayer.
sudo apt install mono-complete
sudo apt install mplayer

If you open a video file in the Files/Nautilus file manager it asks if you want to install codecs.
I also installed these
sudo apt install vlc
sudo apt install mpv

Unzip the Subtitle Edit portable zip file
right click and choose extract here
In Terminal
sudo mono Subtitleedit.exe

 

Using Gnome Commander to copy files and set permissions

Install gnome commander
sudo apt install gnome-commander

run gnome commander
sudo gnome-commander

You can right click files and choose copy, then paste the files somewhere else.

You can right click files and check md5 checksums to check that files are copied correctly.