-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
basic.rs
35 lines (27 loc) · 1.05 KB
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use ndarray::{Array3, Ix3};
use ndarray_vision::core::*;
use ndarray_vision::format::netpbm::*;
use ndarray_vision::format::*;
use ndarray_vision::processing::*;
use std::path::{Path, PathBuf};
fn main() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let cameraman = root.clone().join("images/cameraman.ppm");
println!("{:?}", cameraman);
let decoder = PpmDecoder::default();
let image: Image<u8, _> = decoder
.decode_file(cameraman)
.expect("Couldn't open cameraman.ppm");
let boxkern: Array3<f64> =
BoxLinearFilter::build(Ix3(3, 3, 3)).expect("Was unable to construct filter");
let mut image: Image<f64, _> = image.into_type();
image
.conv2d_inplace(boxkern.view())
.expect("Poorly sized kernel");
// There's no u8: From<f64> so I've done this to hack things
let mut cameraman = PathBuf::from(&root);
cameraman.push("images/cameramanblur.ppm");
let ppm = PpmEncoder::new_plaintext_encoder();
ppm.encode_file(&image, cameraman)
.expect("Unable to encode ppm");
}