Mean and variance of luminance in an N×N window plus the covariance between reference and candidate. Returned as f32s.
(
reference: &[[f32; 3]],
candidate: &[[f32; 3]],
width: usize,
x0: usize,
y0: usize,
size: usize,
)
| 190 | /// Mean and variance of luminance in an N×N window plus the |
| 191 | /// covariance between reference and candidate. Returned as f32s. |
| 192 | fn window_luminance_stats( |
| 193 | reference: &[[f32; 3]], |
| 194 | candidate: &[[f32; 3]], |
| 195 | width: usize, |
| 196 | x0: usize, |
| 197 | y0: usize, |
| 198 | size: usize, |
| 199 | ) -> (f32, f32, f32, f32, f32) { |
| 200 | let mut sum_r = 0f32; |
| 201 | let mut sum_c = 0f32; |
| 202 | for yy in 0..size { |
| 203 | for xx in 0..size { |
| 204 | let i = (y0 + yy) * width + (x0 + xx); |
| 205 | sum_r += luminance(reference[i]); |
| 206 | sum_c += luminance(candidate[i]); |
| 207 | } |
| 208 | } |
| 209 | let n = (size * size) as f32; |
| 210 | let mean_r = sum_r / n; |
| 211 | let mean_c = sum_c / n; |
| 212 | |
| 213 | let mut var_r = 0f32; |
| 214 | let mut var_c = 0f32; |
| 215 | let mut cov = 0f32; |
| 216 | for yy in 0..size { |
| 217 | for xx in 0..size { |
| 218 | let i = (y0 + yy) * width + (x0 + xx); |
| 219 | let dr = luminance(reference[i]) - mean_r; |
| 220 | let dc = luminance(candidate[i]) - mean_c; |
| 221 | var_r += dr * dr; |
| 222 | var_c += dc * dc; |
| 223 | cov += dr * dc; |
| 224 | } |
| 225 | } |
| 226 | var_r /= n; |
| 227 | var_c /= n; |
| 228 | cov /= n; |
| 229 | (mean_r, mean_c, var_r, var_c, cov) |
| 230 | } |
| 231 | |
| 232 | // ============================================================ |
| 233 | // Heatmap + composite output |
no test coverage detected