def make_3d_kernels(): # Central kernel ck = np.zeros((3, 3, 3)) ck[1, 1, 1] = 1 # Initialize kernels array to hold all 26 kernels kernels = np.zeros((26, 3, 3, 3)) # Counter for filling the kernels array counter = 0 # Generate face neighbor kernels for axis in range(3): # Loop through x, y, z axes for delta in [-1, 1]: # Negative and positive directions k = np.copy(ck) k[1 + delta*(axis == 0), 1 + delta*(axis == 1), 1 + delta*(axis == 2)] = -1 kernels[counter, :, :, :] = k counter += 1 # Generate edge neighbor kernels for x in [-1, 1]: for y in [-1, 1]: k = np.copy(ck) k[1 + x, 1 + y, 0] = -1/2 kernels[counter, :, :, :] = k counter += 1 k = np.copy(ck) k[1 + x, 0, 1 + y] = -1/2 kernels[counter, :, :, :] = k counter += 1 k = np.copy(ck) k[0, 1 + x, 1 + y] = -1/2 kernels[counter, :, :, :] = k counter += 1 # Generate corner neighbor kernels for x in [-1, 1]: for y in [-1, 1]: for z in [-1, 1]: k = np.copy(ck) k[1 + x, 1 + y, 1 + z] = -1/3 kernels[counter, :, :, :] = k counter += 1 return kernels