3D-interpolation with dask-image

I have a binary 3D-mask with a core that is completely missing at some slices along the z-dimension. I’d like to interpolate those missing slices so that they get the core shape (and value, but that’s 1 since it’s a binary) at the nearest slice that has a core. Is that possible to do with dask-image? I was looking at the dask_image.ndinterp module but I don’t understand how to use it.

Here’s a dummy dataset for illustration:

dummy_arr = np.zeros((1000, 300, 250))
zs = dummy_arr.shape[0]
xs = dummy_arr.shape[1]
ys = dummy_arr.shape[2]
dummy_arr[:500, 125:(xs-125), 85:(ys-85)] = 1
dummy_arr[500:, 135:(xs-135), 100:(ys-100)] = 1
dummy_arr[50:60, :, :] = 0
dummy_arr[280:295, :, :] = 0
dummy_arr[[601, 699, 701, 799], :, :] = 0

Well, I’m really no expert in interpolation, but is this really one? You’re not trying to map new points to a reference function, but trying to fill huge gaps between 0 and 1, because you expect the 1s to be contiguous over your volume?

Did you already tried some code? How would you do it in Numpy?

You’re right in that I might not use the right terminology for what I wanted to do. In the end, I used unidirectional dilation to accomplish what I wanted.

import dask.array as da
import dask_image.ndmorph as dmorph

z_profile = da.sum(dummy_arr , axis=(1, 2)) # first step for finding longest gap in data
csum = da.cumsum(z_profile) # second step for finding longest gap
bcount = da.bincount(csum) # third step for finding longest gap
longest_gap = da.max(bcount) - 1
iterations = da.ceil(longest_gap / 2) # dilation is done from both directions, so dilate with longest gap / 2
sel = da.zeros((3, 3, 3)) # basis for structuring element
sel[:, 1, 1] = 1 # structuring for dilation in the z-direction only
dummy_arr_filled = dmorph.binary_dilation(dummy_arr, sel, iterations=iterations)

1 Like