Added AverageBrightness Feature
This commit is contained in:
parent
956894c07e
commit
8c6c27fa55
|
@ -79,9 +79,18 @@ impl Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// example feature implementation
|
|
||||||
fn average_luminance(image: Image<f32>) -> (String, FeatureResult) {
|
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]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue