简体   繁体   中英

Custom filter with scipy ndimage

Is there a way to define a custom filter for image processing in Scipy? I need a filter that, given a structural element located at pixel i,j, it assigns a value of that pixel to all other pixels covered by that structural element.

Edit : A filter would be similar to a morphology filter, like erosion/dilation, but instead of assigning a minimum/maximum value over a structural element to a pixel, I want to assign a pixel's value to all other pixels in its neighborhood.

Assuming you are using convolution :

from scipy import ndimage
img = np.array([[1, 2, 0, 0], [5, 3, 0, 4], [0, 0, 0, 7], [9, 3, 0, 0]])
f = np.array([[1,1,1],[1,1,0],[1,0,0]])
result = ndimage.convolve(img, f)

You can find more about that here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM