<jupyter_start><jupyter_text>Color CalibrationContains code to take a sample image with known color targets and find the color correction matrix which best approximates the transformation from observed to theoretical color spaces.<jupyter_code>import numpy as np
import scipy.spatial as space
import scipy.stats as stats
def MeasureColorCorrection(X,Y):
    cov = np.matmul(np.transpose(X), Y)
    U, S, Vt = np.linalg.svd(cov)
    V = np.transpose(Vt)
    Ut = np.transpose(U)
    VUt = np.matmul(V, Ut)
    d = np.linalg.det(VUt)
    print(d)
    CCM = np.matmul(V, np.matmul(np.diag([1,1,d]), Ut))
    return CCM
Observed_Data = np.random.rand(1000,3)
color_correction_matrix = stats.ortho_group.rvs(3)#np.random.rand(3,3)
centroids = np.mean(Observed_Data,0)
Observed_Data = np.subtract(Observed_Data, centroids)
y_perfect = np.matmul(Observed_Data, color_correction_matrix)
y_test = np.add(np.matmul(Observed_Data, color_correction_matrix), 0.01 * np.random.randn(1000,3))
y_test = np.subtract(y_test, np.mean(y_test,0))
ccm = MeasureColorCorrection(Observed_Data, y_test)
print(ccm)
y_ccm = np.matmul(Observed_Data, ccm)
print(y_perfect[0:3,:])
print('\n')
print(y_test[0:3,:])
print('\n')
print(y_ccm[0:3,:])
print(color_correction_matrix)
print(ccm)
cov = np.matmul(np.transpose(X), Y)
U, S, Vt = np.linalg.svd(cov)
V = np.transpose(Vt)
Ut = np.transpose(U)
VUt = np.matmul(V, Ut)
d = np.linalg.det(VUt)
print(d)
np.linalg()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1429548563611491, 'fraction_numerical': 0.017783857729138167, 'mean_word_length': 5.65, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '578197', 'license': 'MIT', 'n_tokens_mistral': 619, 'n_tokens_neox': 608, 'n_words': 117, 'path': 'ColorCalibration/ColorCalibration.ipynb', 'repo_name': 'bnlcas/MicroscopeCamera', 'size': '1462'}