def convolution_3d(picture: CachingDataStructure, kernel: np.ndarray, cval: float = 0.0) -> CachingDataStructure: """Performs convolution for a 3D image. Pads borders with cval""" assert picture.dim == 3 ret_data = picture.empty_of_same_shape() kernel_dim = kernel.shape[0] pad = kernel_dim // 2 for (x, y, z) in picture.iter_keys(): ret_data[x, y, z] = convolve_voxel(picture, kernel, kernel_dim, pad, x, y, z, cval) return ret_data
def bit_rev_inplace(arr: CachingDataStructure, axis: int) \ -> CachingDataStructure: """ Swaps the values along a given axis according to the reversed bit value of that index """ N = arr.shape[0] bitlen = int(np.log2(N)) for key in arr.iter_keys(): rev_bit_idx = rev_bit_str(key[axis], bitlen) if key[axis] >= rev_bit_idx: # Make sure to only swap elements once continue new_key = tuple_gen(rev_bit_idx, key, axis) arr[key], arr[new_key] = arr[new_key], arr[key] return arr