Skip to content

Commit 766346c

Browse files
committed
Run Cargo fmt
1 parent a6beac2 commit 766346c

File tree

10 files changed

+45
-71
lines changed

10 files changed

+45
-71
lines changed

src/core/colour_models.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ pub struct HSI;
2626
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
2727
pub struct HSL;
2828
/// YCrCb represents an image as luma, red-difference chroma and blue-difference
29-
/// chroma.
29+
/// chroma.
3030
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
3131
pub struct YCrCb;
3232
/// CIE XYZ standard - assuming a D50 reference white
3333
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
3434
pub struct CIEXYZ;
3535
/// CIE LAB (also known as CIE L*a*b* or Lab) a colour model that represents
3636
/// colour as lightness, and a* and b* as the green-red and blue-yellow colour
37-
/// differences respectively. It is designed to be representative of human
37+
/// differences respectively. It is designed to be representative of human
3838
/// perception of colour
3939
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
4040
pub struct CIELAB;
@@ -917,5 +917,4 @@ mod tests {
917917
assert_eq!(large.data.slice(s![.., .., i]), zeros);
918918
}
919919
}
920-
921920
}

src/core/image.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515
/// Images are always going to be 3D to handle rows, columns and colour
1616
/// channels
1717
///
18-
/// This should allow for max compatibility with maths ops in ndarray.
18+
/// This should allow for max compatibility with maths ops in ndarray.
1919
/// Caution should be taken if performing any operations that change the
2020
/// number of channels in an image as this may cause other functionality to
2121
/// perform incorrectly. Use conversions to one of the `Generic` colour models
@@ -61,7 +61,7 @@ where
6161
}
6262
}
6363

64-
/// Given the shape of the image and a data vector create an image. If
64+
/// Given the shape of the image and a data vector create an image. If
6565
/// the data sizes don't match a zero filled image will be returned instead
6666
/// of panicking
6767
pub fn from_shape_data(rows: usize, cols: usize, data: Vec<T>) -> Self {
@@ -151,5 +151,4 @@ mod tests {
151151
arr1(&[u16::max_value(), 0, u16::max_value() / 3])
152152
);
153153
}
154-
155154
}

src/core/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
/// corresponding methods in `u8`
2323
/// ```
2424
pub trait PixelBound {
25-
/// The minimum value a pixel can take
25+
/// The minimum value a pixel can take
2626
fn min_pixel() -> Self;
2727
/// The maximum value a pixel can take
2828
fn max_pixel() -> Self;
2929

30-
/// Returns the number of discrete levels. This is an option because it's
31-
/// deemed meaningless for types like floats which suffer from rounding
30+
/// Returns the number of discrete levels. This is an option because it's
31+
/// deemed meaningless for types like floats which suffer from rounding
3232
/// issues
3333
fn discrete_levels() -> Option<usize>;
3434
}

src/enhancement/histogram_equalisation.rs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use crate::core::*;
22
use ndarray::prelude::*;
3-
use ndarray_stats::{HistogramExt, histogram::Grid};
4-
use num_traits::{Num, NumAssignOps};
3+
use ndarray_stats::{histogram::Grid, HistogramExt};
54
use num_traits::cast::{FromPrimitive, ToPrimitive};
5+
use num_traits::{Num, NumAssignOps};
66

77
/// Extension trait to implement histogram equalisation on other types
8-
pub trait HistogramEqExt<A> where A: Ord {
8+
pub trait HistogramEqExt<A>
9+
where
10+
A: Ord,
11+
{
912
/// Equalises an image histogram returning a new image.
1013
/// Grids should be for a 1xN image as the image is flattened during processing
1114
fn equalise_hist(&self, grid: Grid<A>) -> Self;
@@ -15,10 +18,9 @@ pub trait HistogramEqExt<A> where A: Ord {
1518
fn equalise_hist_inplace(&mut self, grid: Grid<A>);
1619
}
1720

18-
1921
impl<T> HistogramEqExt<T> for Array3<T>
2022
where
21-
T: Copy + Clone + Ord + Num + NumAssignOps + ToPrimitive + FromPrimitive + PixelBound
23+
T: Copy + Clone + Ord + Num + NumAssignOps + ToPrimitive + FromPrimitive + PixelBound,
2224
{
2325
fn equalise_hist(&self, grid: Grid<T>) -> Self {
2426
let mut result = self.clone();
@@ -29,11 +31,9 @@ where
2931
fn equalise_hist_inplace(&mut self, grid: Grid<T>) {
3032
for mut c in self.axis_iter_mut(Axis(2)) {
3133
// get the histogram
32-
let flat = Array::from_iter(c.iter())
33-
.mapv(|x| *x)
34-
.insert_axis(Axis(1));
34+
let flat = Array::from_iter(c.iter()).mapv(|x| *x).insert_axis(Axis(1));
3535
let hist = flat.histogram(grid.clone());
36-
// get cdf
36+
// get cdf
3737
let mut running_total = 0;
3838
let mut min = 0.0;
3939
let cdf = hist.counts().mapv(|x| {
@@ -43,9 +43,11 @@ where
4343
}
4444
running_total as f32
4545
});
46-
46+
4747
// Rescale cdf writing back new values
48-
let scale = (T::max_pixel() - T::min_pixel()).to_f32().unwrap_or_default();
48+
let scale = (T::max_pixel() - T::min_pixel())
49+
.to_f32()
50+
.unwrap_or_default();
4951
let denominator = flat.len() as f32 - min;
5052
c.mapv_inplace(|x| {
5153
let index = match grid.index_of(&arr1(&[x])) {
@@ -55,10 +57,10 @@ where
5557
} else {
5658
i[0]
5759
}
58-
},
60+
}
5961
None => 0,
6062
};
61-
let mut f_res = ((cdf[index] - min)/denominator)*scale;
63+
let mut f_res = ((cdf[index] - min) / denominator) * scale;
6264
if T::discrete_levels().is_some() {
6365
f_res = f_res.round();
6466
}
@@ -68,9 +70,8 @@ where
6870
}
6971
}
7072

71-
72-
impl<T, C> HistogramEqExt<T> for Image<T, C>
73-
where
73+
impl<T, C> HistogramEqExt<T> for Image<T, C>
74+
where
7475
Image<T, C>: Clone,
7576
T: Copy + Clone + Ord + Num + NumAssignOps + ToPrimitive + FromPrimitive + PixelBound,
7677
C: ColourModel,
@@ -86,38 +87,33 @@ where
8687
}
8788
}
8889

