feat: complete multichannel (5-7ch) ICC profile generation & verification
- Profile Creation & Inversion (profout.c, xlut.c, mchan_inv.c):
* Unify BtoA CLUT resolutions for devchan >= 5 (9/17/25/33) to provide dense PCS inversion grids
* Guard all reverse simplicial ops in xlut.c with within_restrictedsize() to prevent SIGSEGV when di > 4 (MXRI cap)
* Enhance Powell optimizer in mchan_inv.c with multi-candidate starting strategy and scaled deltaE^2 Lab coordinates
* Allow icSigColorantTableTag in V2 profiles for devchan >= 5 in icc.c
- Numerical & Geometry Stability (scat.c, gamut.c):
* Fix SIGSEGV in rspl scat.c sparse matrix solver caused by assumption of sorted xcol in 4x unrolled loops
* Add null pointer and tag checks in gamut.c radial_point_triang
- Test Targets & Verification (test_multichannel/):
* Add synthetic .ti1 and .ti3 targets for 5-channel (CMYKO), 6-channel (CMYKOG), and 7-channel (CMYKOGV) workflows
* Add ti1_to_ti3 conversion script and verify_roundtrip.py round-trip verification utility
* Verified end-to-end:
- 5-channel: avg dE = 2.38, max dE = 6.27
- 6-channel: avg dE = 1.90, max dE = 5.40
- 7-channel: avg dE = 2.15, max dE = 5.54
- Build & Housekeeping:
* Add .gitignore for compiled executables, autotools outputs, and generated ICC profiles
* Update MULTICHANNEL_IMPLEMENTATION_PLAN.md with verification results
This commit is contained in:
116
Argyll_V3.5.0/test_multichannel/verify_roundtrip.py
Normal file
116
Argyll_V3.5.0/test_multichannel/verify_roundtrip.py
Normal file
@@ -0,0 +1,116 @@
|
||||
import subprocess
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
def get_channel_count(profile):
|
||||
res = subprocess.run(
|
||||
["../icc/iccdump", profile],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
m = re.search(r"Color Space\s+=\s+(\d+)\s+Color", res.stdout)
|
||||
if m:
|
||||
return int(m.group(1))
|
||||
if "Color Space = CMYK" in res.stdout:
|
||||
return 4
|
||||
if "Color Space = RGB" in res.stdout:
|
||||
return 3
|
||||
raise RuntimeError(f"Could not determine channel count from iccdump output")
|
||||
|
||||
def run_forward(profile, device_coords):
|
||||
inp = " ".join(f"{x:.6f}" for x in device_coords) + "\nq\n"
|
||||
res = subprocess.run(
|
||||
["../xicc/xicclu", "-ff", "-ir", profile],
|
||||
input=inp, text=True, capture_output=True, check=True
|
||||
)
|
||||
for line in res.stdout.strip().split("\n"):
|
||||
if "-> Lut ->" in line:
|
||||
parts = line.split("-> Lut ->")[1].strip().split()
|
||||
return [float(parts[0]), float(parts[1]), float(parts[2])]
|
||||
raise RuntimeError(f"Could not parse: {res.stdout}")
|
||||
|
||||
def run_backward(profile, lab_coords):
|
||||
inp = " ".join(f"{x:.6f}" for x in lab_coords) + "\nq\n"
|
||||
res = subprocess.run(
|
||||
["../xicc/xicclu", "-fb", "-ir", profile],
|
||||
input=inp, text=True, capture_output=True, check=True
|
||||
)
|
||||
for line in res.stdout.strip().split("\n"):
|
||||
if "-> Lut ->" in line:
|
||||
parts = line.split("-> Lut ->")[1].strip().split()
|
||||
vals = []
|
||||
for token in parts:
|
||||
try:
|
||||
vals.append(float(token))
|
||||
except ValueError:
|
||||
break
|
||||
return vals
|
||||
raise RuntimeError(f"Could not parse: {res.stdout}")
|
||||
|
||||
def delta_e(lab1, lab2):
|
||||
return math.sqrt(sum((a - b)**2 for a, b in zip(lab1, lab2)))
|
||||
|
||||
def generate_test_cases(nchan):
|
||||
names = ["Cyan", "Magenta", "Yellow", "Black", "Orange", "Green", "Violet"]
|
||||
cases = [
|
||||
("White", [0.0] * nchan)
|
||||
]
|
||||
# Single inks at 50%
|
||||
for i in range(nchan):
|
||||
cname = names[i] if i < len(names) else f"Ink {i+1}"
|
||||
vec = [0.0] * nchan
|
||||
vec[i] = 0.5
|
||||
cases.append((f"{cname} 50%", vec))
|
||||
|
||||
# Mixed CMY
|
||||
vec = [0.0] * nchan
|
||||
vec[0] = 0.2
|
||||
vec[1] = 0.3
|
||||
vec[2] = 0.1
|
||||
cases.append(("Mixed CMY", vec))
|
||||
|
||||
# Extra inks mix
|
||||
if nchan >= 6:
|
||||
vec = [0.0] * nchan
|
||||
vec[4] = 0.2
|
||||
vec[5] = 0.3
|
||||
if nchan >= 7:
|
||||
vec[6] = 0.1
|
||||
cases.append(("Mixed Extra", vec))
|
||||
|
||||
# All-channel mix
|
||||
val = round(0.7 / nchan, 2)
|
||||
cases.append((f"Mixed {nchan}ch", [val] * nchan))
|
||||
|
||||
return cases
|
||||
|
||||
def main():
|
||||
profile = sys.argv[1] if len(sys.argv) > 1 else "test_7clr.icc"
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(script_dir)
|
||||
|
||||
nchan = get_channel_count(profile)
|
||||
test_cases = generate_test_cases(nchan)
|
||||
|
||||
header = f"{'Patch':15} | {'Forward Lab':20} | {'Backward Dev':35} | {'Roundtrip Lab':20} | {'dE':5}"
|
||||
print(f"=== Roundtrip Verification for {profile} ({nchan} Channels) ===")
|
||||
print(header)
|
||||
print("-" * len(header))
|
||||
de_list = []
|
||||
for name, dev in test_cases:
|
||||
fwd_lab = run_forward(profile, dev)
|
||||
bwd_dev = run_backward(profile, fwd_lab)
|
||||
rt_lab = run_forward(profile, bwd_dev)
|
||||
de = delta_e(fwd_lab, rt_lab)
|
||||
de_list.append(de)
|
||||
fwd_str = f"[{fwd_lab[0]:5.1f}, {fwd_lab[1]:5.1f}, {fwd_lab[2]:5.1f}]"
|
||||
rt_str = f"[{rt_lab[0]:5.1f}, {rt_lab[1]:5.1f}, {rt_lab[2]:5.1f}]"
|
||||
bwd_str = " ".join(f"{x:4.2f}" for x in bwd_dev)
|
||||
print(f"{name:15} | {fwd_str:20} | {bwd_str:35} | {rt_str:20} | {de:5.2f}")
|
||||
|
||||
print("-" * len(header))
|
||||
print(f"Summary: avg dE = {sum(de_list)/len(de_list):.2f}, max dE = {max(de_list):.2f}\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user