Created
September 30, 2022 09:42
-
-
Save danoneata/7e9cf4133e6753ecef6c40ad2c980ac4 to your computer and use it in GitHub Desktop.
Colour correction using a color checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This example based on the following tutorial | |
# https://github.com/colour-science/colour-checker-detection/blob/master/colour_checker_detection/examples/examples_detection.ipynb | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import streamlit as st | |
import colour | |
from colour_checker_detection import detect_colour_checkers_segmentation | |
from colour_checker_detection.detection.segmentation import adjust_image | |
def show(img, st): | |
st.image(np.clip(colour.cctf_encoding(img), 0, 1)) | |
def do1(img_name, st): | |
st.markdown("## " + img_name) | |
img = colour.io.read_image(img_name) | |
img = colour.cctf_decoding(img) | |
show(img, st) | |
swatches1, *_ = detect_colour_checkers_segmentation(img) | |
D65 = colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"] | |
CC = colour.CCS_COLOURCHECKERS["cca2014"] | |
swatches_ref = colour.XYZ_to_RGB( | |
colour.xyY_to_XYZ(list(CC.data.values())), | |
CC.illuminant, | |
colour.RGB_COLOURSPACES["sRGB"].whitepoint, | |
colour.RGB_COLOURSPACES["sRGB"].matrix_XYZ_to_RGB, | |
) | |
def plot_vs_ref(swatches): | |
swatches_XYZ = colour.RGB_to_XYZ(swatches, D65, D65, colour.RGB_COLOURSPACES["sRGB"].matrix_RGB_to_XYZ) | |
swatches_xyY = colour.XYZ_to_xyY(swatches_XYZ) | |
cc1 = colour.characterisation.ColourChecker(img_name, dict(zip(CC.data.keys(), swatches_xyY)), D65) | |
fig, _ = colour.plotting.plot_multi_colour_checkers([CC, cc1]) | |
st.pyplot(fig) | |
plot_vs_ref(swatches1) | |
swatches2 = colour.colour_correction(swatches1, swatches1, swatches_ref) | |
plot_vs_ref(swatches2) | |
st.markdown("---") | |
# wget https://doneata.bitbucket.io/static/PXL_20220930_084436202.{dng,jpg} | |
# dcraw -g 2.4 12.92 PXL_20220930_084436202.dng | |
st.set_page_config(layout="wide") | |
cols = st.columns(2) | |
do1("PXL_20220930_084436202.jpg", cols[0]) | |
do1("PXL_20220930_084436202.ppm", cols[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment