问题
Does anyone know of any efficient ways of computing a pixel's neighborhood and returning it in array form based on an input image and pixel coordinates? I would like to compute a number of pixel level features, such as integrated intensity and the Haralick features, based on these neighborhoods.
回答1:
I can think of at least two approaches:
- Construct
slice
objects corresponding to your coordinates, then index into the array with those slices individually. - Construct index arrays based on your coordinates, and use fancy indexing to extract the windows. This requires more memory, but is faster if you want to grab all windows with one go. For an example of something similar, have a look at this example: http://stefanvdwalt.bitbucket.org/assp2013/numpy/#25
来源:https://stackoverflow.com/questions/18793406/ndimage-or-skimage-functions-for-returning-pixel-neighborhoods