# camera_match
`camera_match` is a Python library that provides basic models to match camera colour responses. Using `camera_match`, you can take two cameras with different colour profiles and build a colour pipeline that minimises the difference between them.
Currently, `camera_match` implements the following models:
- Linear Colour Correction Matrix
- Root Polynomial Matrix
- Steve Yedlin's Tetrahedral Matrix
- (Experimental) EMoR Response Curves
- RGB Curve Interpolation
- Radial Basis Functions
## Playground
If you want to use the library without installing anything, I recommend using the Notebook below.
<a href="https://colab.research.google.com/github/ethan-ou/camera-match/blob/main/examples/Camera_Match.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
## Installation
(Recommended) Install the full package with the optional RBF library:
```bash
pip install camera_match[RBF]
```
If you don't need to create LUT's using RBF, you can install the base library:
```bash
pip install camera_match
```
## Examples
### Creating a 3x3 Matrix
A simple matrix that can be used with Resolve's Colour Mixer or any RGB matrix. Can only capture linear changes in colour.
```python
import numpy as np
from camera_match import LinearMatrix
# Import samples of a colour chart for your source camera:
bmpcc_data = np.array([
[0.0460915677249, 0.0414372496307, 0.0392063446343],
[0.0711114183068, 0.0562727414072, 0.0510282665491],
[0.0467581525445, 0.0492189191282, 0.0505541190505]
# ...Additional colour samples
])
# Import corresponding colour patches for your target camera:
film_data = np.array([
[0.0537128634751, 0.0549002364278, 0.0521950721741],
[0.0779063776135, 0.0621158666909, 0.0541097335517],
[0.051306720823, 0.0570512823761, 0.0635398775339]
# ...Additional colour samples
])
# Create a new LinearMatrix:
matrix = LinearMatrix()
# Find the optimum values to match the two cameras:
matrix.solve(bmpcc_data, film_data)
# Plot the result:
matrix.plot()
# Print the matrix:
print(matrix.matrix)
```
### Creating a LUT using RBF
Radial Basis Functions (RBF) allows you to create a LUT that smoothly maps your dataset in 3D. This means you can capture complex colour responses that linear matricies can't capture.
```python
import numpy as np
from camera_match import RBF
# Import samples of a colour chart for your source camera:
bmpcc_data = np.array([
[0.0460915677249, 0.0414372496307, 0.0392063446343],
[0.0711114183068, 0.0562727414072, 0.0510282665491],
[0.0467581525445, 0.0492189191282, 0.0505541190505]
# ...Additional colour samples
])
# Import corresponding colour patches for your target camera:
film_data = np.array([
[0.0537128634751, 0.0549002364278, 0.0521950721741],
[0.0779063776135, 0.0621158666909, 0.0541097335517],
[0.051306720823, 0.0570512823761, 0.0635398775339]
# ...Additional colour samples
])
# Create a new RBF node:
rbf = RBF()
# Find the optimum values to match the two cameras:
rbf.solve(bmpcc_data, film_data)
# Plot the result:
rbf.plot()
# Export as a LUT:
rbf.export_LUT(path="LUT.cube")
```
### Using CST Nodes
Similar to Davinci Resolve, the CST node can be used to transform colour spaces and gammas.
Since this node is just a convenience wrapper around the Colour library, you can use any of the options listed on their docs including [gamma encodings](https://colour.readthedocs.io/en/latest/generated/colour.cctf_decoding.html) and [colour spaces](https://colour.readthedocs.io/en/latest/generated/colour.RGB_COLOURSPACES.html).
```python
# Transform from LogC -> Linear
CST(source_gamma='ARRI LogC3')
# Transform from Linear -> S-Log3
CST(target_gamma="S-Log3")
# Transform from LogC -> SLog3
CST(source_gamma='ARRI LogC3', target_gamma="S-Log3")
# Transform from S-Gamut3.Cine -> Blackmagic Wide Gamut
CST(source_colourspace="S-Gamut3.Cine", target_colourspace="Blackmagic Wide Gamut")
# Combining a gamma and colourspace transform
CST(source_gamma="Blackmagic Film Generation 5", source_colourspace="Blackmagic Wide Gamut", target_gamma='ARRI LogC3', target_colourspace="ARRI Wide Gamut 3")
```
### Building a Pipeline
To create more complex colour pipelines, you can use the Pipeline object to chain multiple nodes together. Here's an example using a LinearMatrix to colour match two digital cameras.
```python
import numpy as np
from camera_match import (
CST,
LinearMatrix,
Pipeline
)
# Import corresponding colour patches for your target camera:
sony_data = np.array([
[0.0537128634751, 0.0549002364278, 0.0521950721741],
[0.0779063776135, 0.0621158666909, 0.0541097335517],
[0.051306720823, 0.0570512823761, 0.0635398775339]
# ...Additional colour samples
])
# Import samples of a colour chart for your source camera:
alexa_data = np.array([
[0.0460915677249, 0.0414372496307, 0.0392063446343],
[0.0711114183068, 0.0562727414072, 0.0510282665491],
[0.0467581525445, 0.0492189191282, 0.0505541190505]
# ...Additional colour samples
])
pipeline = Pipeline([
[CST(source_gamma='ARRI LogC3'), CST(source_gamma="S-Log3")], # Linearises source and target camera data differently.
LinearMatrix()
])
# Find the optimum values to match the two cameras:
pipeline.solve(sony_data, alexa_data)
# Plot the result:
pipeline.plot()
# Get the matrix:
matrix = pipeline.nodes[1]
# Print the matrix:
print(matrix.matrix)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ethan-ou/camera_match",
"name": "camera-match",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "camera_match",
"author": "Ethan Ou",
"author_email": "ethantim@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/30/fc/7f209a5e982e2a0ba78e1061a1917e001e48899f80407b8a2d2ee95bb97d/camera_match-0.0.3.tar.gz",
"platform": null,
"description": "# camera_match\r\n\r\n`camera_match` is a Python library that provides basic models to match camera colour responses. Using `camera_match`, you can take two cameras with different colour profiles and build a colour pipeline that minimises the difference between them.\r\n\r\nCurrently, `camera_match` implements the following models:\r\n\r\n- Linear Colour Correction Matrix\r\n- Root Polynomial Matrix\r\n- Steve Yedlin's Tetrahedral Matrix\r\n- (Experimental) EMoR Response Curves\r\n- RGB Curve Interpolation\r\n- Radial Basis Functions\r\n\r\n## Playground\r\n\r\nIf you want to use the library without installing anything, I recommend using the Notebook below.\r\n\r\n<a href=\"https://colab.research.google.com/github/ethan-ou/camera-match/blob/main/examples/Camera_Match.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\r\n\r\n## Installation\r\n\r\n(Recommended) Install the full package with the optional RBF library:\r\n\r\n```bash\r\npip install camera_match[RBF]\r\n```\r\n\r\nIf you don't need to create LUT's using RBF, you can install the base library:\r\n\r\n```bash\r\npip install camera_match\r\n```\r\n\r\n## Examples\r\n\r\n### Creating a 3x3 Matrix\r\n\r\nA simple matrix that can be used with Resolve's Colour Mixer or any RGB matrix. Can only capture linear changes in colour.\r\n\r\n```python\r\nimport numpy as np\r\nfrom camera_match import LinearMatrix\r\n\r\n# Import samples of a colour chart for your source camera:\r\nbmpcc_data = np.array([\r\n [0.0460915677249, 0.0414372496307, 0.0392063446343],\r\n [0.0711114183068, 0.0562727414072, 0.0510282665491],\r\n [0.0467581525445, 0.0492189191282, 0.0505541190505]\r\n # ...Additional colour samples\r\n])\r\n\r\n# Import corresponding colour patches for your target camera:\r\nfilm_data = np.array([\r\n [0.0537128634751, 0.0549002364278, 0.0521950721741],\r\n [0.0779063776135, 0.0621158666909, 0.0541097335517],\r\n [0.051306720823, 0.0570512823761, 0.0635398775339]\r\n # ...Additional colour samples\r\n])\r\n\r\n# Create a new LinearMatrix:\r\nmatrix = LinearMatrix()\r\n\r\n# Find the optimum values to match the two cameras:\r\nmatrix.solve(bmpcc_data, film_data)\r\n\r\n# Plot the result:\r\nmatrix.plot()\r\n\r\n# Print the matrix:\r\nprint(matrix.matrix)\r\n\r\n```\r\n\r\n### Creating a LUT using RBF\r\n\r\nRadial Basis Functions (RBF) allows you to create a LUT that smoothly maps your dataset in 3D. This means you can capture complex colour responses that linear matricies can't capture.\r\n\r\n```python\r\nimport numpy as np\r\nfrom camera_match import RBF\r\n\r\n# Import samples of a colour chart for your source camera:\r\nbmpcc_data = np.array([\r\n [0.0460915677249, 0.0414372496307, 0.0392063446343],\r\n [0.0711114183068, 0.0562727414072, 0.0510282665491],\r\n [0.0467581525445, 0.0492189191282, 0.0505541190505]\r\n # ...Additional colour samples\r\n])\r\n\r\n# Import corresponding colour patches for your target camera:\r\nfilm_data = np.array([\r\n [0.0537128634751, 0.0549002364278, 0.0521950721741],\r\n [0.0779063776135, 0.0621158666909, 0.0541097335517],\r\n [0.051306720823, 0.0570512823761, 0.0635398775339]\r\n # ...Additional colour samples\r\n])\r\n\r\n# Create a new RBF node:\r\nrbf = RBF()\r\n\r\n# Find the optimum values to match the two cameras:\r\nrbf.solve(bmpcc_data, film_data)\r\n\r\n# Plot the result:\r\nrbf.plot()\r\n\r\n# Export as a LUT:\r\nrbf.export_LUT(path=\"LUT.cube\")\r\n```\r\n\r\n### Using CST Nodes\r\n\r\nSimilar to Davinci Resolve, the CST node can be used to transform colour spaces and gammas.\r\n\r\nSince this node is just a convenience wrapper around the Colour library, you can use any of the options listed on their docs including [gamma encodings](https://colour.readthedocs.io/en/latest/generated/colour.cctf_decoding.html) and [colour spaces](https://colour.readthedocs.io/en/latest/generated/colour.RGB_COLOURSPACES.html).\r\n\r\n```python\r\n# Transform from LogC -> Linear\r\nCST(source_gamma='ARRI LogC3')\r\n\r\n# Transform from Linear -> S-Log3\r\nCST(target_gamma=\"S-Log3\")\r\n\r\n# Transform from LogC -> SLog3\r\nCST(source_gamma='ARRI LogC3', target_gamma=\"S-Log3\")\r\n\r\n# Transform from S-Gamut3.Cine -> Blackmagic Wide Gamut\r\nCST(source_colourspace=\"S-Gamut3.Cine\", target_colourspace=\"Blackmagic Wide Gamut\")\r\n\r\n# Combining a gamma and colourspace transform\r\nCST(source_gamma=\"Blackmagic Film Generation 5\", source_colourspace=\"Blackmagic Wide Gamut\", target_gamma='ARRI LogC3', target_colourspace=\"ARRI Wide Gamut 3\")\r\n```\r\n\r\n### Building a Pipeline\r\n\r\nTo create more complex colour pipelines, you can use the Pipeline object to chain multiple nodes together. Here's an example using a LinearMatrix to colour match two digital cameras.\r\n\r\n```python\r\nimport numpy as np\r\nfrom camera_match import (\r\n CST,\r\n LinearMatrix,\r\n Pipeline\r\n)\r\n\r\n# Import corresponding colour patches for your target camera:\r\nsony_data = np.array([\r\n [0.0537128634751, 0.0549002364278, 0.0521950721741],\r\n [0.0779063776135, 0.0621158666909, 0.0541097335517],\r\n [0.051306720823, 0.0570512823761, 0.0635398775339]\r\n # ...Additional colour samples\r\n])\r\n\r\n# Import samples of a colour chart for your source camera:\r\nalexa_data = np.array([\r\n [0.0460915677249, 0.0414372496307, 0.0392063446343],\r\n [0.0711114183068, 0.0562727414072, 0.0510282665491],\r\n [0.0467581525445, 0.0492189191282, 0.0505541190505]\r\n # ...Additional colour samples\r\n])\r\n\r\npipeline = Pipeline([\r\n [CST(source_gamma='ARRI LogC3'), CST(source_gamma=\"S-Log3\")], # Linearises source and target camera data differently.\r\n LinearMatrix()\r\n])\r\n\r\n# Find the optimum values to match the two cameras:\r\npipeline.solve(sony_data, alexa_data)\r\n\r\n# Plot the result:\r\npipeline.plot()\r\n\r\n# Get the matrix:\r\nmatrix = pipeline.nodes[1]\r\n\r\n# Print the matrix:\r\nprint(matrix.matrix)\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "Match two cameras together using multiple algorithms",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://github.com/ethan-ou/camera_match"
},
"split_keywords": [
"camera_match"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "72527c5ed0ccb58ad11a46640e1362f3b1837ea56da5b600f81e356b56ce24d5",
"md5": "2c9b1b16ddf7944c1407882e0c4d5abb",
"sha256": "7e8ab8b864857f7062baf9f5e628f57aa28f2373f092fe7bac7843140edf071a"
},
"downloads": -1,
"filename": "camera_match-0.0.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "2c9b1b16ddf7944c1407882e0c4d5abb",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.9",
"size": 40237,
"upload_time": "2023-07-28T14:45:47",
"upload_time_iso_8601": "2023-07-28T14:45:47.525665Z",
"url": "https://files.pythonhosted.org/packages/72/52/7c5ed0ccb58ad11a46640e1362f3b1837ea56da5b600f81e356b56ce24d5/camera_match-0.0.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "30fc7f209a5e982e2a0ba78e1061a1917e001e48899f80407b8a2d2ee95bb97d",
"md5": "0316155a69c56242653bf2063dcd823c",
"sha256": "aad348a3a198b9b4a50e07e291401df7e04098883a8317c777ac2223402eb679"
},
"downloads": -1,
"filename": "camera_match-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "0316155a69c56242653bf2063dcd823c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 39957,
"upload_time": "2023-07-28T14:45:50",
"upload_time_iso_8601": "2023-07-28T14:45:50.149950Z",
"url": "https://files.pythonhosted.org/packages/30/fc/7f209a5e982e2a0ba78e1061a1917e001e48899f80407b8a2d2ee95bb97d/camera_match-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-28 14:45:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ethan-ou",
"github_project": "camera_match",
"github_not_found": true,
"lcname": "camera-match"
}