89-
9090
#[cfg(test)]
9191
mod tests {
92+
use super::*;
9293
use crate::core::Gray;
9394
use ndarray_stats::histogram::{Bins, Edges};
94-
use super::*;
9595

9696
#[test]
9797
fn hist_eq_test() {
9898
// test data from wikipedia
99-
let input_pixels = vec![52, 55, 61, 59, 70, 61, 76, 61,
100-
62, 59, 55, 104, 94, 85, 59, 71,
101-
63, 65, 66, 113, 144, 104, 63, 72,
102-
64, 70, 70, 126, 154, 109, 71, 69,
103-
67, 73, 68, 106, 122, 88, 68, 68,
104-
68, 79, 60, 79, 77, 66, 58, 75,
105-
69, 85, 64, 58, 55, 61, 65, 83,
106-
70, 87, 69, 68, 65, 73, 78, 90,];
99+
let input_pixels = vec![
100+
52, 55, 61, 59, 70, 61, 76, 61, 62, 59, 55, 104, 94, 85, 59, 71, 63, 65, 66, 113, 144,
101+
104, 63, 72, 64, 70, 70, 126, 154, 109, 71, 69, 67, 73, 68, 106, 122, 88, 68, 68, 68,
102+
79, 60, 79, 77, 66, 58, 75, 69, 85, 64, 58, 55, 61, 65, 83, 70, 87, 69, 68, 65, 73, 78,
103+
90,
104+
];
107105

108-
let output_pixels = vec![0, 12, 53, 32, 146, 53, 174, 53,
109-
57, 32, 12, 227, 219, 202, 32, 154,
110-
65, 85, 93, 239, 251, 227, 65, 158,
111-
73, 146, 146, 247, 255, 235, 154, 130,
112-
97, 166, 117, 231, 243, 210, 117, 117,
113-
117, 190, 36, 190, 178, 93, 20, 170,
114-
130, 202, 73, 20, 12, 53, 85, 194,
115-
146, 206, 130, 117, 85, 166, 182, 215];
106+
let output_pixels = vec![
107+
0, 12, 53, 32, 146, 53, 174, 53, 57, 32, 12, 227, 219, 202, 32, 154, 65, 85, 93, 239,
108+
251, 227, 65, 158, 73, 146, 146, 247, 255, 235, 154, 130, 97, 166, 117, 231, 243, 210,
109+
117, 117, 117, 190, 36, 190, 178, 93, 20, 170, 130, 202, 73, 20, 12, 53, 85, 194, 146,
110+
206, 130, 117, 85, 166, 182, 215,
111+
];
116112

117113
let input = Image::<u8, Gray>::from_shape_data(8, 8, input_pixels);
118-
114+
119115
let expected = Image::<u8, Gray>::from_shape_data(8, 8, output_pixels);
120-
116+
121117
let edges_vec: Vec<u8> = (0..255).collect();
122118
let grid = Grid::from(vec![Bins::new(Edges::from(edges_vec))]);
123119

src/enhancement/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/// Implementation of histogram equalisation for images
32
pub mod histogram_equalisation;
43

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
2828
/// The core of `ndarray-vision` contains the `Image` type and colour models
2929
pub mod core;
30+
/// Image enhancement intrinsics and algorithms
31+
pub mod enhancement;
3032
/// Image formats - encoding and decoding images from bytes for saving and loading
3133
pub mod format;
3234
/// Image processing intrinsics and common filters/algorithms.
3335
pub mod processing;
34-
/// Image enhancement intrinsics and algorithms
35-
pub mod enhancement;

src/processing/canny.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,4 @@ mod tests {
320320

321321
assert_eq!(result, expected);
322322
}
323-
324323
}

src/processing/conv.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,12 @@ use num_traits::{Num, NumAssignOps};
66
use std::marker::PhantomData;
77
use std::marker::Sized;
88

9-
pub struct NoPadding;
10-
pub struct ZeroPadding;
11-
pub struct ExtendPadding;
12-
13-
pub trait ImagePadder where Self: Sized + Copy {
14-
type Data;
15-
16-
fn pad(&self, pad_size: (usize, usize)) -> Self;
17-
}
18-
19-
20-
impl<T> ImagePadder<T> for NoPadding {
21-
fn pad(&self, pad_size: (usize, usize)) -> Self {
22-
*self
23-
}
24-
}
25-
269
/// Perform image convolutions
2710
pub trait ConvolutionExt
2811
where
2912
Self: Sized,
3013
{
31-
/// Underlying data type to perform the colution on
14+
/// Underlying data type to perform the convolution on
3215
type Data;
3316

3417
/// Perform a convolution returning the resultant data

src/processing/kernels.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait FixedDimensionKernelBuilder<T> {
3636
}
3737

3838
/// Create a Laplacian filter, this provides the 2nd spatial derivative of an
39-
/// image.
39+
/// image.
4040
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
4141
pub struct LaplaceFilter;
4242

@@ -101,7 +101,7 @@ where
101101
T: Copy + Clone + FromPrimitive + Num,
102102
{
103103
/// The parameter for the Gaussian filter is the horizontal and vertical
104-
/// covariances to form the covariance matrix.
104+
/// covariances to form the covariance matrix.
105105
/// ```ignore
106106
/// [ Params[0], 0]
107107
/// [ 0, Params[1]]

src/processing/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/// Implementation of a Canny Edge Detector and associated types
32
pub mod canny;
43
/// Image convolutions in 2D
@@ -26,7 +25,7 @@ pub enum Error {
2625
/// Invalid dimensions to an algorithm - this includes rows and columns and
2726
/// relationships between the two
2827
InvalidDimensions,
29-
/// An invalid parameter has been supplied to an algorithm.
28+
/// An invalid parameter has been supplied to an algorithm.
3029
InvalidParameter,
3130
/// Numeric error such as an invalid conversion or issues in floating point
3231
/// math. As `ndarray` and `ndarray-vision` rely on `num_traits` for a lot

0 commit comments

Comments
 (0)