Skip to content

Commit 65b4a1e

Browse files
committed
Merge branch 'develop'
2 parents 7fd2a95 + d11ae0f commit 65b4a1e

File tree

19 files changed

+1832
-174
lines changed

19 files changed

+1832
-174
lines changed

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "ndarray-vision"
33
version = "0.1.0"
44
authors = ["xd009642 <danielmckenna93@gmail.com>"]
5-
description = "A computer vision library built ontop of ndarray"
5+
description = "A computer vision library built on top of ndarray"
66
repository = "https://github.com/xd009642/ndarray-vision"
77
readme = "README.md"
88
license = "MIT/Apache-2.0"
@@ -12,4 +12,9 @@ edition = "2018"
1212

1313
[dependencies]
1414
ndarray = "0.12"
15+
ndarray-stats = "0.1"
1516
num-traits = "0.2"
17+
18+
[dev-dependencies]
19+
ndarray-rand = "0.9.0"
20+
rand = "0.6.5"

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# ndarray-vision
22

3+
[![Build Status](https://travis-ci.org/xd009642/ndarray-vision.svg?branch=master)](https://travis-ci.org/xd009642/ndarray-vision)
4+
[![License:MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
[![Coverage Status](https://coveralls.io/repos/github/xd009642/ndarray-vision/badge.svg?branch=master)](https://coveralls.io/github/xd009642/ndarray-vision?branch=master)
6+
37
This project is a computer vision library built on top of ndarray. This project
4-
is a work in progress. It is possible to load an image apply filters and save
5-
it back, however it is currently largely non-functional.
8+
is a work in progress. Basic image encoding/decoding and processing are
9+
currently implemented.
10+
11+
See the examples and tests for basic usage.
612

713
# Features
814

9-
* RGB and HSV conversions
10-
* Image convolutions and some filters (box linear, gaussian)
15+
* Conversions between Grayscale, RGB, HSV and CIEXYZ
16+
* Image convolutions and common kernels (box linear, gaussian, laplace)
17+
* Median filtering
18+
* Sobel operator
19+
* Canny Edge Detection
20+
* Histogram Equalisation
1121
* Encoding and decoding PPM (binary or plaintext)

examples/basic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ fn main() {
2323

2424
let mut image: Image<f64, _> = image.into_type();
2525

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

3031
let mut lena = PathBuf::from(&root);
3132
lena.push("images/lenablur.ppm");

examples/edges.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use ndarray_vision::core::*;
2+
use ndarray_vision::format::netpbm::*;
3+
use ndarray_vision::format::*;
4+
use ndarray_vision::processing::*;
5+
use std::env::current_exe;
6+
use std::path::PathBuf;
7+
8+
fn canny_edges(img: &Image<f64, Gray>) -> Image<f64, Gray> {
9+
let x = CannyBuilder::<f64>::new()
10+
.lower_threshold(0.3)
11+
.upper_threshold(0.5)
12+
.blur((5, 5), [0.4, 0.4])
13+
.build();
14+
let res = img.canny_edge_detector(x).expect("Failed to run canny");
15+
16+
Image::from_data(res.data.mapv(|x| if x { 1.0 } else { 0.0 }))
17+
}
18+
19+
fn main() {
20+
if let Ok(mut root) = current_exe() {
21+
root.pop();
22+
root.pop();
23+
root.pop();
24+
root.pop();
25+
let mut lena = PathBuf::from(&root);
26+
lena.push("images/lena.ppm");
27+
28+
let decoder = PpmDecoder::default();
29+
let image: Image<u8, _> = decoder.decode_file(lena).expect("Couldn't open Lena.ppm");
30+
31+
let image: Image<f64, _> = image.into_type();
32+
let image: Image<_, Gray> = image.into();
33+
34+
let canny = canny_edges(&image);
35+
36+
let image = image.apply_sobel().expect("Error in sobel");
37+
// back to RGB
38+
let image: Image<_, RGB> = image.into();
39+
let mut lena = PathBuf::from(&root);
40+
lena.push("images/lena-sobel.ppm");
41+
42+
let ppm = PpmEncoder::new_plaintext_encoder();
43+
ppm.encode_file(&image, lena).expect("Unable to encode ppm");
44+
45+
let mut lena = PathBuf::from(&root);
46+
lena.push("images/lena-canny.ppm");
47+
ppm.encode_file(&canny.into(), lena)
48+
.expect("Unable to encode ppm");
49+
}
50+
}

0 commit comments

Comments
 (0)