process_image_pixels¶
-
gammapy.image.
process_image_pixels
(images, kernel, out, pixel_function)[source]¶ Process images for a given kernel and per-pixel function.
This is a helper function for the following common task: For a given set of same-shaped images and a smaller-shaped kernel, process each image pixel by moving the kernel at that position, cut out kernel-shaped parts from the images and call a function to compute output values for that position.
This function loops over image pixels and takes care of bounding box computations, including image boundary handling.
Parameters: images : dict of arrays
Images needed to compute out
kernel : array (shape must be odd-valued)
kernel shape must be odd-valued
out : single array or dict of arrays
These arrays must have been pre-created by the caller
pixel_function : function to process a part of the images
Examples
As an example, here is how to implement convolution as a special case of process_image_pixels with one input and output image:
def convolve(image, kernel): '''Convolve image with kernel''' from gammapy.image.utils import process_image_pixels images = dict(image=np.asanyarray(image)) kernel = np.asanyarray(kernel) out = dict(image=np.empty_like(image)) def convolve_function(images, kernel): value = np.sum(images['image'] * kernel) return dict(image=value) process_image_pixels(images, kernel, out, convolve_function) return out['image']
- TODO: add different options to treat the edges
- TODO: implement multiprocessing version
- TODO: this function is similar to view_as_windows in scikit-image:
- http://scikit-image.org/docs/dev/api/skimage.util.html#view-as-windows Is this function needed or can everything be done with view_as_windows?