From 8c6c27fa552b9ec57861ea626307044ed6d95120 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Sat, 17 Jun 2023 12:06:21 +0200 Subject: [PATCH] Added AverageBrightness Feature --- src/Feature/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Feature/mod.rs b/src/Feature/mod.rs index 78c4b0c..de1615f 100644 --- a/src/Feature/mod.rs +++ b/src/Feature/mod.rs @@ -79,9 +79,18 @@ impl Database { } } -/// example feature implementation fn average_luminance(image: Image) -> (String, FeatureResult) { - (String::from("average-brightness"), FeatureResult::F32(0.0)) + let num_pixels = image.pixels.len() as u32; + let total_brightness: f32 = image.pixels + .iter() + .map(|(r, g, b, _)| 0.299 * r + 0.587 * g + 0.114 * b) // Calculate Y for each pixel + .sum(); + let average_brightness = total_brightness / num_pixels as f32; + + let feature_name = String::from("average-brightness"); + let feature_result = FeatureResult::F32(average_brightness); + + (feature_name, feature_result) } #[test]