Added AverageBrightness Feature

This commit is contained in:
SirTalksalot75 2023-06-17 12:06:21 +02:00 committed by GitHub
parent 956894c07e
commit 8c6c27fa55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -79,9 +79,18 @@ impl Database {
}
}
/// example feature implementation
fn average_luminance(image: Image<f32>) -> (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]