Skip to content

Instantly share code, notes, and snippets.

@mikecvet
Created October 13, 2023 22:55
Show Gist options
  • Save mikecvet/39668f441a760d0816bbe12456d13b2f to your computer and use it in GitHub Desktop.
Save mikecvet/39668f441a760d0816bbe12456d13b2f to your computer and use it in GitHub Desktop.
/// A patch is a concept from image processing which captures subregions of the image pixels,
/// used to capture groups of spatial features from the underlying image.
pub fn
patches (&mut self, image: &Array2<f64>) -> Vec<Patch>
{
let mut data: Vec<Patch> = Vec::new();
for x in 0..(image.shape()[0] - self.rows + 1) {
for y in 0..(image.shape()[1] - self.cols + 1) {
let p = Patch {
x: x,
y: y,
data: image.slice(
// Collect a 2-D slice of the image from
// [(x -> x + kernel rows), (y -> y + kernel_cols)]
s![
x..(x + self.rows),
y..(y + self.cols)
])
.to_owned()
.insert_axis(Axis(2))
};
data.push(p)
}
}
data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment