Skip to content

Commit bc2e4d7

Browse files
committed
Moved to use ZeroPadder with conv
Now just need to make the padder injectable for convolutions
1 parent 5396d7d commit bc2e4d7

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/processing/conv.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::core::{ColourModel, Image};
2+
use crate::core::padding::*;
23
use crate::processing::Error;
34
use ndarray::prelude::*;
45
use ndarray::{s, Zip};
@@ -40,24 +41,11 @@ where
4041
// Bit icky but handles fact that uncentred convolutions will cross the bounds
4142
// otherwise
4243
let (row_offset, col_offset) = kernel_centre(k_s[0], k_s[1]);
43-
// row_offset * 2 may not equal k_s[0] due to truncation
44-
let shape_ext = (
45-
self.shape()[0] + row_offset * 2,
46-
self.shape()[1] + col_offset * 2,
47-
self.shape()[2],
48-
);
4944
let shape = (self.shape()[0], self.shape()[1], self.shape()[2]);
5045

5146
if shape.0 > 0 && shape.1 > 0 {
5247
let mut result = Self::zeros(shape);
53-
54-
let mut tmp = Self::zeros(shape_ext);
55-
tmp.slice_mut(s![
56-
row_offset..shape_ext.0 - row_offset,
57-
col_offset..shape_ext.1 - col_offset,
58-
..
59-
])
60-
.assign(&self);
48+
let tmp = self.pad((row_offset, col_offset), &ZeroPadding {});
6149

6250
Zip::indexed(tmp.windows(kernel.dim())).apply(|(i, j, _), window| {
6351
let mult = &window * &kernel;

0 commit comments

Comments
 (0)