4

I think I understand the working of ndimage.generic_filter but I don't understand what happens when you throw in an array with more than 2 dimensions (like [[R],[G],[B]] values from an image)

Given the following code:

import numpy as np
from scipy.ndimage import generic_filter
a = np.arange(36).reshape(3,3,4)
def fnc(buffer):
  return np.min(buffer)
footprint = [
 [[1, 1], [1, 1]],
 [[1, 1], [1, 1]],
 [[1, 1], [1, 1]] 
]
generic_filter(a, fnc, footprint = footprint)

The output is:

   array([[
   [ 0,  0,  1,  2],
   [ 0,  0,  1,  2],
   [ 4,  4,  5,  6]
   ],[
   [ 0,  0,  1,  2],
   [ 0,  0,  1,  2],
   [ 4,  4,  5,  6]
   ],[
   [12, 12, 13, 14],
   [12, 12, 13, 14],
   [16, 16, 17, 18]
   ]])

It seems to me here that the first array is duplicated at the cost of the last entered array which I can't see the logic of. Would this be intentional behaviour or am I not supposed to use generic_filter like this?

tilt
  • 220
  • 1
  • 11

0 Answers0