Skip to content

Commit ca0fd50

Browse files
authored
Remove lena (#49)
1 parent 8a15687 commit ca0fd50

File tree

7 files changed

+13952
-581
lines changed

7 files changed

+13952
-581
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ approx = "0.4"
3434
noisy_float = "0.2"
3535
png = "0.16"
3636
ndarray-linalg = { version = "0.14", features = ["intel-mkl"] }
37+
# it is a dependency of intel-mkl-tool, we pin it to temporary solve
38+
# https://github.com/rust-math/intel-mkl-src/issues/68
39+
anyhow = "<1.0.49"

examples/basic.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,32 @@ use ndarray_vision::format::netpbm::*;
44
use ndarray_vision::format::*;
55
use ndarray_vision::processing::*;
66
use std::env::current_exe;
7-
use std::path::PathBuf;
7+
use std::path::{Path, PathBuf};
88

99
fn main() {
10-
if let Ok(mut root) = current_exe() {
11-
root.pop();
12-
root.pop();
13-
root.pop();
14-
root.pop();
15-
let mut lena = PathBuf::from(&root);
16-
lena.push("images/lena.ppm");
10+
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
11+
let mut cameraman = root.clone().join("images/cameraman.ppm");
12+
println!("{:?}", cameraman);
1713

18-
let decoder = PpmDecoder::default();
19-
let image: Image<u8, _> = decoder.decode_file(lena).expect("Couldn't open Lena.ppm");
14+
let decoder = PpmDecoder::default();
15+
let image: Image<u8, _> = decoder
16+
.decode_file(cameraman)
17+
.expect("Couldn't open cameraman.ppm");
2018

21-
let boxkern: Array3<f64> =
22-
BoxLinearFilter::build(Ix3(3, 3, 3)).expect("Was unable to construct filter");
19+
let boxkern: Array3<f64> =
20+
BoxLinearFilter::build(Ix3(3, 3, 3)).expect("Was unable to construct filter");
2321

24-
let mut image: Image<f64, _> = image.into_type();
22+
let mut image: Image<f64, _> = image.into_type();
2523

26-
let _ = image
27-
.conv2d_inplace(boxkern.view())
28-
.expect("Poorly sized kernel");
29-
// There's no u8: From<f64> so I've done this to hack things
24+
let _ = image
25+
.conv2d_inplace(boxkern.view())
26+
.expect("Poorly sized kernel");
27+
// There's no u8: From<f64> so I've done this to hack things
3028

31-
let mut lena = PathBuf::from(&root);
32-
lena.push("images/lenablur.ppm");
29+
let mut cameraman = PathBuf::from(&root);
30+
cameraman.push("images/cameramanblur.ppm");
3331

34-
let ppm = PpmEncoder::new_plaintext_encoder();
35-
ppm.encode_file(&image, lena).expect("Unable to encode ppm");
36-
}
32+
let ppm = PpmEncoder::new_plaintext_encoder();
33+
ppm.encode_file(&image, cameraman)
34+
.expect("Unable to encode ppm");
3735
}

examples/edges.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ fn main() {
2222
root.pop();
2323
root.pop();
2424
root.pop();
25-
let mut lena = PathBuf::from(&root);
26-
lena.push("images/lena.ppm");
25+
let mut cameraman = PathBuf::from(&root);
26+
cameraman.push("images/cameraman.ppm");
2727

2828
let decoder = PpmDecoder::default();
29-
let image: Image<u8, _> = decoder.decode_file(lena).expect("Couldn't open Lena.ppm");
29+
let image: Image<u8, _> = decoder
30+
.decode_file(cameraman)
31+
.expect("Couldn't open cameraman.ppm");
3032

3133
let image: Image<f64, _> = image.into_type();
3234
let image: Image<_, Gray> = image.into();
@@ -36,15 +38,16 @@ fn main() {
3638
let image = image.apply_sobel().expect("Error in sobel");
3739
// back to RGB
3840
let image: Image<_, RGB> = image.into();
39-
let mut lena = PathBuf::from(&root);
40-
lena.push("images/lena-sobel.ppm");
41+
let mut cameraman = PathBuf::from(&root);
42+
cameraman.push("images/cameraman-sobel.ppm");
4143

4244
let ppm = PpmEncoder::new_plaintext_encoder();
43-
ppm.encode_file(&image, lena).expect("Unable to encode ppm");
45+
ppm.encode_file(&image, cameraman)
46+
.expect("Unable to encode ppm");
4447

45-
let mut lena = PathBuf::from(&root);
46-
lena.push("images/lena-canny.ppm");
47-
ppm.encode_file(&canny.into(), lena)
48+
let mut cameraman = PathBuf::from(&root);
49+
cameraman.push("images/cameraman-canny.ppm");
50+
ppm.encode_file(&canny.into(), cameraman)
4851
.expect("Unable to encode ppm");
4952
}
5053
}

examples/transforms.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,39 @@ use std::fs::File;
99
use std::io::BufWriter;
1010
use std::path::{Path, PathBuf};
1111

12-
fn get_lena() -> Option<Image<u8, RGB>> {
12+
fn get_cameraman() -> Option<Image<u8, RGB>> {
1313
if let Ok(mut root) = current_exe() {
1414
root.pop();
1515
root.pop();
1616
root.pop();
1717
root.pop();
18-
let mut lena = PathBuf::from(&root);
19-
lena.push("images/lena.ppm");
18+
let mut cameraman = PathBuf::from(&root);
19+
cameraman.push("images/cameraman.ppm");
2020

2121
let decoder = PpmDecoder::default();
22-
let image: Image<u8, _> = decoder.decode_file(lena).expect("Couldn't open Lena.ppm");
22+
let image: Image<u8, _> = decoder
23+
.decode_file(cameraman)
24+
.expect("Couldn't open cameraman.ppm");
2325
Some(image)
2426
} else {
2527
None
2628
}
2729
}
2830

2931
fn main() {
30-
let lena = get_lena().expect("Couldn't load lena");
32+
let cameraman = get_cameraman().expect("Couldn't load cameraman");
3133

3234
// Create transformation matrix
33-
let x = 0.5 * (lena.cols() as f64) - 0.5;
34-
let y = 0.5 * (lena.rows() as f64) - 0.5;
35+
let x = 0.5 * (cameraman.cols() as f64) - 0.5;
36+
let y = 0.5 * (cameraman.rows() as f64) - 0.5;
3537
let trans = rotate_around_centre(FRAC_PI_4, (x, y)).dot(&scale(0.7, 0.7));
3638

37-
let transformed = lena
39+
let transformed = cameraman
3840
.transform(trans.view(), None)
3941
.expect("Transform failed");
4042

4143
// save
42-
let path = Path::new("transformed_lena.png");
44+
let path = Path::new("transformed_cameraman.png");
4345
let file = File::create(path).expect("Couldn't create output file");
4446
let ref mut w = BufWriter::new(file);
4547

images/cameraman.ppm

+13,906
Large diffs are not rendered by default.

images/lena.ppm

-541
This file was deleted.

images/peppers.png

375 KB
Loading

0 commit comments

Comments
 (0)