1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
extern crate ndarray;
use ndarray::*;

pub fn default() -> GrayscaleFilter {
    GrayscaleFilter{}
}

pub struct GrayscaleFilter {}

impl GrayscaleFilter {
    pub fn run (&self, img: Array3<f32>) -> Array2<f32> {
        let target = if img.shape()[2] == 4 {
            img.select(Axis(2), &[0,1,2])
        } else {
            img
        };
        target.mean_axis(Axis(2))
    }
}