Created
October 13, 2023 22:55
-
-
Save mikecvet/0b63393c32077b6fe6b5be47319acd72 to your computer and use it in GitHub Desktop.
patch extraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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