neutral_balance/
neutral_balance.rs1use kallo_core::{PrintContext, ScanContext};
11use kallo_spectral::{Spectrum, load_csv};
12
13fn read(stem: &str) -> Spectrum {
14 let set = load_csv(format!("data/dyes/{stem}.csv")).expect("dye csv");
15 set.samples[0].reflectance.clone()
16}
17
18fn main() {
19 let placeholder = PrintContext::new([1.2, 1.1, 1.0]);
20 let real = PrintContext::new([1.2, 1.1, 1.0]).with_dyes([
21 read("vision3_500t_cyan"),
22 read("vision3_500t_magenta"),
23 read("vision3_500t_yellow"),
24 ]);
25
26 println!(
27 "{:<10} {:>22} {:>22}",
28 "density", "placeholder gains", "measured gains"
29 );
30 for step in 1..=10 {
31 let density = 0.2 * f64::from(step);
32 let a = placeholder.balance_gain(density);
33 let b = real.balance_gain(density);
34 println!(
35 "{density:<10.1} [{:>6.3} {:>6.3} {:>6.3}] [{:>6.3} {:>6.3} {:>6.3}]",
36 a[0], a[1], a[2], b[0], b[1], b[2]
37 );
38 }
39
40 let full = PrintContext::new([1.2, 1.1, 1.0]).with_spectra(
41 [
42 read("vision3_500t_cyan"),
43 read("vision3_500t_magenta"),
44 read("vision3_500t_yellow"),
45 ],
46 [
47 read("paper_endura_metallic_sensitivity_cyan"),
48 read("paper_endura_metallic_sensitivity_magenta"),
49 read("paper_endura_metallic_sensitivity_yellow"),
50 ],
51 );
52 let masked = PrintContext::new([1.2, 1.1, 1.0])
53 .with_spectra(
54 [
55 read("vision3_500t_cyan"),
56 read("vision3_500t_magenta"),
57 read("vision3_500t_yellow"),
58 ],
59 [
60 read("paper_endura_metallic_sensitivity_cyan"),
61 read("paper_endura_metallic_sensitivity_magenta"),
62 read("paper_endura_metallic_sensitivity_yellow"),
63 ],
64 )
65 .with_base_density(read("vision3_500t_minimum_density"));
66
67 println!();
68 println!("solving the enlarger filter pack on the measured model:");
69 let solved = masked.solve_filters(1.0);
70 println!(
71 " solved {:.0}Y {:.0}M {:.0}C (Kodak CC units)",
72 solved[0], solved[1], solved[2]
73 );
74 let filtered = masked.clone().with_filters(solved);
75 for density in [0.5, 1.0, 1.5, 2.0] {
76 let g = filtered.balance_gain(density);
77 let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
78 - g.iter().copied().fold(f64::INFINITY, f64::min);
79 println!(
80 " D={density:>3.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
81 g[0], g[1], g[2]
82 );
83 }
84
85 println!();
86 println!("measured film dyes + papers + minimum density (the mask):");
87 for step in 1..=10 {
88 let density = 0.2 * f64::from(step);
89 let g = masked.balance_gain(density);
90 let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
91 - g.iter().copied().fold(f64::INFINITY, f64::min);
92 println!(
93 " {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
94 g[0], g[1], g[2]
95 );
96 }
97
98 println!();
99 println!("measured film dyes + measured paper layers:");
100 for step in 1..=10 {
101 let density = 0.2 * f64::from(step);
102 let g = full.balance_gain(density);
103 let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
104 - g.iter().copied().fold(f64::INFINITY, f64::min);
105 println!(
106 " {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
107 g[0], g[1], g[2]
108 );
109 }
110
111 println!();
112 println!("paper dyes in the scan, neutral densities (should be neutral):");
113 let scan = ScanContext::new().with_dyes([
114 read("paper_endura_metallic_cyan"),
115 read("paper_endura_metallic_magenta"),
116 read("paper_endura_metallic_yellow"),
117 ]);
118 for step in 1..=6 {
119 let density = 0.3 * f64::from(step);
120 let rgb = scan.scan([density; 3]);
121 let spread = rgb.iter().copied().fold(f64::NEG_INFINITY, f64::max)
122 - rgb.iter().copied().fold(f64::INFINITY, f64::min);
123 println!(
124 " {density:>4.1}: rgb [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
125 rgb[0], rgb[1], rgb[2]
126 );
127 }
128
129 println!();
130 println!("spread of the gains (1.0 = the balance does nothing):");
131 for step in 1..=10 {
132 let density = 0.2 * f64::from(step);
133 let spread = |g: [f64; 3]| {
134 g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
135 - g.iter().copied().fold(f64::INFINITY, f64::min)
136 };
137 println!(
138 " {density:>4.1}: placeholder {:.3} measured {:.3}",
139 spread(placeholder.balance_gain(density)),
140 spread(real.balance_gain(density))
141 );
142 }
143}